How to get the user entered values of username and password in a spring security authenticated login

后端 未结 2 1306
隐瞒了意图╮
隐瞒了意图╮ 2021-01-03 14:30

I use Spring MVC in my application and the login is authenticated by spring security. I have the following two methods in my UserServiceImpl.java class, public

2条回答
  •  盖世英雄少女心
    2021-01-03 15:00

    if you want, you can create your own AuthenticationProvider

    public class CustomAuthenticationProvider implements AuthenticationProvider{
    
        private UserDetailsService service;
    
        @Override
        public Authentication authenticate(Authentication authentication) throws AuthenticationException {
            UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
            String username = token.getName();
            String password = token.getCredentials(); // retrieve the password 
            // do something here
    
            // if ok then return the authentication
            return new UsernamePasswordAuthenticationToken(username, password, authorities);
        }
    }
    

    and plug it to your security configuration

    
      
    
    
    
      
        
          
        
      
    
    

提交回复
热议问题