2016-02-28 129 views
1

我正在配置彈簧安全性與我的彈簧應用程序。Login.jsp未與Spring安全性進行解析

下面是我httpsecurity配置

http.authorizeRequests() 
     .anyRequest().authenticated() 
     .and() 
     .formLogin()    
     .loginPage("/login") 
     .loginProcessingUrl("/login") 
     .permitAll() 
     .defaultSuccessUrl("/home") 
     .and() 
     .logout() 
     .logoutSuccessUrl("/login?logout"); 

下面是我的login.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> 
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %> 

<html> 
<body> 
    <h1 id="banner">Login to Security Demo</h1> 
    <form name="f" action="<c:url value='j_spring_security_check'/>" 
       method="POST"> 
     <table> 
      <tr> 
       <td>Username:</td> 
       <td><input type='text' name='j_username' /></td> 
      </tr> 
      <tr> 
       <td>Password:</td> 
       <td><input type='password' name='j_password'></td> 
      </tr> 
      <tr> 
       <td colspan="2">&nbsp;</td> 
      </tr> 
      <tr> 
       <td colspan='2'><input name="submit" type="submit">&nbsp;<input name="reset" type="reset"></td> 
      </tr> 
     </table> 
    </form> 
</body> 
</html> 

的問題是現在顯示爲是當login.jsp的被擊中,我得到源代碼。當我刪除彈簧安全配置它工作並解析jsp頁面。

有人可以指出我的正確方向是什麼會導致此問題?

回答

0

您的彈簧安全loginProcessingUrl在您的配置中設置爲/login,但表單操作設置爲j_spring_security_check

將您的<c:url value='j_spring_security_check'/>更改爲<c:url value='/login'/>,並且您的登錄信息可以正常工作。

另外,請記住,除非您明確禁用了Spring安全CSRF令牌,否則您需要在您的自定義登錄表單中使用此隱藏元素。

請參閱Springs documentation關於如何包含此內容。

+0

嗨Geditdk! ,對不起,我一直無法嘗試你的解決方案。但是我必須告訴你,你提到的代碼是在login.jsp頁面中的,並且在我提交表單後就會生效。但實際上,我的問題是,登錄頁面顯示的源代碼,即JSP標籤本身如提到的問題,所以邏輯上不確定這是否會有所幫助! – DragonZoned