我是Apache Shiro的初学者。我一直在关注文档以及许多其他教程,博客等。但是我只是无法进行身份验证。当我尝试使用有效的用户名和密码登录时,总是被InvalidCredentialsException
抛出。我将DynamoDB用作存储用户凭据的自定义领域,但我真的认为这并不重要。显然,这是我存储和/或进行凭据匹配的方式,这是不正确的。这是我的设置:
Shiro.ini:
[main]
myRealm = com.enki.closing.users.DynamoDBRealm
credentialsMatcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
credentialsMatcher.storedCredentialsHexEncoded = false
credentialsMatcher.hashIterations = 1024
myRealm.credentialsMatcher = $credentialsMatcher
创建用户帐户:
String password = ...
ByteSource passwordSalt = new SecureRandomNumberGenerator().nextBytes();
String hashedPasswordBase64 = new Sha256Hash(password, passwordSalt, 1024).toBase64();
// store the hashedPassword and salt in DynamoDB...
// I've tried storing the salt with and without base64 encoding.
密码和盐可以很好地存储在DynamoDB中,这些值看起来还不错。这是身份验证的自定义领域:
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
UsernamePasswordToken userPass = (UsernamePasswordToken) token;
String username = userPass.getUsername();
...
// pull the matching password and salt out of DynamoDB, no problems...
ByteSource passwordSalt = ByteSource.Util.bytes( storedPasswordSalt );
return new SimpleAuthenticationInfo(username, passwordHash, passwordSalt, getName());
}
这几乎完全是文档告诉我要做的,但是有些事情不正确。当我尝试登录时,它得到InvalidCredentialsException
。
我想出了如何使其工作。我不得不更改此设置(在我的自定义领域中):
ByteSource passwordSalt = ByteSource.Util.bytes( storedPasswordSalt );
对此:
ByteSource passwordSalt = ByteSource.Util.bytes(
Base64.decode( storedPasswordSalt) );
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句