Search in sources :

Example 1 with AnnotationAwareOrderComparator

use of org.springframework.core.annotation.AnnotationAwareOrderComparator in project sonarqube by SonarSource.

the class PriorityBeanFactoryTest method setUp.

@Before
public void setUp() {
    // needed to support autowiring with @Inject
    beanFactory.addBeanPostProcessor(new AutowiredAnnotationBeanPostProcessor());
    // needed to read @Priority
    beanFactory.setDependencyComparator(new AnnotationAwareOrderComparator());
    beanFactory.setParentBeanFactory(parentBeanFactory);
}
Also used : AutowiredAnnotationBeanPostProcessor(org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) Before(org.junit.Before)

Example 2 with AnnotationAwareOrderComparator

use of org.springframework.core.annotation.AnnotationAwareOrderComparator in project kylo by Teradata.

the class JaasAuthConfig method jaasConfiguration.

@Bean(name = "jaasConfiguration")
public javax.security.auth.login.Configuration jaasConfiguration(Optional<List<LoginConfiguration>> loginModuleEntries) {
    // Generally the entries will be null only in situations like unit/integration tests.
    if (loginModuleEntries.isPresent()) {
        List<LoginConfiguration> sorted = new ArrayList<>(loginModuleEntries.get());
        sorted.sort(new AnnotationAwareOrderComparator());
        Map<String, AppConfigurationEntry[]> merged = sorted.stream().map(c -> c.getAllApplicationEntries().entrySet()).flatMap(s -> s.stream()).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue(), ArrayUtils::addAll));
        return new InMemoryConfiguration(merged);
    } else {
        return new InMemoryConfiguration(Collections.emptyMap());
    }
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) LoginConfigurationBuilder(com.thinkbiganalytics.auth.jaas.LoginConfigurationBuilder) LoginConfiguration(com.thinkbiganalytics.auth.jaas.LoginConfiguration) ArrayUtils(org.apache.commons.lang3.ArrayUtils) DefaultJaasAuthenticationProvider(org.springframework.security.authentication.jaas.DefaultJaasAuthenticationProvider) Scope(org.springframework.context.annotation.Scope) ArrayList(java.util.ArrayList) AuthorityGranter(org.springframework.security.authentication.jaas.AuthorityGranter) JaasHttpCallbackHandlerFilter(com.thinkbiganalytics.auth.jaas.http.JaasHttpCallbackHandlerFilter) Map(java.util.Map) UserPrincipalAuthorityGranter(com.thinkbiganalytics.auth.UserPrincipalAuthorityGranter) Named(javax.inject.Named) JaasAuthenticationCallbackHandler(org.springframework.security.authentication.jaas.JaasAuthenticationCallbackHandler) Order(org.springframework.core.annotation.Order) InMemoryConfiguration(org.springframework.security.authentication.jaas.memory.InMemoryConfiguration) UsernameJaasAuthenticationProvider(com.thinkbiganalytics.auth.jaas.UsernameJaasAuthenticationProvider) Collectors(java.util.stream.Collectors) DefaultKyloJaasAuthenticationProvider(com.thinkbiganalytics.auth.jaas.DefaultKyloJaasAuthenticationProvider) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) DefaultPrincipalAuthorityGranter(com.thinkbiganalytics.auth.DefaultPrincipalAuthorityGranter) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) AbstractJaasAuthenticationProvider(org.springframework.security.authentication.jaas.AbstractJaasAuthenticationProvider) GroupPrincipalAuthorityGranter(com.thinkbiganalytics.auth.GroupPrincipalAuthorityGranter) Collections(java.util.Collections) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) InMemoryConfiguration(org.springframework.security.authentication.jaas.memory.InMemoryConfiguration) ArrayList(java.util.ArrayList) LoginConfiguration(com.thinkbiganalytics.auth.jaas.LoginConfiguration) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) Bean(org.springframework.context.annotation.Bean)

Example 3 with AnnotationAwareOrderComparator

use of org.springframework.core.annotation.AnnotationAwareOrderComparator in project cuba by cuba-platform.

the class DateIntervalEditor method getPredefinedDateIntervals.

protected Collection<PredefinedDateInterval> getPredefinedDateIntervals() {
    List<PredefinedDateInterval> intervals = new ArrayList<>(AppBeans.getAll(PredefinedDateInterval.class).values());
    intervals.sort(new AnnotationAwareOrderComparator());
    return intervals;
}
Also used : PredefinedDateInterval(com.haulmont.cuba.gui.components.filter.dateinterval.predefined.PredefinedDateInterval) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator)

Example 4 with AnnotationAwareOrderComparator

use of org.springframework.core.annotation.AnnotationAwareOrderComparator in project spring-security by spring-projects.

the class WebSecurityConfigurerAdapterTests method compareOrderWebSecurityConfigurerAdapterWhenLowestOrderToDefaultOrderThenGreaterThanZero.

@Test
public void compareOrderWebSecurityConfigurerAdapterWhenLowestOrderToDefaultOrderThenGreaterThanZero() {
    AnnotationAwareOrderComparator comparator = new AnnotationAwareOrderComparator();
    assertThat(comparator.compare(new LowestPriorityWebSecurityConfig(), new DefaultOrderWebSecurityConfig())).isGreaterThan(0);
}
Also used : AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) Test(org.junit.jupiter.api.Test)

Example 5 with AnnotationAwareOrderComparator

use of org.springframework.core.annotation.AnnotationAwareOrderComparator in project spring-framework by spring-projects.

the class AnnotationConfigUtils method registerAnnotationConfigProcessors.

/**
 * Register all relevant annotation post processors in the given registry.
 * @param registry the registry to operate on
 * @param source the configuration source element (already extracted)
 * that this registration was triggered from. May be {@code null}.
 * @return a Set of BeanDefinitionHolders, containing all bean definitions
 * that have actually been registered by this call
 */
public static Set<BeanDefinitionHolder> registerAnnotationConfigProcessors(BeanDefinitionRegistry registry, @Nullable Object source) {
    DefaultListableBeanFactory beanFactory = unwrapDefaultListableBeanFactory(registry);
    if (beanFactory != null) {
        if (!(beanFactory.getDependencyComparator() instanceof AnnotationAwareOrderComparator)) {
            beanFactory.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
        }
        if (!(beanFactory.getAutowireCandidateResolver() instanceof ContextAnnotationAutowireCandidateResolver)) {
            beanFactory.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
        }
    }
    Set<BeanDefinitionHolder> beanDefs = new LinkedHashSet<>(8);
    if (!registry.containsBeanDefinition(CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME)) {
        RootBeanDefinition def = new RootBeanDefinition(ConfigurationClassPostProcessor.class);
        def.setSource(source);
        beanDefs.add(registerPostProcessor(registry, def, CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME));
    }
    if (!registry.containsBeanDefinition(AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)) {
        RootBeanDefinition def = new RootBeanDefinition(AutowiredAnnotationBeanPostProcessor.class);
        def.setSource(source);
        beanDefs.add(registerPostProcessor(registry, def, AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
    }
    // Check for Jakarta Annotations support, and if present add the CommonAnnotationBeanPostProcessor.
    if (jakartaAnnotationsPresent && !registry.containsBeanDefinition(COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)) {
        RootBeanDefinition def = new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class);
        def.setSource(source);
        beanDefs.add(registerPostProcessor(registry, def, COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
    }
    // for the javax variant of PostConstruct/PreDestroy.
    if (jsr250Present && !registry.containsBeanDefinition(JSR250_ANNOTATION_PROCESSOR_BEAN_NAME)) {
        try {
            RootBeanDefinition def = new RootBeanDefinition(InitDestroyAnnotationBeanPostProcessor.class);
            def.getPropertyValues().add("initAnnotationType", classLoader.loadClass("javax.annotation.PostConstruct"));
            def.getPropertyValues().add("destroyAnnotationType", classLoader.loadClass("javax.annotation.PreDestroy"));
            def.setSource(source);
            beanDefs.add(registerPostProcessor(registry, def, JSR250_ANNOTATION_PROCESSOR_BEAN_NAME));
        } catch (ClassNotFoundException ex) {
        // Failed to load javax variants of the annotation types -> ignore.
        }
    }
    // Check for JPA support, and if present add the PersistenceAnnotationBeanPostProcessor.
    if (jpaPresent && !registry.containsBeanDefinition(PERSISTENCE_ANNOTATION_PROCESSOR_BEAN_NAME)) {
        RootBeanDefinition def = new RootBeanDefinition();
        try {
            def.setBeanClass(ClassUtils.forName(PERSISTENCE_ANNOTATION_PROCESSOR_CLASS_NAME, AnnotationConfigUtils.class.getClassLoader()));
        } catch (ClassNotFoundException ex) {
            throw new IllegalStateException("Cannot load optional framework class: " + PERSISTENCE_ANNOTATION_PROCESSOR_CLASS_NAME, ex);
        }
        def.setSource(source);
        beanDefs.add(registerPostProcessor(registry, def, PERSISTENCE_ANNOTATION_PROCESSOR_BEAN_NAME));
    }
    if (!registry.containsBeanDefinition(EVENT_LISTENER_PROCESSOR_BEAN_NAME)) {
        RootBeanDefinition def = new RootBeanDefinition(EventListenerMethodProcessor.class);
        def.setSource(source);
        beanDefs.add(registerPostProcessor(registry, def, EVENT_LISTENER_PROCESSOR_BEAN_NAME));
    }
    if (!registry.containsBeanDefinition(EVENT_LISTENER_FACTORY_BEAN_NAME)) {
        RootBeanDefinition def = new RootBeanDefinition(DefaultEventListenerFactory.class);
        def.setSource(source);
        beanDefs.add(registerPostProcessor(registry, def, EVENT_LISTENER_FACTORY_BEAN_NAME));
    }
    return beanDefs;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator)

Aggregations

AnnotationAwareOrderComparator (org.springframework.core.annotation.AnnotationAwareOrderComparator)5 PredefinedDateInterval (com.haulmont.cuba.gui.components.filter.dateinterval.predefined.PredefinedDateInterval)1 DefaultPrincipalAuthorityGranter (com.thinkbiganalytics.auth.DefaultPrincipalAuthorityGranter)1 GroupPrincipalAuthorityGranter (com.thinkbiganalytics.auth.GroupPrincipalAuthorityGranter)1 UserPrincipalAuthorityGranter (com.thinkbiganalytics.auth.UserPrincipalAuthorityGranter)1 DefaultKyloJaasAuthenticationProvider (com.thinkbiganalytics.auth.jaas.DefaultKyloJaasAuthenticationProvider)1 LoginConfiguration (com.thinkbiganalytics.auth.jaas.LoginConfiguration)1 LoginConfigurationBuilder (com.thinkbiganalytics.auth.jaas.LoginConfigurationBuilder)1 UsernameJaasAuthenticationProvider (com.thinkbiganalytics.auth.jaas.UsernameJaasAuthenticationProvider)1 JaasHttpCallbackHandlerFilter (com.thinkbiganalytics.auth.jaas.http.JaasHttpCallbackHandlerFilter)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Named (javax.inject.Named)1 AppConfigurationEntry (javax.security.auth.login.AppConfigurationEntry)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1