Spring Security - 发送到/ j_spring_security_check [英] Spring Security - Dispatch to /j_spring_security_check
问题描述
我有春季安全措施,并通过login.jsp登录完全正常。
I have spring security in place and login via login.jsp works perfectly fine.
现在,我必须根据URL自动获取用户登录(类似于单点登录)。我基本上在URL中有一个路径参数,它基本上是一个加密代码,我处理这个代码进行自动登录。
Now, I have to automatically get the user logged in based on the URL (similar to Single Sign On). I basically have a path parameter in the URL which is basically an encrypted code, I process this code to do an auto login.
我正在修改我的LoginController以检查我是否有一个有效的路径参数使用我的用户名&密码,使用此用户名&密码我正在做转发:/ j_spring_security_check?j_username =+用户名+& j_password =+密码
I am modifying my LoginController to check if I have a valid path param using which I get my username & password, using this username & password I am doing "forward:/j_spring_security_check?j_username="+username+"&j_password="+password
这会将我引导至login.jsp,并显示以下错误您的登录尝试失败,请重试。导致:不支持身份验证方法:GET
This directs me to login.jsp with following error Your login attempt was not successful, try again. Caused : Authentication method not supported: GET
我还尝试过redirect:/ j_spring_security_check?j_username = +用户名+& j_password =+密码
但没有任何帮助。
I have also tried with "redirect:/j_spring_security_check?j_username="+username+"&j_password="+password
but with no help.
致电 / j_spring_security_check
是 POST
但是转发:
& 重定向:
正在执行 GET
,那么如何调度 / j_spring_security_check $来自我的LoginController的c $ c> as
POST
?
Call to /j_spring_security_check
is a POST
but forward:
& redirect:
is doing a GET
, so how can I dispatch to /j_spring_security_check
as POST
from my LoginController?
谢谢
推荐答案
/ j_spring_security_check
URL映射到 UsernamePasswordAuthenticationFilter
以提供服务请求。
/j_spring_security_check
URL is mapped to UsernamePasswordAuthenticationFilter
to serve the requests.
在 UsernamePasswordAuthenticationFilter
中,默认情况下, postOnly
设置为 true
。
In UsernamePasswordAuthenticationFilter
, by default, the postOnly
is set to true
.
中的以下更改spring-security.xml
将 postOnly
设置为 false
工作。
<bean id="authenticationFilter"
class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"
p:postOnly="false" />
此外,在 web.xml
中,需要以下配置:
Also, in web.xml
, the following configuration is required:
<filter-mapping> <filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
这篇关于Spring Security - 发送到/ j_spring_security_check的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!