[英]Spring Security filters out every case
我在兩頁的基本網站上有以下安全配置。
<http use-expressions="true">
<intercept-url pattern="/login*" access="permitAll" />
<intercept-url pattern="/resources/**" access="permitAll" />
<intercept-url pattern="/**" access="hasRole('ROLE_ADMIN')" />
<form-login login-page='/login.jsp'
default-target-url="/index.jsp"
username-parameter="name"
password-parameter="password"/>
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="admin" password="admin" authorities="ROLE_USER, ROLE_ADMIN" />
<user name="user" password="user" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
我不使用自定義控制器,僅使用默認的彈簧視圖分辨率。
<mvc:annotation-driven />
<mvc:resources location="/resources/" mapping="/resources/**"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"/>
<property name="suffix" value=".jsp"/>
</bean>
當我嘗試訪問默認頁面index.jsp
它將按照我的期望將我重定向到login.jsp
頁面,但是當我輸入表單數據時,它不會將我發送到index.jsp
頁面,將我再次重定向到login.jsp
。 表單字段在安全配置中的name
定義為showin,表單action
為index.jsp
。
我的login.jsp
表單:
<form method="post" action="<c:url value = '/index.jsp' />">
<label for="inputEmail3">User</label>
<input name="name" type="text" id="inputEmail3" placeholder="User name" required>
<label for="inputPassword3">Password</label>
<input name="password" type="password" id="inputPassword3" placeholder="Password" required>
<button type="submit" class="btn btn-success btn-sm">Sign in</button>
<button type="reset" class="btn btn-default btn-sm">Reset</button>
</form>
我想念什么?
Spring Security使用包括表單登錄在內的過濾器。 默認情況下,當需要驗證用戶身份時, DefaultLoginPageGeneratingFilter
生成一個包含HTML表單的頁面,但是您也可以提供它。
然后, UsernamePasswordAuthenticationFilter
截取表單的提交,默認情況下在URL j_spring_security_check
,並且應使用POST提交表單,否則spring安全(默認情況下)將引發Exception。
您應該使用專用URL提交登錄表單。 如果你不喜歡j_spring_security_check
您可以用更改login-processing-url
形式登錄屬性,但它不應該是一樣的成功URL。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.