2015-08-27 18 views
1

我正在使用表單身份驗證來處理我的JSF應用程序。如何處理 - SESN0008E用戶試圖訪問用戶擁有的會話 - 在WebSphere上

我讓自己陷入了SESN0008E錯誤處理的原因。我知道當登錄的用戶想要以另一個用戶身份進行身份驗證時發生錯誤,而登錄的用戶會話仍然存在。

現在可以檢查用戶是否在登錄頁面時登錄。如果他通過身份驗證,我只需將他重定向到主頁。

但是,仍然可以複製錯誤 - 只需在兩個選項卡中打開登錄頁面並登錄到不同的帳戶即可。

對於登錄我用簡單的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> 

我不知道我是否可以自動處理這個異常並註銷當前用戶?

我只想在新用戶登錄嘗試時註銷當前用戶。

+0

嘗試在登錄頁面(login.xhtml)無效會話。這樣你就可以在登錄時獲得全新的會話。 – Gas

回答

0

創建一個servletfilter,用於檢查登錄頁面的請求(以及loginform發佈到的url)。如果用戶通過身份驗證,則將用戶重定向到其他位置。將此濾鏡設置爲濾鏡鏈中的第一個濾鏡。如果需要,您也可以在這裏使會話無效。基本上這是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> 
相關問題