-
Notifications
You must be signed in to change notification settings - Fork 6k
Introduce Customizable AuthorizationFailureHandler in OAuth2AuthorizationRequestRedirectFilter #14168
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
Conversation
…tionRequestRedirectFilter
Hi @leewin12, thanks for the PR! My initial feedback is that I would prefer not to introduce a sub-interface into the filter for this case. Additionally, re-reading your issue description:
I'm not sure I am clear on how introducing a failure handler specifically solves the first problem ("Allow users to receive a more descriptive custom error message"). Can you describe how you would do this with a failure handler that differs from what we could do by wrapping and delegating to the existing Depending on your answer to the above, I think we should consider simply re-using |
Hi @sjohnr, Happy New Year!
I realize I may have conflated two different concepts: the users of Spring Security (developers) and the end-users of services built using Spring Security. I initially thought that developers could use the new AuthorizationFailureHandler to customize actions for failures, such as providing more detailed error messages, redirecting to specific pages, or returning specific HTTP error codes. However, wrapping and delegating to the existing OAuth2AuthorizationRequestResolver does not fully address this because the
Regarding your suggestion to reuse |
@leewin12 I apologize for the delay in response! 😬 It has been very busy the last several weeks.
I have pushed a branch with my idea for better illustration (see this commit). It wraps the thrown exception received from the process of resolving and redirecting (whatever that Whether this exception is authentication-related or not, I think we'll find as many reasons not to want/need a new interface just for this error as well. I also don't see a problem with needing to introduce something new later, as it would be an easy deprecation and replacement with a new type of error handler if needed (which I suspect won't ever be necessary). I also think this will handle both of your use cases. What do you think? |
Hi @leewin12, did you have a chance to see the branch I pushed (see above)? |
@willemvd Yes, I am able to finish this issue. thanks you for your professional courtesy. I will notify you if I am unable to do so. |
@sjohnr pr is ready for review. |
@leewin12 thank for picking it up! I looked at your PR and I think it is missing configuration so a developer can override the Another thing that I would like to change, is to make the In that sense, also the |
@willemvd I've agreed with your review and have applied all the points that you mentioned. Please take a look and feel free to share your thoughts. |
@leewin12 thanks for the changes! the only thing I'm missing is part 2 of my comment:
|
@willemvd oops, my mistake. I've just fixed it. Thank you once again for your review!! |
👍 LGTM! 😀 |
@sjohnr , gentle reminder, can you also have a look? 😄 |
@willemvd @leewin12 apologies, I have been out on vacation for 2 weeks. I have not yet had a chance to closely review the PR but will add it to my list for the week. Let me first respond to the comments you added.
Generally, I think we would wait on this type of change until it is deemed necessary/asked for. We prefer to keep the DSL minimal and not introduce unnecessary additions. In the meantime, you can set the new authentication failure handler by using the setter directly on the
I do not prefer to open up classes to the public API unless absolutely necessary, and I don't currently see a reason to do so. For context, the reason the private class |
My thoughts were that we can set it but from the DSL to keep it in line with the other setters, since doing it with manually registering or via the
Ok, agree! |
You are correct of course that they are more complex. The reasoning for waiting to update the DSL is that adding more methods to the DSL makes it more complex as well. So if very few users need to set this new field, we impact fewer users by leaving it off the DSL. I think the best course would be to simply file a new issue for adding it to the DSL and see if anyone else has interest. If so, we can easily add it as a separate PR. If nothing else, it keeps this PR focused on just one change. |
@sjohnr I remove those commits for supporting DSL and opening the private class. |
@sjohnr I am so glad to contribute. thanks to your guidance. |
Thanks for contributing, @leewin12!
We do not generally backport enhancements. We usually recommend that you copy the source of the class into your own project and use it in the interim, if you need to use it prior to upgrading. To register a customized version of the class as a filter, you will also need to register an |
@sjohnr okay, thank you for the advise. I am glad to contribute to spring-security. |
This PR introduces a new AuthorizationFailureHandler to OAuth2AuthorizationRequestRedirectFilter, Customizable AuthorizationFailureHandler in OAuth2AuthorizationRequestRedirectFilter (Related to gh-13793).
Since most failure handlers in Spring Security focus on AuthenticationException, I'm proposing a new failure handler specifically for the OAuth2AuthorizationRequestRedirectFilter to address a wider range of errors.
I welcome any alternative solutions or improvements you might suggest.
I will start working on the unit tests once this approach is confirmed.