Skip to content

Commit

Permalink
Merge pull request #1024 from codeconsole/7.0.x-fix-authfail-locale
Browse files Browse the repository at this point in the history
Fix locale for authfail to be consistant with g:message FormatTagLib resolveLocale
  • Loading branch information
codeconsole authored Sep 27, 2024
2 parents 5ee8c34 + fa10e4a commit 0314580
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package grails.plugin.springsecurity

import grails.converters.JSON
import org.grails.web.servlet.mvc.GrailsWebRequest
import org.springframework.context.MessageSource
import org.springframework.security.access.annotation.Secured
import org.springframework.security.authentication.AccountExpiredException
Expand Down Expand Up @@ -104,18 +105,19 @@ class LoginController {
String msg = ''
def exception = session[WebAttributes.AUTHENTICATION_EXCEPTION]
if (exception) {
def locale = GrailsWebRequest.lookup().getLocale() ?: Locale.getDefault()
if (exception instanceof AccountExpiredException) {
msg = messageSource.getMessage('springSecurity.errors.login.expired', null, "Account Expired", request.locale)
msg = messageSource.getMessage('springSecurity.errors.login.expired', null, "Account Expired", locale)
} else if (exception instanceof CredentialsExpiredException) {
msg = messageSource.getMessage('springSecurity.errors.login.passwordExpired', null, "Password Expired", request.locale)
msg = messageSource.getMessage('springSecurity.errors.login.passwordExpired', null, "Password Expired", locale)
} else if (exception instanceof DisabledException) {
msg = messageSource.getMessage('springSecurity.errors.login.disabled', null, "Account Disabled", request.locale)
msg = messageSource.getMessage('springSecurity.errors.login.disabled', null, "Account Disabled", locale)
} else if (exception instanceof LockedException) {
msg = messageSource.getMessage('springSecurity.errors.login.locked', null, "Account Locked", request.locale)
msg = messageSource.getMessage('springSecurity.errors.login.locked', null, "Account Locked", locale)
} else if (exception instanceof SessionAuthenticationException) {
msg = messageSource.getMessage('springSecurity.errors.login.max.sessions.exceeded', null, "Sorry, you have exceeded your maximum number of open sessions.", request.locale)
msg = messageSource.getMessage('springSecurity.errors.login.max.sessions.exceeded', null, "Sorry, you have exceeded your maximum number of open sessions.", locale)
} else {
msg = messageSource.getMessage('springSecurity.errors.login.fail', null, "Authentication Failure", request.locale)
msg = messageSource.getMessage('springSecurity.errors.login.fail', null, "Authentication Failure", locale)
}
}

Expand Down

0 comments on commit 0314580

Please sign in to comment.