将值传递给Shiro ini中的枚举属性 [英] Passing Values to Enumerated Properties in Shiro ini

查看:395
本文介绍了将值传递给Shiro ini中的枚举属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JDBC Realm并在SQL中存储身份验证数据。我将salt存储在users表中并依赖于DEFAULT_SALTED_AUTHENICATION_QUERY。要调用该查询,我必须设置SaltStyle。

I am using the JDBC Realm and storing authentication data in SQL. I am storing the salt in the users table and relying on the DEFAULT_SALTED_AUTHENICATION_QUERY. To invoke that query I must set the SaltStyle.

因此,我需要通过INI将SaltStyle.COLUMN枚举值传递给JdbcRealm。

Therefore, I need to pass the SaltStyle.COLUMN enumerated value to JdbcRealm through the INI.

SaltStyle不是类,所以我无法创建引用

SaltStyle is not a class so I cannot create a reference

无论我做什么都会产生此错误= org.apache.shiro.config。 UnresolveableReferenceException:

Whatever I do pass generates this error = org.apache.shiro.config.UnresolveableReferenceException:

无法从文档中的详尽搜索或引用中找到示例。非常感谢任何帮助。

Can't find examples from exstensive searching or reference in documentation. Any help is much appreciated.

#====================================================================
# Shiro INI configuration
#
# ===================================================================
[main]
JdbcRealm=org.apache.shiro.realm.jdbc.JdbcRealm
JdbcRealm.permissionsLookupEnabled = true 
sha256Matcher = org.apache.shiro.authc.credential.HashedCredentialsMatcher
sha256Matcher.hashAlgorithmName=SHA-256
sha256Matcher.hashIterations=1
JdbcRealm.credentialsMatcher = $sha256Matcher
JdbcRealm.saltStyle= enum expression needed here

这是JdbcRealm中的属性

Here is the property in JdbcRealm

public void setSaltStyle(SaltStyle saltStyle) {
    this.saltStyle = saltStyle;
    if (saltStyle == SaltStyle.COLUMN && authenticationQuery.equals 
             (DEFAULT_AUTHENTICATION_QUERY)) {
        authenticationQuery = DEFAULT_SALTED_AUTHENTICATION_QUERY;
    }
}


推荐答案

我的理解是目前(Shiro 1.2)您无法在shiro.ini中配置ENUM值,请参阅 this

但是,您可以在调用领域相关方法的java代码中执行此操作(如登录) )。我在我的servlet init()中做了如下:

My understanding is that currently (Shiro 1.2) you cannot configure ENUM values in shiro.ini, see this.
However, you can do it in your java code where you invoke realm related methods (like login). I did it in my servlet init() as follows:

public class AuthManager extends HttpServlet {
protected SaltStyle saltStyle = SaltStyle.COLUMN;
// set remaining fields...
   public void init() throws ServletException { 
          Collection<Realm> realms=((RealmSecurityManager) securityManager).getRealms();    
          CustomJdbcRealm jdbcRealm=(CustomJdbcRealm)realms.toArray()[0];
          jdbcRealm.setSaltStyle(saltStyle);
   }

这篇关于将值传递给Shiro ini中的枚举属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆