Java 为什么 j_spring_security_check 404?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20584009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why j_spring_security_check 404?
提问by xwhyz
I'm trying to implement form based authentication with Spring security. Redirection works fine:
my main page works correctly and for http://localhost:8080/master/admin
I'm redirected to login page (http://localhost:8080/master/login/
):
我正在尝试使用 Spring 安全性实现基于表单的身份验证。重定向工作正常:我的主页工作正常,并且 http://localhost:8080/master/admin
我被重定向到登录页面 ( http://localhost:8080/master/login/
):
<form action="j_spring_security_check" method="POST">
<label for="username">User Name:</label>
<input id="username" name="j_username" type="text"/>
<label for="password">Password:</label>
<input id="password" name="j_password" type="password"/>
<input type="submit" value="Log In"/>
</form>
but when I submit I get 404 on address: `http://localhost:8080/master/login/j_spring_security_check`
Here's my configuration web.xml:
这是我的配置 web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
And my root-context.xml (i made redirection to google so that I know page exists in context)
还有我的 root-context.xml(我重定向到 google,以便我知道页面存在于上下文中)
<sec:http auto-config="true">
<sec:intercept-url pattern="/admin/**" access="ROLE_USER" />
<sec:form-login login-page="/login/"
authentication-failure-url="http://www.google.com" default-target-url="http://www.google.com" />
<sec:logout logout-success-url="/logout" />
</sec:http>
<sec:authentication-manager>
<sec:authentication-provider>
<sec:user-service>
<sec:user name="test" password="test" authorities="ROLE_USER, ROLE_ADMIN" />
<sec:user name="testuser" password="testuserpassword"
authorities="ROLE_USER" />
</sec:user-service>
</sec:authentication-provider>
</sec:authentication-manager>
I've lost quite a lot of time already, trying different combinations but no luck. Any help is appreciated!
我已经失去了很多时间,尝试不同的组合但没有运气。任何帮助表示赞赏!
采纳答案by Joshua Moore
I think it may be the fact your security form should point to
我认为这可能是您的安全表格应该指出的事实
/master/j_spring_security_check