重构版功能实现

This commit is contained in:
tiansh
2021-10-28 18:54:05 +08:00
parent 3a03c965e1
commit 551bb6c20a
64 changed files with 881 additions and 6794 deletions
@@ -28,38 +28,28 @@ public class UserRealm extends AuthorizingRealm {
//授权
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
// System.out.println("..///执行了授权方法");
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
//拿到当前登录的对象
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
ArrayList<String> roleList = new ArrayList();
if(user.getLevel()==2){
//赋予管理员权限
// info.addRole("admin");
roleList.add("admin");
roleList.add("user");
// info.addStringPermission("user:one");
}else{
// info.addRole("user");
roleList.add("user");
}
info.addRoles(roleList);
return info;
}
//认证(登录)
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken tokenOBJ) throws AuthenticationException {
// System.out.println("执行了认证方法");
UsernamePasswordToken userToken = null;
userToken = (UsernamePasswordToken)tokenOBJ;
User user = new User();
user.setEmail(userToken.getUsername());
User u = userService.getUsers(user);
//用户名认证
if(u==null){
//返回null 就是异常:UnknownAccountException
return null;
}
//密码认证(防止泄露,不需要我们做)