zoukankan      html  css  js  c++  java
  • 每天学点Shiro-盐值加密

    1. spring-context-shiro文件中配置Matcher

     <bean id="jdbcRealm" class="com.pawn.shiro.realm.MyRealm">
            <property name="credentialsMatcher" ref="credentialsMatcher">
            </property>
        </bean>
    
        <bean id="credentialsMatcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
            <property name="hashAlgorithmName" value="MD5"/>
            <property name="hashIterations" value="1"/>
        </bean>

    2. 修改realm,将从db中获取的凭证修改为密文,并且返回规定的盐值

     protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken)
                throws AuthenticationException {
    
            System.out.println("=========>MyRealm doGetAuthenticationInfo");
            UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
            String username = token.getUsername() ;
    
            if("unknown".equals(username)){
                throw new UnknownAccountException("用户名不存在") ;
            }
    
            Object principal = username ;
            Object credentials= "a66abb5684c45962d887564f08346e8d" ;
            ByteSource credentialsSalt = ByteSource.Util.bytes(username);
            String realmName = getName() ;
    
            AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(principal,credentials,credentialsSalt,realmName) ;
    
            return authenticationInfo;
        }
  • 相关阅读:
    进程、线程
    timer控件、三级联动
    用户控件、动态创建添加
    打印控件
    窗体移动和阴影,对话框控件
    winform listview控件
    winform打开唯一窗体、构造函数传值
    菜单和工具栏
    winform公共控件
    hibernate中各种包的添加
  • 原文地址:https://www.cnblogs.com/xpawn/p/7615159.html
Copyright © 2011-2022 走看看