【发布时间】:2014-03-22 19:15:57
【问题描述】:
jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<security-domain flushOnSessionInvalidation="true">my-aktion
</security-domain>
<valve>
<class-name>utils.MyAuthenticator</class-name>
</valve>
</jboss-web>
独立的.xml
<security-domain name="my-aktion" cache-type="default">
<authentication>
<login-module code="utils.MyAuthenticator" flag="required">
<module-option name="dsJndiName" value="java:jboss/datasources/MySQLDS"/>
<module-option name="principalsQuery" value="SELECT password FROM user WHERE username=?"/>
<module-option name="rolesQuery" value="SELECT r.role, 'Roles' FROM Role r INNER JOIN user u ON u.role_id = r.id WHERE u.username=?"/>
<module-option name="hashAlgorithm" value="SHA-256"/>
<module-option name="hashEncoding" value="base64"/>
</login-module>
</authentication>
</security-domain>
web.xml(提取)
<security-constraint>
<web-resource-collection>
<web-resource-name></web-resource-name>
<url-pattern>/Profile/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>User</role-name>
<role-name>Manager</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>my-aktion</realm-name>
<form-login-config>
<form-login-page>/Login/login.xhtml</form-login-page>
<form-error-page>/Login/error.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>User</role-name>
</security-role>
<security-role>
<role-name>Manager</role-name>
</security-role>
LogoutServlet.java(doPost(...) 相同)
@WebServlet("/Login/logout.xhtml")
public final class LogoutServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public LogoutServlet() {
super();
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setHeader("Cache-Control", "no-cache, no-store");
response.setHeader("Pragma", "no-cache");
response.setHeader("Expires", new java.util.Date().toString());
if (request.getSession(false) != null) {
request.getSession(false).invalidate();// remove session.
}
// if (request.getSession() != null) {
//
// request.getSession().invalidate();// remove session.
//
// }
request.logout();
response.sendRedirect(request.getContextPath());
}
我有一个自定义 Authenticator,它扩展了 DatabaseServerLoginModule 并覆盖了 createPasswordHash 方法以保证其自身的安全性。
我的问题是,当我使用经理角色登录并使用另一个浏览器更改登录用户的角色时,它会缓存该用户的角色。只有当我注销用户并再次登录时,他才无法访问管理器内容。我使用 LogoutServlet 注销。
我在 servlet 中尝试了各种更改,但没有帮助。当我从 wildfly 中的standalone.xml 中删除“cache-type=default”时,它可以工作,但是对于在侧面进行的每个操作,都会调用身份验证模块中的登录方法,这非常糟糕。
在 jboss-web.xml 中,参数 flushOnSessionInvalidation="true" 似乎是这个问题的正确答案,但它没有效果。感谢您的帮助!
【问题讨论】:
-
在手机上,因此键入格式正确的答案需要一些时间。您是否在数据库中以任何方式跟踪登录用户?基本上,如果您可以强制受影响的用户在其用户角色受到影响时注销,那么您将获得成功。
-
我不跟踪数据库中的登录用户,如果在用户注销和重新登录后首先更新角色,这对我来说是可以的。问题是现金/会话没有正确清除。
-
另外,顺便说一句,它的拼写是“缓存”,而“缓存”数据意味着您正在等待一段时间的数据。 “现金”这个词不合适。
-
@ChrisForrence 你还有其他的想法来解决这个问题吗?当注销后正确清除服务器缓存时,我认为问题将得到解决。
-
不幸的是,什么都没有想到;我对 Wildfly 和 JBoss 不熟悉(我更喜欢 Tomcat 人)。
标签: security jsf jakarta-ee jaas wildfly