1.将前台获取的用户名和密码生成token交给shiro
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(USERNAME, PASSWORD);
try {
subject.login(token);
} catch (AuthenticationException e) {
errInfo = "身份验证失败!";
}
2.实现AuthorizingRealm 重写doGetAuthenticationInfo方法,解析tokenString username = (String)token.getPrincipal();
通过用户名在数据库中查询密码 return new SimpleAuthenticationInfo(username, password, getName());
匹配失败会报错