MyAuthenticationProvider.java 文件源码

java
阅读 61 收藏 0 点赞 0 评论 0

项目:AngularAndSpring 作者:
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String name = authentication.getName();
    String password = authentication.getCredentials().toString();       
    Query query = new Query();
    query.addCriteria(Criteria.where("userId").is(name));
    MyUser user = operations.findOne(query, MyUser.class).block();
    String encryptedPw = null;
    try {
        encryptedPw = this.passwordEncryption.getEncryptedPassword(password, user.getSalt());
    } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
        log.error("Pw decrytion error: ",e);
    }
    if(encryptedPw == null || !encryptedPw.equals(user.getPassword())) {
        throw new AuthenticationCredentialsNotFoundException("User: "+name+" not found.");
    }
    log.info("User: "+name+" logged in.");
    return new UsernamePasswordAuthenticationToken(
            name, password, user.getAuthorities());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号