-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Method security annotation intercepts the ExceptionHandler method #15507
Comments
Hi @kse-music. Have you verified if the problem persists in the latest version? Looks like it has been fixed via #15352 |
@marcusdacoregio The latest version still exists |
In addition, I think this is a common problem, because after the BeanPostProcessor ( I'm not sure if I need to add a mechanism to exclude the methods of spring internal interfaces, such as ApplicationListener SmartLifecycle etc. |
While I'm interested in continuing this conversation, I'm not sure how much effort we should put into skipping certain methods when a class-level annotation is in place. Ostensibly, placing The better solution, I believe, is to instead place the annotation on a parent interface that more clearly indicates which methods or to place the annotation directly on the methods that need authorization. The technique outlined here may also be of interest. For my reference, can you please produce a sample that uses a Spring Security version where the above application works as you expect? |
I have added sample code
I agree, but technically it does exist.In my sample code:
The fix here solves gh-15352, but also causes gh-13783 to fail, even in 6.4.0-M3. I copied the code in gh-13783 to the gh13789 package of the sample code: |
I hear your concerns, @kse-music. Since it seems your most recent comments are about how Spring Security searches hierarchically for annotations, let's continue chatting about that at #15352 so that the conversation doesn't become fragmented.
Your point here is well-taken though I don't know how we can provide a complete solution to avoid all the methods that folks might want to skip. Better, I think is to either publish a technique or to make the default configuration simple to alter. For example, if an application is determined to use @Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
static AuthorizationAdvisor preAuthorizeAuthorizationAdvisor() {
AuthorizationManagerBeforeMethodInterceptor preAuthorize =
AuthorizationManagerBeforeMethodInterceptor.preAuthorize();
Pointcut hasPreAuthorizeAnnotation = preAuthorize.getPointcut();
String expression = "!@annotation(org.springframework.web.bind.annotation.ExceptionHandler)";
Pointcut skipExceptionHandler = new AspectJPointcutExpression(expression);
preAuthorize.setPointcut(Pointcuts.intersection(hasPreAuthorizeAnnotation, skipExceptionHandler));
return preAuthorize;
} |
Affect all branch
Describe the bug
The exception handler method defined in the
Controller
is intercepted by the security annotationTo Reproduce
see Sample code
Expected behavior
The exception handler method
handleException
can be executedSample
Demo
The text was updated successfully, but these errors were encountered: