Java源码示例:com.sun.jersey.spi.container.ResourceFilterFactory

示例1
public void configure(Environment environment) {
    checkNotNull(environment, "environment");
    JerseyAuthConfiguration config = JerseyAuthConfigurationBuilder.build(_securityManager);

    for (ResourceFilterFactory resourceFilterFactory : config.getResourceFilterFactories()) {
        //noinspection unchecked
        environment.jersey().getResourceConfig().getResourceFilterFactories().add(resourceFilterFactory);
    }
    for (Object provider : config.getProviderInstances()) {
        environment.jersey().register(provider);
    }
    for (Class<?> providerClass : config.getProviderClasses()) {
        environment.jersey().register(providerClass);
    }
}
 
示例2
public static JerseyAuthConfiguration build(SecurityManager securityManager) {
    checkNotNull(securityManager, "securityManager");
    ApiKeyAuthenticationTokenGenerator tokenGenerator = new ApiKeyAuthenticationTokenGenerator();

    return new JerseyAuthConfiguration(
            ImmutableList.of(
                    AuthenticationExceptionHandler.class,
                    AuthorizationExceptionHandler.class,
                    UnauthorizedExceptionMapper.class,
                    new AuthenticatedSubjectProvider(securityManager)
            ),
            ImmutableList.<ResourceFilterFactory>of(new AuthResourceFilterFactory(securityManager, tokenGenerator))
    );
}
 
示例3
public JerseyAuthConfiguration(List<Object> providers, List<ResourceFilterFactory> resourceFilterFactories) {
    _providers = providers;
    _resourceFilterFactories = resourceFilterFactories;
}
 
示例4
public List<ResourceFilterFactory> getResourceFilterFactories() {
    return _resourceFilterFactories;
}
 
示例5
protected static ResourceTestRule setupResourceTestRule(List<Object> resourceList, List<Object> filters,
                                                        AuthIdentityManager<ApiKey> authIdentityManager,
                                                        PermissionManager permissionManager) {
    ResourceTestRule.Builder resourceTestRuleBuilder = ResourceTestRule.builder();

    for (Object resource : resourceList) {
        resourceTestRuleBuilder.addResource(resource);
    }

    List<ResourceFilterFactory> resourceFilterFactories = Lists.newArrayList();
    List<ContainerRequestFilter> containerRequestFilters = Lists.newArrayList();
    List<ContainerResponseFilter> containerResponseFilters = Lists.newArrayList();

    for (Object filter : filters) {
        if (filter instanceof ResourceFilterFactory) {
            resourceFilterFactories.add((ResourceFilterFactory) filter);
        }
        if (filter instanceof ContainerRequestFilter) {
            containerRequestFilters.add((ContainerRequestFilter) filter);
        }
        if (filter instanceof ContainerResponseFilter) {
            containerResponseFilters.add((ContainerResponseFilter) filter);
        }
    }

    resourceTestRuleBuilder.addProperty(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES, resourceFilterFactories);
    resourceTestRuleBuilder.addProperty(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, containerRequestFilters);
    resourceTestRuleBuilder.addProperty(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, containerResponseFilters);

    // Jersey tests don't inject Context parameters, so create an injector to provide a mock instance.
    resourceTestRuleBuilder.addProvider(new DatabusJerseyTest.ContextInjectableProvider<>(HttpServletRequest.class, mock(HttpServletRequest.class)));

    ResourceTestAuthUtil.setUpResources(resourceTestRuleBuilder, SecurityManagerBuilder.create()
            .withAuthIdentityReader(authIdentityManager)
            .withPermissionReader(permissionManager)
            .build());

    for (Object mapper : ExceptionMappers.getMappers()) {
        resourceTestRuleBuilder.addProvider(mapper);
    }
    for (Class mapperType : ExceptionMappers.getMapperTypes()) {
        resourceTestRuleBuilder.addProvider(mapperType);
    }

    ResourceTestRule resourceTestRule = resourceTestRuleBuilder.build();

    // Write Date objects using ISO8601 strings instead of numeric milliseconds-since-1970.
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
    resourceTestRule.getObjectMapper().setDateFormat(fmt);

    return resourceTestRule;
}