0

我有一个使用 Spring Security 的 Web 项目。用户从 login.jsp 开始,通过认证,直接进入 hello.jsp。请注意,所有 JSP 页面都位于 WEB-INF 中。在此过程中,我注意到 URL 以 开头localhost:8081/Project1/pages/login.jsp,在提交页面后,URL 已更改为 http://localhost:8081/Project1/pages/j_spring_security_check;jsessionid=792884C463EAC3C6CBC155EA75F4C6E4

然后页面在身份验证后显示 HTTP 状态 404,而不是显示 hello.jsp。在控制台输出中,我看到以下消息:

WARNING: No mapping found for HTTP request with URI [/SpringSecurity3/pages/j_spring_security_check] in DispatcherServlet with name 'SpringSecurity3'

我不确定 Spring 配置中的未配置是什么?配置代码如下:

<http auto-config="true">
   <intercept-url pattern="/welcome*" access="ROLE_ADMIN"/>
   <intercept-url pattern="/pages/hello.jsp" access="ROLE_ADMIN"/>
   <form-login login-page="/login" default-target-url="/welcome" authentication-failure-url="/loginfailed" />
   <logout logout-success-url="/pages/login.jsp"/>
</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>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/WEB-INF/pages/*</url-pattern>
</filter-mapping>
4

2 回答 2

1

消除

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/WEB-INF/pages/*</url-pattern>
</filter-mapping>

您也可以参考本教程: http ://www.mkyong.com/spring-security/spring-security-hello-world-example http://www.mkyong.com/spring-security/spring-security-form -登录示例/

于 2013-06-22T13:41:49.087 回答
1

仔细检查安全配置是否包含在主应用程序上下文中(而不是 servlet 应用程序上下文)。声明安全过滤器链 ( <http ...>) 的 xml 配置文件应列在contextConfigLocation上下文参数中web.xml(或由其中列出的 xml 配置文件之一导入)。

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        ...
        [spring-security config file should be included here]
        ...
    </param-value>
</context-param>
于 2013-06-22T13:47:26.127 回答