Passing Values to Enumerated Properties in Shiro ini

一笑奈何 提交于 2019-12-04 10:15:18
Alicia

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);
   }

You can to extend the JdbcRealm and to override the method:

-- CustomShiroJdbcRealm.java:

public class CustomShiroJdbcRealm extends JdbcRealm {

    public void setSaltStyle(String saltStyle) {
        super.setSaltStyle(SaltStyle.valueOf(saltStyle));
    }

}

--- shiro.ini:

jdbcRealm = com.mycompany.CustomShiroJdbcRealm
jdbcRealm.saltStyle = COLUMN
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!