Shiro 自定义 JDBC 境界
Shiro custom JDBC realm
我正在使用 Shiro 安全框架并实现自定义 JDBC 领域。
我的 shiro.ini 文件中当前设置了以下值
jdbcRealm.authenticationQuery = SELECT password FROM user WHERE username = ?
我的问题是,如果我扩展 JdbcRealm 并覆盖其 doGetAuthenticationInfo(AuthenticationToken token) 方法,[=我的shiro.ini文件中设置的28=]还能被调用吗?还是方法覆盖优先于 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 是从数据库完成身份验证的主要方法。因此,如果您覆盖它,通常您将覆盖身份验证过程。所以最好先调用 super class 方法然后获取它的 ino 然后使用它这样你就不必更改任何东西。 shiro.ini 中的 sql 也会自动映射。在您覆盖之前它们不会更改
setAuthenticationQuery、setUserRolesQuery 等
您可以轻松调用以下方法来模拟实际流程,然后自定义它。
AuthenticationInfo info = super.doGetAuthenticationInfo(token);
请注意,super 是对父级的引用,而 super() 是它的构造函数。
喜欢:
public class CustomJdbcRealm extends JdbcRealm
{
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException
{
AuthenticationInfo info = super.doGetAuthenticationInfo(token);
// Your own code here
}
}
我正在使用 Shiro 安全框架并实现自定义 JDBC 领域。
我的 shiro.ini 文件中当前设置了以下值
jdbcRealm.authenticationQuery = SELECT password FROM user WHERE username = ?
我的问题是,如果我扩展 JdbcRealm 并覆盖其 doGetAuthenticationInfo(AuthenticationToken token) 方法,[=我的shiro.ini文件中设置的28=]还能被调用吗?还是方法覆盖优先于 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 是从数据库完成身份验证的主要方法。因此,如果您覆盖它,通常您将覆盖身份验证过程。所以最好先调用 super class 方法然后获取它的 ino 然后使用它这样你就不必更改任何东西。 shiro.ini 中的 sql 也会自动映射。在您覆盖之前它们不会更改
setAuthenticationQuery、setUserRolesQuery 等
您可以轻松调用以下方法来模拟实际流程,然后自定义它。
AuthenticationInfo info = super.doGetAuthenticationInfo(token);
请注意,super 是对父级的引用,而 super() 是它的构造函数。
喜欢:
public class CustomJdbcRealm extends JdbcRealm
{
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException
{
AuthenticationInfo info = super.doGetAuthenticationInfo(token);
// Your own code here
}
}