jdbcRealm中加密身份验证

来源:互联网 发布:免费上网的软件 编辑:程序博客网 时间:2024/06/01 08:56
xml配置
<bean id="hashService" class="org.apache.shiro.crypto.hash.DefaultHashService">    <property name="hashAlgorithmName" value="MD5"></property>    <property name="hashIterations" value="3"></property>    <property name="generatePublicSalt" value="true"></property>    </bean>        <bean id="passwordService" class="org.apache.shiro.authc.credential.DefaultPasswordService">    <property name="hashService" ref="hashService"></property>    </bean>        <bean id="credentialsMatcher" class="org.apache.shiro.authc.credential.PasswordMatcher">    <property name="passwordService" ref="passwordService"></property>    </bean>        <!-- 自定义Realm --><bean id="myRealm" class="org.apache.shiro.realm.jdbc.JdbcRealm"><property name="authenticationQuery" value="select password from users where username = ?"></property><property name="userRolesQuery" value="SELECT r.role_name FROM roles r INNER JOIN users u ON u.username=? INNER JOIN users_roles ur ON ur.u_id=u.id AND ur.r_id=r.id"></property><property name="permissionsQuery" value="SELECT p.permission FROM roles r INNER JOIN permissions p , roles_permissions rp WHERE p.id=rp.p_id AND r.id=r_id AND r.role_name=?"></property><property name="permissionsLookupEnabled" value="true"></property><property name="dataSource" ref="dataSource"></property><property name="credentialsMatcher" ref="credentialsMatcher"></property></bean>


PasswordMatcher  cm =  (PasswordMatcher) myRealm.getCredentialsMatcher();String encPassword = cm.getPasswordService().encryptPassword(user.getPassword());


原创粉丝点击