Description
Summary
In the following example the constructor of the SecuredAnnotationSecurityMetadataSource cannot understand the type of the annotation and instead of assigning the value "MyCustomAnnotation" in the annotationType field it assigns the value "Annotation"
which later does not allow the org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor to be triggered for any method that is annotated with the "MyCustomAnnotation" annotation.
public class CustomMethodSecurityConfiguration extends GlobalMethodSecurityConfiguration {
@Override
protected MethodSecurityMetadataSource customMethodSecurityMetadataSource() {
return new SecuredAnnotationSecurityMetadataSource(annotationMetaDataExtractor());
}
private AnnotationMetadataExtractor<MyCustomAnnotation> annotationMetaDataExtractor() {
return (MyCustomAnnotation securityAnnotation) -> Collections.singleton((ConfigAttribute) () -> "test");
}
}
When rewriting the annotationMetaDataExtractor method without lambdas, the annotationType field of the SecuredAnnotationSecurityMetadataSource is correctly set to "MyCustomAnnotation" and the interceptor is triggered as expected
private AnnotationMetadataExtractor<MyCustomAnnotation> annotationMetaDataExtractor() {
return new AnnotationMetadataExtractor<MyCustomAnnotation>() {
@Override
public Collection<? extends ConfigAttribute> extractAttributes(MyCustomAnnotation securityAnnotation) {
return Collections.singleton((ConfigAttribute) () -> "test");
}
};
}
Actual Behavior
org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor not to be triggered for any method that is annotated with the "MyCustomAnnotation" annotation.
Expected Behavior
Any method annotation with @MyCustomAnnotation should be picked up by the interceptor (and apply the security logic)
Version
spring-security-code: 5.5.3