Skip to content
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

Fix locale for authfail to be consistant with g:message FormatTagLib resolveLocale #1025

Merged
merged 1 commit into from
Oct 11, 2024

Conversation

codeconsole
Copy link
Contributor

@codeconsole codeconsole commented Sep 27, 2024

request.locale gets the user's locale, but not the locale set by the user.

g:message gets the locale set by the user and what is used by all the other locations of this plugin.

this fix makes the behavior consistent with the rest of the plugin.

https://github.com/grails/grails-gsp/blob/7ad985676e6217ad331f75aafad8258c1cb9d8cb/grails-plugin-gsp/src/main/groovy/org/grails/plugins/web/taglib/FormatTagLib.groovy#L336-L349

@@ -104,18 +105,19 @@ class LoginController {
String msg = ''
def exception = session[WebAttributes.AUTHENTICATION_EXCEPTION]
if (exception) {
def locale = GrailsWebRequest.lookup().getLocale() ?: Locale.getDefault()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of GrailsWebRequest.lookup().getLocale() ?: Locale.getDefault() I think you could just use LocaleContextHolder.locale which should give you the same result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matrei "should" ? I took the logic from FormatTagLib.groovy#L336-L349
can you confirm 100% it will give the same result. If so, FormatTagLib would need to be updated as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Should" as in I have not tested it in this context.

According to https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/i18n/LocaleContextHolder.html#getLocale():

Return the Locale associated with the current thread, if any, or the system default Locale otherwise

From https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-servlet/localeresolver.html:

When a request comes in, the DispatcherServlet looks for a locale resolver and, if it finds one, it tries to use it to set the locale.

By default in a Grails app, that is a SessionLocaleResolver, set by GrailsI18nPlugin.doWithSpring().

GrailsWebRequest.lookup().getLocale() will eventually end up using the same LocaleResolver to get the Locale but it will not fallback to using the system Locale.

@codeconsole codeconsole merged commit c94ca5d into grails:6.1.x Oct 11, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants