[英]Spring security does not intercept login call
我正在嘗試設置spring安全性,我有一個控制器,該控制器在驗證失敗后轉發到登錄頁面。 但是我的接受似乎沒有得到...
控制器片段:
if (validation not successful) {
return "login";
}
在我的xml中,我有:
<security:intercept-url pattern="/login*" access="ROLE_USER" />
但這失敗,我得到以下錯誤:
所請求的資源(/myapp/WEB-INF/jsp/login.jsp)不可用。
我怎樣才能截獲登錄信息?
如果用戶尚未登錄,則意味着他還沒有ROLE_USER
,因此Spring Security不允許訪問/login
。
將use-expressions="true"
添加到<http>
元素 ,並將攔截線更改為此:
<http use-expressions="true">
<!-- ... -->
<security:intercept-url pattern="/login*" access="permitAll" />
另外,請確保login.jsp在/WEB-INF/jsp/login.jsp
下。
評論后編輯 :
似乎您根本沒有Spring Security配置,因此從此開始:
<http auto-config='true' use-expressions="true">
<intercept-url pattern="/login*" access="permitAll"/>
<intercept-url pattern="/**" access="ROLE_USER" />
<!-- use login-page='/login' assuming you've got
Spring MVC configured to redirect to login.jsp -->
<form-login login-page='/login'/>
</http>
或者,如果您使用的是Spring Security 3.1:
<http pattern="/login" security="none" />
<http auto-config='true'>
<intercept-url pattern="/**" access="ROLE_USER" />
<!-- use login-page='/login' assuming you've got
Spring MVC configured to redirect to login.jsp -->
<form-login login-page='/login'/>
</http>
使用示例內容創建/WEB-INF/jsp/login.jsp
文件:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>Login Page</title>
</head>
<body>
<h3>Login</h3>
<c:if test="${not empty error}">
<div class="errorblock">
Your login attempt was not successful, try again.<br /> Caused :
${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}
</div>
</c:if>
<form name='f' action="<c:url value='j_spring_security_check' />"
method='POST'>
<table>
<tr>
<td>User:</td>
<td><input type='text' name='j_username' value=''>
</td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='j_password' />
</td>
</tr>
<tr>
<td colspan='2'><input name="submit" type="submit"
value="submit" />
</td>
</tr>
</table>
</form>
</body>
</html>
而且,請閱讀有關Spring Security的更多信息,因為這些確實是該框架的基礎。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.