我正在使用Form Auth开发我的JSF应用程序。
我陷入了SESN0008E错误处理的原因。我了解当登录的用户想要以其他用户身份进行身份验证而登录的用户 session 仍然存在时,会发生错误。
现在可以检查用户进入登录页面时是否已登录。如果他通过了身份验证,我只需将他重定向到主页。
但是错误仍然可以重现-只需在两个选项卡中打开登录页面,然后登录到不同的帐户即可。
对于登录,我使用简单的login.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition template="/WEB-INF/template/login/layout.xhtml">
<ui:define name="content">
<p:outputLabel value="#{loginHandler.alreadyLoggedRedirect()}"></p:outputLabel>
<form action="j_security_check" method="post">
<p:panelGrid id="loginContentPanel" columns="2">
<p:outputLabel for="j_username" value="Username" />
<p:inputText id="j_username" />
<p:outputLabel for="j_password" value="Password" />
<p:password id="j_password"></p:password>
<f:facet name="footer">
<div id="loginButtonCenter">
<h:commandButton id="loginButton"
styleClass="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
value="Login" />
</div>
</f:facet>
</p:panelGrid>
</form>
</ui:define>
</ui:composition>
</h:body>
</html>
当用户已经登录时,loginHandler.alreadyLoggedRedirect()处理重定向。
这是web.xml的一部分:
<login-config>
<auth-method>FORM</auth-method>
<realm-name>User Auth</realm-name>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/login.xhtml?s=err</form-error-page>
</form-login-config>
</login-config>
<security-constraint>
<web-resource-collection>
<web-resource-name>User Auth</web-resource-name>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>admin</role-name>
</security-role>
我想知道是否可以处理此异常并自动注销当前用户?
我只想注销新用户登录尝试中的当前用户。
最佳答案
创建一个servletfilter来检查对登录页面的请求(以及将loginform发布到的url)。如果用户已通过身份验证,则将用户重定向到其他位置。将此过滤器设置为过滤器链中的第一个过滤器。如果需要,您也可以在此处使 session 无效。基本上,这是SessionCheckFilter。
是否有理由完全为经过身份验证的用户显示登录页面?该过滤器还可以检查是否允许用户访问登录页面。
如果从SessionCheckFilter传递->
JSF2概念
<ui:fragment rendered="#{myRequestScopeBean.userAuthenticated}">
Hello user name etc.</ui:fragment>
<ui:fragment rendered="#{not myRequestScopeBean.userAuthenticated}">
Show login form
</ui:fragment>
关于jsf - 如何处理-SESN0008E用户试图在WebSphere上访问该用户拥有的 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32249210/