Search in sources :

Example 1 with Named

use of javax.inject.Named in project jersey by jersey.

the class ExecutorProviders method createInjectionBindings.

/**
     * Create qualified {@link java.util.concurrent.ExecutorService} and {@link java.util.concurrent.ScheduledExecutorService}
     * injection bindings based on the registered providers implementing the
     * {@link org.glassfish.jersey.spi.ExecutorServiceProvider} and/or
     * {@link org.glassfish.jersey.spi.ScheduledExecutorServiceProvider} SPI.
     * <p>
     * This method supports creation of qualified injection bindings based on custom
     * {@link javax.inject.Qualifier qualifier annotations} attached to the registered provider implementation classes
     * as well as named injection bindings based on the {@link javax.inject.Named} qualifier annotation attached to the
     * registered provider implementation classes.
     * </p>
     *
     * @param injectionManager application's injection manager.
     */
public static void createInjectionBindings(InjectionManager injectionManager) {
    /*
         * Add ExecutorService into DI framework.
         */
    Map<Class<? extends Annotation>, List<ExecutorServiceProvider>> executorProviderMap = getQualifierToProviderMap(injectionManager, ExecutorServiceProvider.class);
    for (Map.Entry<Class<? extends Annotation>, List<ExecutorServiceProvider>> qualifierToProviders : executorProviderMap.entrySet()) {
        Class<? extends Annotation> qualifierAnnotationClass = qualifierToProviders.getKey();
        Iterator<ExecutorServiceProvider> bucketProviderIterator = qualifierToProviders.getValue().iterator();
        ExecutorServiceProvider executorProvider = bucketProviderIterator.next();
        logExecutorServiceProvider(qualifierAnnotationClass, bucketProviderIterator, executorProvider);
        SupplierInstanceBinding<ExecutorService> descriptor = Bindings.supplier(new ExecutorServiceSupplier(executorProvider)).in(Singleton.class).to(ExecutorService.class);
        Annotation qualifier = executorProvider.getClass().getAnnotation(qualifierAnnotationClass);
        if (qualifier instanceof Named) {
            descriptor.named(((Named) qualifier).value());
        } else {
            descriptor.qualifiedBy(qualifier);
        }
        injectionManager.register(descriptor);
    }
    /*
         * Add ScheduledExecutorService into DI framework.
         */
    Map<Class<? extends Annotation>, List<ScheduledExecutorServiceProvider>> schedulerProviderMap = getQualifierToProviderMap(injectionManager, ScheduledExecutorServiceProvider.class);
    for (Map.Entry<Class<? extends Annotation>, List<ScheduledExecutorServiceProvider>> qualifierToProviders : schedulerProviderMap.entrySet()) {
        Class<? extends Annotation> qualifierAnnotationClass = qualifierToProviders.getKey();
        Iterator<ScheduledExecutorServiceProvider> bucketProviderIterator = qualifierToProviders.getValue().iterator();
        ScheduledExecutorServiceProvider executorProvider = bucketProviderIterator.next();
        logScheduledExecutorProvider(qualifierAnnotationClass, bucketProviderIterator, executorProvider);
        SupplierInstanceBinding<ScheduledExecutorService> descriptor = Bindings.supplier(new ScheduledExecutorServiceSupplier(executorProvider)).in(Singleton.class).to(ScheduledExecutorService.class);
        if (!executorProviderMap.containsKey(qualifierAnnotationClass)) {
            // it is safe to register binding for ExecutorService too...
            descriptor.to(ExecutorService.class);
        }
        Annotation qualifier = executorProvider.getClass().getAnnotation(qualifierAnnotationClass);
        if (qualifier instanceof Named) {
            descriptor.named(((Named) qualifier).value());
        } else {
            descriptor.qualifiedBy(qualifier);
        }
        injectionManager.register(descriptor);
    }
}
Also used : Named(javax.inject.Named) ScheduledExecutorServiceProvider(org.glassfish.jersey.spi.ScheduledExecutorServiceProvider) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Annotation(java.lang.annotation.Annotation) ExecutorServiceProvider(org.glassfish.jersey.spi.ExecutorServiceProvider) ScheduledExecutorServiceProvider(org.glassfish.jersey.spi.ScheduledExecutorServiceProvider) Singleton(javax.inject.Singleton) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with Named

use of javax.inject.Named in project OpenAM by OpenRock.

the class CoreGuiceModule method getCTSObjectMapper.

/**
     * CTS Jackson Object Mapper.
     * <p>
     * Use a static singleton as per <a href="http://wiki.fasterxml.com/JacksonBestPracticesPerformance">performance
     * best practice.</a>
     */
@Provides
@Named(CoreTokenConstants.OBJECT_MAPPER)
@Singleton
ObjectMapper getCTSObjectMapper() {
    ObjectMapper mapper = new ObjectMapper().configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true).configure(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
    /**
         * @see http://stackoverflow.com/questions/7105745/how-to-specify-jackson-to-only-use-fields-preferably-globally
         */
    mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker().withFieldVisibility(JsonAutoDetect.Visibility.ANY).withGetterVisibility(JsonAutoDetect.Visibility.NONE).withIsGetterVisibility(JsonAutoDetect.Visibility.NONE).withSetterVisibility(JsonAutoDetect.Visibility.NONE).withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
    SimpleModule customModule = new SimpleModule("openam", Version.unknownVersion());
    customModule.addKeyDeserializer(SessionID.class, new SessionIDKeyDeserialiser());
    mapper.registerModule(customModule);
    mapper.addHandler(new CompatibilityProblemHandler());
    return mapper;
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Named(javax.inject.Named) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 3 with Named

use of javax.inject.Named in project OpenAM by OpenRock.

the class RestGuiceModule method getInternalCrestRealmRouter.

@Provides
@Named("InternalCrestRouter")
@Singleton
Router getInternalCrestRealmRouter(@Named("CrestRealmRouter") Router crestRealmRouter) {
    Router internalCrestRouter = new Router();
    internalCrestRouter.setDefaultRoute(crestRealmRouter);
    return internalCrestRouter;
}
Also used : Router(org.forgerock.json.resource.Router) Named(javax.inject.Named) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 4 with Named

use of javax.inject.Named in project OpenAM by OpenRock.

the class SoapSTSInstanceModule method getProperties.

/*
     */
/**
     * These properties configure the web-service deployment, and are primarily referenced by the ws-security interceptors
     * deployed as part of CXF. These interceptors are responsible for enforcing the security-policy bindings protecting
     * the STS. To this end, various crypto objects are required, and the TokenValidators for the configured validated
     * token types are plugged-in.
     * @param wssValidatorFactory the factory class which will produce the wss Validator instances to enforce SecurityPolicy bindings
     * @param logger for error state logging
     * @return the Map that serves to configure the web-service deployment
     * @throws WSSecurityException In case an unexpected TokenType is encountered, or a TokenValidator could not be created.
     */
@Provides
@Named(AMSTSConstants.STS_WEB_SERVICE_PROPERTIES)
@Inject
Map<String, Object> getProperties(WSSValidatorFactory wssValidatorFactory, Logger logger) throws WSSecurityException {
    Map<String, Object> properties = new HashMap<>();
    // KeystoreConfig may be null for a TLS-based SecurityPolicy binding, or for the AM-bare binding.
    if (stsInstanceConfig.getKeystoreConfig() != null) {
        properties.put(SecurityConstants.CALLBACK_HANDLER, new SoapSTSCallbackHandler(stsInstanceConfig.getKeystoreConfig(), logger));
        Crypto crypto = CryptoFactory.getInstance(getEncryptionProperties());
        properties.put(SecurityConstants.ENCRYPT_CRYPTO, crypto);
        properties.put(SecurityConstants.SIGNATURE_CRYPTO, crypto);
        properties.put(SecurityConstants.SIGNATURE_USERNAME, stsInstanceConfig.getKeystoreConfig().getSignatureKeyAlias());
    }
    properties.put("faultStackTraceEnabled", "true");
    properties.put("exceptionMessageCauseEnabled", "true");
    processSecurityPolicyTokenValidatorConfiguration(properties, wssValidatorFactory, logger);
    return properties;
}
Also used : Crypto(org.apache.ws.security.components.crypto.Crypto) HashMap(java.util.HashMap) SoapSTSCallbackHandler(org.forgerock.openam.sts.soap.SoapSTSCallbackHandler) Inject(javax.inject.Inject) Named(javax.inject.Named) Provides(com.google.inject.Provides)

Example 5 with Named

use of javax.inject.Named in project OpenAM by OpenRock.

the class RadiusServerGuiceModule method getRadiusServiceConfigManger.

/**
     * Guice provider for the ServiceConfigManager.
     *
     * @return a ServiceConfigurationManager that can be used
     * @throws RadiusLifecycleException - when the service config manager can not be obtained.
     */
@Provides
@Named("RadiusServer")
protected ServiceConfigManager getRadiusServiceConfigManger() throws RadiusLifecycleException {
    ServiceConfigManager mgr = null;
    // get a ServiceConfigManager for our service
    try {
        final SSOToken admTk = AccessController.doPrivileged(AdminTokenAction.getInstance());
        mgr = new ServiceConfigManager(RadiusServerConstants.RADIUS_SERVICE_NAME, admTk);
    } catch (final Exception e) {
        throw new RadiusLifecycleException("Could not obtain ServiceConfigManger for the RADIUS service.", e);
    }
    return mgr;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) Named(javax.inject.Named) Provides(com.google.inject.Provides)

Aggregations

Named (javax.inject.Named)133 Produces (javax.enterprise.inject.Produces)40 ApplicationScoped (javax.enterprise.context.ApplicationScoped)30 Test (org.junit.Test)29 Provides (com.google.inject.Provides)23 Properties (java.util.Properties)18 Singleton (javax.inject.Singleton)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)15 Api (com.google.api.server.spi.config.Api)15 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)12 Annotation (java.lang.annotation.Annotation)11 Provides (dagger.Provides)9 ArrayList (java.util.ArrayList)8 List (java.util.List)7 Inject (javax.inject.Inject)7 HashMap (java.util.HashMap)6 ApiConfigAnnotationReader (com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader)4 Type (java.lang.reflect.Type)4