-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add localization to error messages from ExceptionTranslationFilter #4504
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
Add localization to error messages from ExceptionTranslationFilter #4504
Conversation
@jgrandja any feedback? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @britter !
There has been very little updates to the localization of error messages in the past few years as it's not recommended to give any information to potential attackers on what the resulting error was. However, the updates you have provided are fine so I'll merge this PR after you apply the requested changes from my comments and add a test.
@@ -83,6 +86,8 @@ | |||
|
|||
private RequestCache requestCache = new HttpSessionRequestCache(); | |||
|
|||
private MessageSourceAccessor messages = SpringSecurityMessageSource.getAccessor(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add final modifier
@@ -0,0 +1 @@ | |||
ExceptionTranslationFilter.insufficientAuthentication=Full authentication is required to access this resource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this key to messages.properties (default bundle) as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
I need some time to work on a test, since I have to understand how the current tests work and how to make the test reliable on different system locales. Thank you! |
af837a8
to
ee54038
Compare
ee54038
to
c6e9376
Compare
@jgrandja all done. Let's see what Travis thinks. |
In by simple Spring Boot application with Basic Authentication, I can add localization and custom messages if somebody tries to access a resource with wrong credentials. This is implemented in
AbstractUserDetailsAuthenticationProvider
.However when somebody forgets to add authentication information the
ExceptionTranslationFilter
will throw anInsufficientAuthenticationException
. Since the message is hard coded, there is no easy way to customize or localize the error message.This PR adds localization using message bundles and a
MessageSourceAccessor
the same way as it is implemented inAbstractUserDetailsAuthenticationProvider
.