apache shiro权限认证类
来源:互联网 发布:淘宝windows 编辑:程序博客网 时间:2024/05/16 06:47
- public class ShiroDbRealm extends AuthorizingRealm {
-
- @Inject
-
- private UserService userService ;
-
-
-
-
-
-
-
-
-
- protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
- throws AuthenticationException {
-
- UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
-
- User user= userService.getUserByUserId(token.getUsername());
-
- if (user!= null) {
-
- return new SimpleAuthenticationInfo(user.getUserId(), user.getUserId(), getName());
-
- } else {
-
- return null;
-
- }
-
- }
-
-
-
-
-
-
-
- protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
-
- String loginName = (String) principals.fromRealm(getName()).iterator().next();
-
- User user= userService.getUserByUserId(loginName);
-
- if (user != null) {
-
- SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
-
- info.addStringPermission("common-user");
-
- return info;
-
- } else {
-
- return null;
-
- }
-
- }
-
- }