所有操作都在shiro 框架中
将我们的对象转化为shiro框架中的对象
UsernamePasswordToken token = new UsernamePasswordToken(user.getUserName(), user.getPassword()); Subject currentUser = SecurityUtils.getSubject();
currentUser.login(token);
login 将进入class UserRealm extends AuthorizingRealm中的
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {方法
AuthenticationToken是 UsernamePasswordToken 的父类
2.查找数据库中的user,产生shiro中的对象new SimpleAuthenticationInfo(user, user.getPassword(),this.getClass().getName());//放入shiro.调用
3.进入configuration,设置的自定义的 class CredentialsMatcher extends SimpleCredentialsMatcher{
doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {中
AuthenticationInfo 是SimpleAuthenticationInfo 的父类。
,在方法中进行比较两个对象中的密码是否相等。
//输入的用户名和密码
UsernamePasswordToken utoken=(UsernamePasswordToken) token;
String inPassword = new String(utoken.getPassword());
SimpleHash sh2 = new SimpleHash("md5", inPassword, "Shiro", 3);
System.out.println(sh2); //对其进行加密。
//数据库中的密码为加密后的密码
String dbPassword=(String) info.getCredentials();
return this.equals(sh2.toString(),dbPassword);
4.如果匹配了就登入,如果不匹配就跳转到configuration中设定的错误方法中。