jsf - apache shiro 使用哈希凭证无法成功登录

标签 jsf shiro

我正在使用 shiro,并且我使用哈希凭证作为我的凭证。

这是我的 shiro.ini 配置:

credentialsMatcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
credentialsMatcher.storedCredentialsHexEncoded = false
credentialsMatcher.hashIterations = 1024
realmA.credentialsMatcher = $credentialsMatcher
securityManager.realms = $realmA

下面是我生成盐和散列密码的方法:

RandomNumberGenerator rng = new SecureRandomNumberGenerator();
ByteSource salt = rng.nextBytes();
String passwordsalt=salt.toBase64();
String hashedPasswordBase64 = new Sha256Hash(user.getPassword(),
                    salt, 1024).toBase64();
user.setPassword(hashedPasswordBase64);
user.setByteTabSalt(passwordsalt);
dao.createUser(user);

这是我扩展的领域:

protected AuthenticationInfo doGetAuthenticationInfo(
            AuthenticationToken authToken) throws AuthenticationException {
        UsernamePasswordToken token = (UsernamePasswordToken) authToken;
        User user = dao.getForUsername(token.getUsername());
        if (user != null) {
            SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(
                    user.getEmail_account(), user.getPassword(), getName());
            ByteSource salt = new SimpleByteSource(Base64.decode(user
                    .getByteTabSalt()));
            info.setCredentialsSalt(salt);
            return info;
        } else {
            return null;
        }
    }

但是当我使用新生成的帐户登录时,我从未成功。 调试结果是我正确地获得了用户对象。有什么想法吗?

非常感谢。

最佳答案

HashedCredentialsMatcher 是一个较旧的 Shiro 概念。相反,我强烈建议使用 PasswordService 及其对应的 PasswordMatcher,如下所述:

https://shiro.apache.org/static/1.2.2/apidocs/org/apache/shiro/authc/credential/PasswordService.html

关于jsf - apache shiro 使用哈希凭证无法成功登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17048153/

相关文章:

java - 集合未按预期顺序排序,例如±±在zzz之后

java - JSF 2.0 : Why does f:ajax send all the form fields and not only those marked with execute-attribute?

validation - 当用户想要覆盖时,JSF 表单验证会跳过第二次提交的特定验证器

security - 如何使用 Apache Shiro 处理分层角色/权限?

grails - 访问 grails shiro 插件中的特定 Controller

java - 未定义名为 'shiroFilter' 的 bean

java - NoSuchMethodError : org. slf4j.impl.StaticLoggerBinder.getSingleton()

css - 根据 PrimeFaces 数据表中的字符串更改列高

jsf - 何时调用托管 bean 构造函数?

node.js - 使用来自 node.js 的凭据进行反向代理登录