Announcement Announcement Module
Collapse
No announcement yet.
Using I18n in the login page Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using I18n in the login page

    Hi folks,

    I would like to show messages personalized with UsernameNotFoundException in my login page 8)
    <%
    ((AuthenticationException) session.getAttribute(AbstractProcessingFilter.ACEG I_SECURITY_LAST_EXCEPTION_KEY)).getMessage()
    %>
    but, all exception that is throwed in AuthenticationDao.loadUserByUsername
    public UserDetails loadUserByUsername(String username)
    throws UsernameNotFoundException, DataAccessException;
    it is catched in DaoAuthenticationProvider.getUserFromBackend and substituted by BadCredentialsException
    private UserDetails getUserFromBackend(String username) {
    try {
    return this.authenticationDao.loadUserByUsername(username );
    } catch (UsernameNotFoundException notFound) {
    throw new BadCredentialsException("Bad credentials presented");
    } catch (DataAccessException repositoryProblem) {
    throw new AuthenticationServiceException(repositoryProblem
    .getMessage(), repositoryProblem);
    }
    }
    How I can show my proper messages?

  • #2
    In CVS HEAD DaoAuthenticationProvider version 1.24 was updated last week:


    Code:
        private UserDetails getUserFromBackend&#40;String username&#41; &#123;
            try &#123;
                return this.authenticationDao.loadUserByUsername&#40;username&#41;;
            &#125; catch &#40;UsernameNotFoundException notFound&#41; &#123;
                if &#40;hideUserNotFoundExceptions&#41; &#123;
                    throw new BadCredentialsException&#40;"Bad credentials presented"&#41;;
                &#125; else &#123;
                    throw notFound;
                &#125;
            &#125; catch &#40;DataAccessException repositoryProblem&#41; &#123;
                throw new AuthenticationServiceException&#40;repositoryProblem
                    .getMessage&#40;&#41;, repositoryProblem&#41;;
            &#125;
        &#125;
    So your different exception is no longer "swallowed" if you set the hideUserNotFoundExceptions to false (it defaults to true).

    Comment


    • #3
      Great solution

      Hello Ben,

      Great solution :!:

      Best Regards,

      Comment

      Working...
      X