Search in sources :

Example 1 with AdviceMode

use of org.springframework.context.annotation.AdviceMode in project spring-security by spring-projects.

the class GlobalMethodSecuritySelector method selectImports.

@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
    Class<EnableGlobalMethodSecurity> annoType = EnableGlobalMethodSecurity.class;
    Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(annoType.getName(), false);
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(annotationAttributes);
    Assert.notNull(attributes, () -> String.format("@%s is not present on importing class '%s' as expected", annoType.getSimpleName(), importingClassMetadata.getClassName()));
    // TODO would be nice if could use BeanClassLoaderAware (does not work)
    Class<?> importingClass = ClassUtils.resolveClassName(importingClassMetadata.getClassName(), ClassUtils.getDefaultClassLoader());
    boolean skipMethodSecurityConfiguration = GlobalMethodSecurityConfiguration.class.isAssignableFrom(importingClass);
    AdviceMode mode = attributes.getEnum("mode");
    boolean isProxy = AdviceMode.PROXY == mode;
    String autoProxyClassName = isProxy ? AutoProxyRegistrar.class.getName() : GlobalMethodSecurityAspectJAutoProxyRegistrar.class.getName();
    boolean jsr250Enabled = attributes.getBoolean("jsr250Enabled");
    List<String> classNames = new ArrayList<>(4);
    if (isProxy) {
        classNames.add(MethodSecurityMetadataSourceAdvisorRegistrar.class.getName());
    }
    classNames.add(autoProxyClassName);
    if (!skipMethodSecurityConfiguration) {
        classNames.add(GlobalMethodSecurityConfiguration.class.getName());
    }
    if (jsr250Enabled) {
        classNames.add(Jsr250MetadataSourceConfiguration.class.getName());
    }
    return classNames.toArray(new String[0]);
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) AdviceMode(org.springframework.context.annotation.AdviceMode) ArrayList(java.util.ArrayList) AutoProxyRegistrar(org.springframework.context.annotation.AutoProxyRegistrar)

Aggregations

ArrayList (java.util.ArrayList)1 AdviceMode (org.springframework.context.annotation.AdviceMode)1 AutoProxyRegistrar (org.springframework.context.annotation.AutoProxyRegistrar)1 AnnotationAttributes (org.springframework.core.annotation.AnnotationAttributes)1