apache shiro无法使用PasswordMatcher检查md5密码

问题描述 投票:0回答:2

我正在使用shiro 1.4.0。

我的密码是MD5,如果我使用HashedCredentialsMatcher,那么我可以登录成功:

  [main]

    shiro.loginUrl = /login.jsp
    shiro.successUrl = /home.jsp
 passwordMatcher=org.apache.shiro.authc.credential.HashedCredentialsMatcher
    passwordMatcher.hashAlgorithmName=MD5
    passwordMatcher.storedCredentialsHexEncoded=true

    ds = com.mchange.v2.c3p0.ComboPooledDataSource
    ds.driverClass = com.mysql.jdbc.Driver
    ds.jdbcUrl = jdbc:mysql://localhost:3306/simple_shiro_web_app
    ds.user = test
    ds.password = 123456

    jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
    jdbcRealm.permissionsLookupEnabled = true
    jdbcRealm.authenticationQuery = SELECT password FROM USERS WHERE username = ?
    jdbcRealm.userRolesQuery = SELECT role_name FROM USERS_ROLES WHERE username = ?
    jdbcRealm.permissionsQuery = SELECT permission_name FROM ROLES_PERMISSIONS WHERE role_name = ?
    jdbcRealm.credentialsMatcher = $passwordMatcher
    jdbcRealm.dataSource=$ds

    securityManager.realm = $jdbcRealm

但是,如果我使用PasswordMatcher(tomcat启动时没有任何错误消息),那么我登录失败:

passwordMatcher = org.apache.shiro.authc.credential.PasswordMatcher
passwordService = org.apache.shiro.authc.credential.DefaultPasswordService
passwordService.hashService.hashAlgorithmName=MD5
passwordMatcher.passwordService = $passwordService

似乎仍然使用默认的SHA-256,为什么?

另外,在1.4中,org.apache.shiro.crypto.hash.DefaultHashService.classshiro-core.jar中有相同的类和相同的包名(例如shiro-crypto-hash.jar),有什么区别和原因?

- - - - - - - 更新 - - - - - - - - - - - - -

有一条日志消息:

TRACE ClassUtils.forName - Unable to load class named [e10adc3949ba59abbe56e057f20f] from the current ClassLoader.  Trying the system/application ClassLoader...

虽然e10adc3949ba59abbe56e057f20f是我的md5密码。

shiro
2个回答
0
投票

日志中的任何警告?如果不是LdapRealm.doGetAuthenticationInfo(),看看你是否得到了你期望的密码。

在1.4中,一些代码已被移动到其他模块中(尽管它们将以与1.4之前相同的方式解析)


0
投票

通过调试,我发现DefaultPasswordService使用base64哈希格式。在我将哈希格式更改为hex后,它就可以了。

<bean id="hexFormat" class="org.apache.shiro.crypto.hash.format.HexFormat">

    </bean>

     <bean id="passwordService" class="org.apache.shiro.authc.credential.DefaultPasswordService">
        <property name="hashService" ref="hashService" />
        <property name="hashFormat" ref="hexFormat" />
    </bean>
© www.soinside.com 2019 - 2024. All rights reserved.