Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Values to Enumerated Properties in Shiro ini

Tags:

java

ini

shiro

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.

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

SaltStyle is not a class so I cannot create a reference

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

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;
    }
}
like image 248
Threadid Avatar asked Oct 22 '22 17:10

Threadid


1 Answers

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);
   }
like image 83
Alicia Avatar answered Oct 27 '22 21:10

Alicia