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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations