jan*_*nor 6 security jsf jaas java-ee wildfly
的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>
Run Code Online (Sandbox Code Playgroud)
standalone.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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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());
}
Run Code Online (Sandbox Code Playgroud)
我有一个自定义Authenticator扩展DatabaseServerLoginModule并覆盖createPasswordHash方法以保证自己的安全性.
我的问题是,当我使用管理员角色登录并使用其他浏览器更改登录用户的角色时,它会缓存该用户的角色.只有当我再次登录用户并重新登录时,他才能访问管理员内容.我使用LogoutServlet注销.
我尝试了servlet中的各种更改,但它没有帮助.当我从wildfly中的standalone.xml中删除"cache-type = default"时,它可以工作,但是对于在侧面进行的每个操作,都会调用身份验证模块中的登录方法,这非常糟糕.
在jboss-web.xml中,参数flushOnSessionInvalidation ="true"似乎是解决此问题的正确答案,但它没有任何效果.感谢您的任何帮助!
Jor*_*ejo 11
这是wildfly 8.0.0中的一个错误,计划在8.1中修复.请参阅https://issues.jboss.org/browse/WFLY-3221
在此期间,您可以尝试此解决方法,以在会话超时或无效时清除特定用户的缓存.
创建一个Session侦听器并从sessionDestroyed调用该方法.
public void clearCache(String username){
try {
ObjectName jaasMgr = new ObjectName("jboss.as:subsystem=security,security-domain=<YOUR SECURITY DOMAIN>" );
Object[] params = {username};
String[] signature = {"java.lang.String"};
MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0);
server.invoke(jaasMgr, "flushCache", params, signature);
} catch (Exception ex) {
logger.warn(ex.getMessage());
}}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7692 次 |
最近记录: |