mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
重构版功能实现
This commit is contained in:
@@ -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;
|
||||
}
|
||||
//密码认证(防止泄露,不需要我们做)
|
||||
|
||||
Reference in New Issue
Block a user