shiro请求授权实现

1.config
Map<String, String> map = new LinkedHashMap<>();
map.put("/user/add","perms[user:add]");
map.put("/user/update","perms[user:update]");
bean.setUnauthorizedUrl("/noauth");
2.controller
@RequestMapping("/noauth")
@ResponseBody
public String unauthorized(){
return "未授权无法访问此页面";
}
3.为了更贴近需求,给不同的人授予不同的权限,所以给表加个字段perms

4.config
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
System.out.println("执行了授权");
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
Subject subject = SecurityUtils.getSubject();
User currentUser = (User) subject.getPrincipal();
info.addStringPermission(currentUser.getPerms());
return info;
}
