UsernamePasswordAuthenticationToken

简介: UsernamePasswordAuthenticationToken继承AbstractAuthenticationToken实现Authentication所以当在页面中输入用户名和密码之后首先会进入到UsernamePasswordAuthenticationToken验证(Authen...

 

UsernamePasswordAuthenticationToken继承AbstractAuthenticationToken实现Authentication
所以当在页面中输入用户名和密码之后首先会进入到UsernamePasswordAuthenticationToken验证(Authentication),
然后生成的Authentication会被交由AuthenticationManager来进行管理
而AuthenticationManager管理一系列的AuthenticationProvider,
而每一个Provider都会通UserDetailsService和UserDetail来返回一个
以UsernamePasswordAuthenticationToken实现的带用户名和密码以及权限的Authentication

 

public class SecurityProvider implements AuthenticationProvider {
    @Autowired
    private MyUserDetailService userDetailsService;
    @Override
    public Authentication authenticate(Authentication authentication)
            throws AuthenticationException {
//
        UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
        UserDetails userDetails = userDetailsService.loadUserByUsername(token.getName());
        if (userDetails == null) {
            throw new UsernameNotFoundException("找不到该用户");
        }
        if(!userDetails.getPassword().equals(token.getCredentials().toString()))
        {
              throw new BadCredentialsException("密码错误");
        }
        return new UsernamePasswordAuthenticationToken(userDetails,userDetails.getPassword(),userDetails.getAuthorities());
    }

    @Override
    public boolean supports(Class<?> authentication) {
        // TODO Auto-generated method stub
        return UsernamePasswordAuthenticationToken.class.equals(authentication);
    }

}

https://github.com/Somersames/MySecurity

 http://www.jdon.com/dl/best/securing-rest-services-with-spring.html.html

http://stackoverflow.com/questions/8764545/how-to-get-active-users-userdetails/8769670#8769670

 

相关文章
|
监控 安全
什么是 sporadic user
什么是 sporadic user
|
数据安全/隐私保护
Shiro之UsernamePasswordToken&RememberMeAuthenticationToken&AuthenticationToken
Shiro之UsernamePasswordToken&RememberMeAuthenticationToken&AuthenticationToken
|
开发工具 git
Incorrect username or password (access token)
Incorrect username or password (access token)
173 0
Incorrect username or password (access token)
|
NoSQL Redis 数据安全/隐私保护
AUTH password
为redis服务请求设置一个密码。redis可以设置在客户端执行commands请求前需要通过密码验证。通过修改配置文件的requirepass就可以设置密码。 如果密码与配置文件里面设置的密码一致,服务端就会发会一个OK的状态码,接受客户端发送其他的请求命令,否则服务端会返回一个错误码,客户端需要尝试使用新的密码来进行连接。
1130 0
|
索引
1035. Password (20)
To prepare for PAT, the judge sometimes has to generate random passwords for the users.
968 0
|
数据安全/隐私保护 网络架构 网络安全
|
数据安全/隐私保护 网络架构 网络安全
|
数据安全/隐私保护