2011-11-10 151 views
2

我是Spring Security的新手,并且在Spring MVC应用程序中配置了Spring Security。Spring Security登录问题

提交登录页面后,我收到以下错误

The requested resource (/j_spring_security_check) is not available.

我无法理解这种行为。

请帮助。

弹簧security.xml文件

<security:http auto-config="true" use-expressions="true" access-denied-page="/appln/denied"> 
    <security:intercept-url pattern="/appln/login" access="permitAll" /> 
    <security:intercept-url pattern="/appln/index" access="hasRole('ROLE_ADMIN')" /> 
    <security:intercept-url pattern="/appln/run" access="hasRole('ROLE_ADMIN')" /> 
    <security:intercept-url pattern="/appln/common" access="hasRole('ROLE_USER')" /> 

    <security:form-login login-page="/appln/login" 
         authentication-failure-url="/appln/login?error=true" 
         default-target-url="/appln/run" 
         authentication-success-handler-ref="AuthHandlr" /> 

    <security:logout invalidate-session="true" 
        logout-success-url="/appln/login" 
        delete-cookies="JSESSIONID" /> 
</security:http> 

的web.xml

<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> 

<servlet> 
    <servlet-name>servlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
+1

弹簧安全配置片段(以及相关的web.xml一个)将真正帮助。 –

+1

你检查了你的日志文件吗?该消息通常表明服务器没有干净地启动。某处应该有一个日志错误/堆栈跟踪。 –

回答

1

解决的问题。

在我loginpage.jsp,action属性定义为

action=../../j_spring_security_check

我与前面玩,将其改为

action = /j_spring_security_check

,它的工作没有任何问题。

虽然问题解决了,有谁可以请详细说明为什么路径中的更改有效。

0

表单操作可以是'j_spring_security_check'或'/ j_spring_security_check'。

这是Spring-Security中的默认值,不能更改。

同样的表单字段必须是“为j_username”和“为j_password”