zoukankan      html  css  js  c++  java
  • shiro凭证配置

    shiro凭证配置

    1、方式一

    在自定义realm的构造器中配置凭证匹配器对象

    public UserRealm() {
            //凭证匹配器对象
            HashedCredentialsMatcher matcher=new HashedCredentialsMatcher();
            //指定加密算法
            matcher.setHashAlgorithmName("md5");
            //指定散列次数
            matcher.setHashIterations(2);
            
            setCredentialsMatcher(matcher);
        }
    

    在用户认证时指定盐

    ByteSource byteSource=ByteSource.Util.bytes("yl");
    /**
     *用户认证
     *参数说明:
     * 参数1:可以是任意对象,作为用户身份
     * 参数2:数据库查询出来的密码
     * 参数3:盐 
     * 参数4:当前类名
     */
    SimpleAuthenticationInfo info=newSimpleAuthenticationInfo(activeUser,user.getPassword(),byteSource,this.getName());
    

    2、方式二

    通过ini配置文件配置,指定盐的方式同上

    [main]
    # 创建凭证匹配器对象
    matcher= org.apache.shiro.authc.credential.HashedCredentialsMatcher
    matcher.hashAlgorithmName=md5 
    matcher.hashIterations=2
    # 创建userReaml对象
    userRealm= com.yl.shiro.UserRealm
    # 注入凭证匹配器到userReaml
    userRealm.credentialsMatcher=$matcher
    # 把userReaml注入安全管理器
    securityManager.realm=$userRealm
    

    3、方式三

    注入自定义realm时指定凭证匹配器,指定盐的方式同上

    UserRealm userRealm=new UserRealm();//自定义realm对象
    HashedCredentialsMatcher matcher=new HashedCredentialsMatcher();//凭证匹配器对象
    matcher.setHashAlgorithmName("md5");//指定加密算法
    matcher.setHashIterations(2);//指定散列次数
    userRealm.setCredentialsMatcher(matcher);//注入凭证匹配器
    
    记得快乐
  • 相关阅读:
    动态规划2.1 矩阵中的最短路径
    动态规划3.3 最长递增子序列
    动态规划3.2 最长公共子串
    动态规划3.1 求两个字符串的莱文斯坦编辑距离
    大数相乘
    科大讯飞C++面试经验
    存储世界的两个祖师爷和他们的后代们!!!
    读写(I/O)辩论
    集线器(HUB)、交换机、路由器的区别和联系 及OSI七层模型 及TCP/IP通信协议
    HTTP协议
  • 原文地址:https://www.cnblogs.com/Y-wee/p/13943764.html
Copyright © 2011-2022 走看看