Package jeeves.server.context

Examples of jeeves.server.context.ServiceContext


  }

  private ServiceContext mockServiceContext(boolean canEdit,
                                              boolean canDownload,
                                              boolean canDynamic) throws Exception{//boolean isAdmin, String userId) {
        ServiceContext context = mock(ServiceContext.class);
        doCallRealMethod().when(context).setAsThreadLocal();

        AccessManager accessManager = mock(AccessManager.class);
        when(accessManager.canEdit(any(ServiceContext.class), anyString()))
                .thenReturn(canEdit);
        when(accessManager.canDownload(any(ServiceContext.class), anyString()))
                .thenReturn(canDownload);
        when(accessManager.canDynamic(any(ServiceContext.class), anyString()))
                .thenReturn(canDynamic);
        GeonetContext gc = mock(GeonetContext.class);
        when(gc.getBean(AccessManager.class)).thenReturn(accessManager);
        when(context.getHandlerContext(Geonet.CONTEXT_NAME)).thenReturn(gc);
       
    context.setAsThreadLocal();
    return context;
  }
View Full Code Here


    public void testRun() throws Exception {
        final long numSearches = _searchRequestRepository.count();
        TransactionlessTesting.get().run(new TestTask() {
            @Override
            public void run() throws Exception {
                final ServiceContext context = createServiceContext();
                final SearchLoggerTask task = context.getBean(SearchLoggerTask.class);
                Query query = new TermQuery(new Term("any", "search"));
                task.configure(context, false, "any", query, 3, Sort.RELEVANCE, null, "value");
                task.run();
            }
        });
View Full Code Here

     * Check if bean is defined in the context
     *
     * @param beanId id of the bean to look up
     */
    public static boolean existsBean(String beanId) {
        ServiceContext serviceContext = ServiceContext.get();
        if(serviceContext == null) return true;
        ServletContext servletContext = serviceContext.getServlet().getServletContext();
        ConfigurableApplicationContext springContext = JeevesDelegatingFilterProxy.getApplicationContextFromServletContext(servletContext);
        if(springContext == null) return true;
        return springContext.containsBean(beanId);
    }
View Full Code Here

     *
     * @return true if accessible or system is unable to determine because the current
     *              thread does not have a ServiceContext in its thread local store
     */
    public static boolean isAccessibleService(Object serviceName) {
        ServiceContext serviceContext = ServiceContext.get();
        if(serviceContext == null) return true;
        ServletContext servletContext = serviceContext.getServlet().getServletContext();
        ConfigurableApplicationContext springContext = JeevesDelegatingFilterProxy.getApplicationContextFromServletContext(servletContext);
        SecurityContext context = SecurityContextHolder.getContext();
        if(springContext == null || context == null) return true;
       
        Map<String, AbstractSecurityInterceptor> evals = springContext.getBeansOfType(AbstractSecurityInterceptor.class);
        Authentication authentication = context.getAuthentication();
       
        FilterInvocation fi = new FilterInvocation(null, "/srv/"+serviceContext.getLanguage()+"/"+serviceName, null);
        for(AbstractSecurityInterceptor securityInterceptor: evals.values()) {
            if(securityInterceptor == null) return true;
           

            Collection<ConfigAttribute> attrs = securityInterceptor.obtainSecurityMetadataSource().getAttributes(fi);
View Full Code Here

    }

    //---------------------------------------------------------------------------

    public ServiceContext createServiceContext(String name, ConfigurableApplicationContext appContext) {
        ServiceContext context = new ServiceContext(name, appContext, htContexts,
                entityManager);

        context.setBaseUrl(baseUrl);
        context.setLanguage("?");
        context.setUserSession(null);
        context.setIpAddress("?");
        context.setAppPath(appPath);
        context.setUploadDir(uploadDir);
        context.setMaxUploadSize(maxUploadSize);
        context.setServlet(servlet);

        return context;
    }
View Full Code Here

        return context;
    }

    public void dispatch(ServiceRequest req, UserSession session) {
        ServiceContext context = new ServiceContext(req.getService(), jeevesApplicationContext,
                htContexts, entityManager);
        dispatch(req, session, context);
    }
View Full Code Here

      Class<?> c = Class.forName(className);

      ApplicationHandler h = (ApplicationHandler) c.newInstance();

      ServiceContext srvContext = _serviceMan.createServiceContext("AppHandler", _applicationContext);
      srvContext.setLanguage(_defaultLang);
      srvContext.setLogger(_appHandLogger);
      srvContext.setServlet(servlet);
      srvContext.setAsThreadLocal();

      try {
        info ("--- Starting handler --------------------------------------");

        Object context = h.start(handler, srvContext);
View Full Code Here

    @Autowired
    MetadataRepository _metadataRepo;

    @Test
    public void testDoImportMefVersion1() throws Exception {
        ServiceContext context = createServiceContext();
        User admin = loginAsAdmin(context);
        ImportMetadata importMetadata = new ImportMetadata(this, context).invoke();
        List<String> metadataIds = importMetadata.getMetadataIds();

        assertEquals(1, metadataIds.size());
View Full Code Here

        assertEquals(admin.getId(), metadata.getSourceInfo().getOwner());
    }

    @Test
    public void testDoImportMefVersion2() throws Exception {
        ServiceContext context = createServiceContext();

        final File resource = new File(MEFLibIntegrationTest.class.getResource("mef2-example-2md.zip").getFile());

        final User admin = loginAsAdmin(context);
View Full Code Here

    private AtomicInteger _inc = new AtomicInteger();

    public void testIllegalAccessUpdate() throws Exception {
        addPhotographicMetadataToRepository(adminUserId());
        final ServiceContext serviceContext = createServiceContext();

        Element params = createUpdateTransaction("Title", "newTitle");
        final Element result = _transaction.execute(params, serviceContext);

        assertEquals(0, getUpdatedCount(result, TOTAL_DELETED));
View Full Code Here

TOP

Related Classes of jeeves.server.context.ServiceContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.