Search in sources :

Example 21 with Named

use of javax.inject.Named in project kernel by exoplatform.

the class ConcurrentContainer method resolveType.

/**
 * Resolves the given type and generic type
 */
private Object resolveType(Class<?> type, Type genericType, Annotation[] annotations, String logMessagePrefix) {
    if (type.isPrimitive()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(logMessagePrefix + ": Primitive types are not supported");
        }
        return 1;
    }
    Named named = null;
    Class<?> qualifier = null;
    for (int i = 0, length = annotations.length; i < length; i++) {
        Annotation a = annotations[i];
        if (a instanceof Named) {
            named = (Named) a;
            break;
        } else if (a.annotationType().isAnnotationPresent(Qualifier.class)) {
            qualifier = a.annotationType();
            break;
        }
    }
    if (type.isInterface() && type.equals(Provider.class)) {
        if (!(genericType instanceof ParameterizedType)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(logMessagePrefix + ": The generic type is not of type ParameterizedType");
            }
            return 2;
        }
        ParameterizedType aType = (ParameterizedType) genericType;
        Type[] typeVars = aType.getActualTypeArguments();
        Class<?> expectedType = (Class<?>) typeVars[0];
        final ComponentAdapter<?> adapter;
        if (named != null) {
            adapter = holder.getComponentAdapter(named.value(), expectedType);
        } else if (qualifier != null) {
            adapter = holder.getComponentAdapter(qualifier, expectedType);
        } else {
            adapter = holder.getComponentAdapterOfType(expectedType);
        }
        if (adapter == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(logMessagePrefix + ": We have no value to set so we skip it");
            }
            return 3;
        }
        return new Provider<Object>() {

            public Object get() {
                return adapter.getComponentInstance();
            }
        };
    } else {
        if (named != null) {
            return holder.getComponentInstance(named.value(), type);
        } else if (qualifier != null) {
            return holder.getComponentInstance(qualifier, type);
        } else {
            return holder.getComponentInstanceOfType(type);
        }
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Named(javax.inject.Named) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Qualifier(javax.inject.Qualifier) Annotation(java.lang.annotation.Annotation) Provider(javax.inject.Provider)

Example 22 with Named

use of javax.inject.Named in project kernel by exoplatform.

the class ConcurrentContainerMT method resolveType.

/**
 * Resolves the given type and generic type
 */
private Object resolveType(final Class<?> type, Type genericType, Annotation[] annotations, String logMessagePrefix, List<Dependency> dependencies) {
    if (type.isPrimitive()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(logMessagePrefix + ": Primitive types are not supported");
        }
        return 1;
    }
    Named named = null;
    Class<?> qualifier = null;
    for (int i = 0, length = annotations.length; i < length; i++) {
        Annotation a = annotations[i];
        if (a instanceof Named) {
            named = (Named) a;
            break;
        } else if (a.annotationType().isAnnotationPresent(Qualifier.class)) {
            qualifier = a.annotationType();
            break;
        }
    }
    if (type.isInterface() && type.equals(Provider.class)) {
        if (!(genericType instanceof ParameterizedType)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(logMessagePrefix + ": The generic type is not of type ParameterizedType");
            }
            return 2;
        }
        ParameterizedType aType = (ParameterizedType) genericType;
        Type[] typeVars = aType.getActualTypeArguments();
        Class<?> expectedType = (Class<?>) typeVars[0];
        final ComponentAdapter<?> adapter;
        final Object key;
        if (named != null) {
            adapter = holder.getComponentAdapter(key = named.value(), expectedType);
        } else if (qualifier != null) {
            adapter = holder.getComponentAdapter(key = qualifier, expectedType);
        } else {
            key = expectedType;
            adapter = holder.getComponentAdapterOfType(expectedType);
        }
        if (adapter == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(logMessagePrefix + ": We have no value to set so we skip it");
            }
            return 3;
        }
        final Provider<Object> result = new Provider<Object>() {

            public Object get() {
                return adapter.getComponentInstance();
            }
        };
        dependencies.add(new DependencyByProvider(key, expectedType, result, adapter));
        return result;
    } else {
        if (named != null) {
            final String name = named.value();
            dependencies.add(new DependencyByName(name, type));
            return holder.getComponentAdapter(name, type);
        } else if (qualifier != null) {
            dependencies.add(new DependencyByQualifier(qualifier, type));
            return holder.getComponentAdapter(qualifier, type);
        } else {
            dependencies.add(new DependencyByType(type));
            return holder.getComponentAdapterOfType(type);
        }
    }
}
Also used : Named(javax.inject.Named) Annotation(java.lang.annotation.Annotation) Provider(javax.inject.Provider) ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Qualifier(javax.inject.Qualifier)

Example 23 with Named

use of javax.inject.Named in project verify-hub by alphagov.

the class SamlProxyModule method getVerifyMetadataResolver.

@Provides
@Singleton
@Named("VerifyMetadataResolver")
public MetadataResolver getVerifyMetadataResolver(Environment environment, SamlProxyConfiguration configuration) {
    final MetadataResolver metadataResolver = new DropwizardMetadataResolverFactory().createMetadataResolver(environment, configuration.getMetadataConfiguration());
    registerMetadataRefreshTask(environment, metadataResolver, configuration.getMetadataConfiguration(), "metadata");
    return metadataResolver;
}
Also used : DropwizardMetadataResolverFactory(uk.gov.ida.saml.metadata.factories.DropwizardMetadataResolverFactory) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) AbstractReloadingMetadataResolver(org.opensaml.saml.metadata.resolver.impl.AbstractReloadingMetadataResolver) Named(javax.inject.Named) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 24 with Named

use of javax.inject.Named in project verify-hub by alphagov.

the class SamlEngineModule method getVerifyMetadataResolver.

@Provides
@Singleton
@Named("VerifyMetadataResolver")
private MetadataResolver getVerifyMetadataResolver(Environment environment, SamlEngineConfiguration configuration) {
    final MetadataResolver metadataResolver = new DropwizardMetadataResolverFactory().createMetadataResolver(environment, configuration.getMetadataConfiguration());
    registerMetadataRefreshTask(environment, metadataResolver, configuration.getMetadataConfiguration(), "metadata");
    return metadataResolver;
}
Also used : DropwizardMetadataResolverFactory(uk.gov.ida.saml.metadata.factories.DropwizardMetadataResolverFactory) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) AbstractReloadingMetadataResolver(org.opensaml.saml.metadata.resolver.impl.AbstractReloadingMetadataResolver) Named(javax.inject.Named) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 25 with Named

use of javax.inject.Named in project verify-hub by alphagov.

the class SamlEngineModule method getAES256WithGCMAssertionDecrypter.

@Provides
@Named("AES256DecrypterWithGCM")
private AssertionDecrypter getAES256WithGCMAssertionDecrypter(IdaKeyStore keyStore) {
    IdaKeyStoreCredentialRetriever idaKeyStoreCredentialRetriever = new IdaKeyStoreCredentialRetriever(keyStore);
    Decrypter decrypter = new DecrypterFactory().createDecrypter(idaKeyStoreCredentialRetriever.getDecryptingCredentials());
    return new AssertionDecrypter(new EncryptionAlgorithmValidator(ImmutableSet.of(EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES256, EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES256_GCM)), decrypter);
}
Also used : IdaKeyStoreCredentialRetriever(uk.gov.ida.saml.security.IdaKeyStoreCredentialRetriever) DecrypterFactory(uk.gov.ida.saml.security.DecrypterFactory) AssertionDecrypter(uk.gov.ida.saml.security.AssertionDecrypter) EncryptionAlgorithmValidator(uk.gov.ida.saml.security.validators.encryptedelementtype.EncryptionAlgorithmValidator) Decrypter(org.opensaml.saml.saml2.encryption.Decrypter) AssertionDecrypter(uk.gov.ida.saml.security.AssertionDecrypter) Named(javax.inject.Named) Provides(com.google.inject.Provides)

Aggregations

Named (javax.inject.Named)126 Produces (javax.enterprise.inject.Produces)36 Test (org.junit.Test)29 ApplicationScoped (javax.enterprise.context.ApplicationScoped)26 Provides (com.google.inject.Provides)22 Singleton (javax.inject.Singleton)17 Properties (java.util.Properties)16 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