【发布时间】:2023-03-26 00:30:01
【问题描述】:
我正在尝试使用 JPA 数据源通过 Apache Shiro 构建动态 Allowance/Permission。
最后,一切都回到了这个类:
public class CustomAuthorizationFilter extends HttpMethodPermissionFilter {
@Override
public boolean isAccessAllowed(ServletRequest r, ServletResponse r, Object m) throws IOException {
//Somehow get the user stored somewhere in the servlet memory
SysUser loggedUser = %some_code_here%
for (String allowance : loggedUser.getAllowances()) {
// Do many validations
if (pathsMatch(allowance, request)) {
return true;
}
}
return super.isAccessAllowed(request, response, mappedValue);
}
}
每个请求都会触发 isAccessAllowed() 方法,因此我不想从数据库中获取信息。 Shiro 构建了许多关于用户的对象,其中之一是 AuthorizationInfo。我构建了一个 CustomAuthorizationInfo ,其中 Permissions 和 Allowances 列表位于其中...但是如何在不重新访问数据库的情况下检索它们?
是否可以在不访问数据库的情况下使用 shiro 从经过身份验证的用户那里存储/检索信息?
(PS.: isPermitted 之类的方法并不能解决问题,因为我需要权限本身才能使用 pathsMatch() 方法)。
【问题讨论】: