@Override doGetAuthenticationInfo 方法的密码认证解析
在代码中,实际上已经将用户输入的密码与从数据库中查询的该用户的密码进行了比较认证。这一步是通过构建 'SimpleAuthenticationInfo' 对象时传入的参数完成的:
new SimpleAuthenticationInfo(
user, //principal 身份
user.getPassword(),//hashedCredentials 已加密的密码
credentialsSalt,//credentialsSalt
this.getName());//realmName
其中,第二个参数 'user.getPassword()' 就是从数据库中查询到的该用户的密码,而第一个参数 'user' 则是用户对象,会在后续的授权操作中使用。'SimpleAuthenticationInfo' 对象的构建完成后,会被交给认证管理器 ('SecurityManager') 进行认证。在认证过程中,认证管理器会比较用户输入的密码和 'SimpleAuthenticationInfo' 中的已加密密码是否一致,如果一致则认证通过,否则认证失败。
原文地址: http://www.cveoy.top/t/topic/osAb 著作权归作者所有。请勿转载和采集!