• shiro自定义realm


    [main]
    myAuthorRealm=cn.shiro.mytest.realm.MyAuthorRealm
    securityManager.realms=$myAuthorRealm

    /**
     * 自定义realm
     * 在这个类中处理身份认证及权限判断
     * @author Administrator
     *
     */
    public class MyAuthorRealm extends AuthorizingRealm {
    
        /**
         * 完成授权
         */
        @Override
        protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection pc) {
            //从登录界面传递过来 username = "zhangwanfu"
            String username = (String)pc.getPrimaryPrincipal();
            //查询数据库得到授权
            String permission = "add,delete,update,select";
            String[] pers = permission.split(",");
            SimpleAuthorizationInfo simpleAuthorizationInfo
                 = new SimpleAuthorizationInfo();
            //将4条字符串添加到授权集合
            for(String pr:pers){
                simpleAuthorizationInfo.addStringPermission(pr);
            }
            
            return simpleAuthorizationInfo;
        }
    
        /**
         * 完成身份认证
         */
        @Override
        protected AuthenticationInfo doGetAuthenticationInfo(
                AuthenticationToken token) throws AuthenticationException {
            
            //从登录传过来的username  zhangwanfu
            String username = (String)token.getPrincipal();
            //查询数据库得到zhangwanfu的密码
            String password = "123456";
            SimpleAuthenticationInfo simpleAuthenticationInfo
                 = new SimpleAuthenticationInfo(username, password, "MyAuthorRealm");
            return simpleAuthenticationInfo;
        }
    
    }
  • 相关阅读:
    STL Allocator
    Several NeedToKnow(assert/stdin/stdout/CString/Standard C++ Library)
    VS Project Property Sheet
    进度总结(3)
    进度总结(2)
    进度总结(4)
    进度总结(7)
    进度总结(1)
    进度总结(5)
    进度总结(6)
  • 原文地址:https://www.cnblogs.com/yoyo198212/p/8413091.html
Copyright © 2020-2023  润新知