Spring Security: Custom exception message from UserDetailsService

后端 未结 2 1015
一生所求
一生所求 2021-02-08 13:59

I am able to display the SPRING_SECURITY_LAST_EXCEPTION.message (\"Bad Credentials\") when a user tries to log in with incorrect credentials or user is disabled for some reason.

2条回答
  •  失恋的感觉
    2021-02-08 14:14

    Create a property file in class path like loginMessage.properties

    In that property file, specify

    AbstractUserDetailsAuthenticationProvider.badCredentials=Username/Password entered is incorrect.

    Add the following bean in your applicationContext.xml,

      
          
            
                loginMessage
            
        
    
    

    In userDao, if result null

    throw new UsernameNotFoundException("");
    

    After that, u'll get message like Username/Password entered is incorrect. instead of Bad Credentials

提交回复
热议问题