2016-08-03 53 views
0

我想通過使用j_security_control設置webapp的登錄功能,但最近當我登錄時,我一直在從標題中獲取錯誤。下面是相關登錄JSP:Tomcat 8 - 無效的直接引用到表單登錄頁

<div class="loginContainer"> 
     <form role="form" method="POST" action="<%=request.getContextPath()%>/j_security_check"> 
      <c:if test="${not empty param.Retry}"> 
       <div class="errorText"> 
        <p>Login failed. Please try again.</p> 
       </div> 
      </c:if> 
      <div class="username"> 
       <label class="loginText" for="inputUser">User</label> 
       <input type="text" class="form-control" id="inputUser" placeholder="Username" name="j_username" autofocus> 
      </div> 
      <div class="password"> 
       <label class="loginText" for="inputPassword">Password</label> 
       <input type="password" class="form-control" id="inputPassword" placeholder="Password" name="j_password"> 
      </div> 
      <div> 
       <button type="submit" class="btn loginButton" id="loginButton">Login</button> 
      </div> 
     </form> 
    </div> 

它正在從一個標題稱爲例如:

<c:choose> 
    <c:when test="${not empty pageContext.request.userPrincipal}"> 
     <a id="logout" href="${base}/jsp/login/logout.jsp" 
      class="fse-hid-small navbartext" 
      data-ng-class="{'selected': idSelected === 'logout'}" 
      title="Goodbye!">LOGOUT</a> 
    </c:when> 
    <c:otherwise> 
     <a id="login" href="${base}/jsp/login/login.jsp" 
      class="fse-hid-small navbartext" 
      data-ng-class="{'selected': idSelected === 'login'}" 
      title="Login Here!">LOGIN</a> 
    </c:otherwise> 
</c:choose> 

而且在web.xml中定義的:前一段時間

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>InternalUserRole</web-resource-name> 
     <url-pattern>/jsp/internal/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>InternalUser</role-name> 
    </auth-constraint> 
    <user-data-constraint> 
     <transport-guarantee>CONFIDENTIAL</transport-guarantee> 
    </user-data-constraint> 
</security-constraint> 
<login-config> 
    <auth-method>FORM</auth-method> 
    <form-login-config> 
     <form-login-page>/jsp/login/login.jsp</form-login-page> 
     <form-error-page>/jsp/login/login.jsp?Retry=True</form-error-page> 
    </form-login-config> 
</login-config> 

這是工作不幸的是,我不知道它何時破裂。無論如何,我做這項工作?

+0

我試過清除我的緩存和編碼的URL,但我有同樣的問題。 –

+0

我試圖做一個安全的重定向,並給我一個本地主機拒絕連接錯誤 –

回答

0

鑑於沒有其他人有解決方案,我管理一個hacky解決方案,以通過這個可憐的tomcat安全問題。

  1. 創建一個簡單的servlet,重定向到根頁面。
  2. 創建一個web資源收集條目,使該servlet頁面安全並需要一個角色。
  3. 使您到登錄頁面的鏈接指向您創建的servlet。

當您點擊該鏈接時,您將被重定向到您想要轉到的登錄頁面。登錄,您將被重定向到根索引頁面。一個簡單的方法來解決一個令人難以置信的惱人的安全錯誤,甚至沒有什麼幫助。