简体   繁体   English

Shiro自定义JDBC领域

[英]Shiro custom JDBC realm

I'm messing around with the Shiro Security Framework and implementing a custom JDBC realm. 我搞砸了Shiro安全框架并实现了自定义JDBC领域。

The following value is currently set in my shiro.ini file 我的shiro.ini文件中当前设置了以下值

jdbcRealm.authenticationQuery = SELECT password FROM user WHERE username = ?

My question is if I extend JdbcRealm and override its doGetAuthenticationInfo(AuthenticationToken token) method will the jdbcRealm.authenticationQuery set in my shiro.ini file still be called? 我的问题是,如果我延长JdbcRealm并覆盖其doGetAuthenticationInfo(AuthenticationToken令牌)方法将jdbcRealm.authenticationQuery在我shiro.ini文件中设置仍然叫什么名字? Or does the method override take preference over the settings in the shiro.ini file? 还是方法重写优先于shiro.ini文件中的设置?

public class CustomJdbcRealm extends JdbcRealm 
{
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException 
    {
        // Connect to DB to get password and salt values
    }
}

doGetAuthenticationInfo is the main method where authentication is done from database. doGetAuthenticationInfo是从数据库进行身份验证的主要方法。 SO if you override it generally you are overriding authentication process. 因此,如果您通常覆盖它,那么您将覆盖身份验证过程。 So better call super class method first then get its ino and then use it so you will not have to change anything. 因此最好先调用超类方法,然后再获取其ino然后再使用它,这样您就不必更改任何内容。 Also sqls in shiro.ini are automatically mapped. shiro.ini中的sql也会自动映射。 and they will not be changed until you override 除非您覆盖它们,否则它们将不会更改
setAuthenticationQuery, setUserRolesQuery, etc setAuthenticationQuery,setUserRolesQuery等

You can easily call following method to simulate the actual process then customize it. 您可以轻松地调用以下方法来模拟实际过程,然后对其进行自定义。

AuthenticationInfo  info = super.doGetAuthenticationInfo(token); 

Note, that super is a reference to the parent, but super() is it's constructor. 注意,super是对父级的引用,但是super()是其构造函数。

like: 喜欢:

public class CustomJdbcRealm extends JdbcRealm 
{
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException 
    {

       AuthenticationInfo  info = super.doGetAuthenticationInfo(token);
      // Your own code here 
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM