我目前正在编写一个由Spring Security担保的Spring MVC应用程序。对于登录,使用基本表单身份验证,因为我没有添加进一步的配置,凭证被张贴到http://www.localhost:8080/myWebApp/j_spring_security_check
。更改弹簧和弹簧安全的servlet映射
到目前为止,我已经介绍了第二个servlet(CometD),它不受Spring或Spring Security的影响。为此,我试图更改servlet-mappings
以将Spring和Spring Security分别映射到/app
,分别为/app/*
和另一个Servlet以及cometd/*
。我web.xml
看起来如下:
<!-- Spring security -->
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<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>/app/*</url-pattern>
</filter-mapping>
<!-- Spring MVC -->
<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>/app</url-pattern>
</servlet-mapping>
<!-- CometD -->
<servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.CometdServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>
这样做的问题是,这改变后,我可以登录了。服务器无法找到任何请求映射,并且客户端告诉我 NetworkError: 404 Not Found - http://localhost:8080/myWebApp/app/j_spring_security_check
。
这个映射有什么问题?如何配置Spring和Spring Security以仅处理特定映射的请求,而不是像文档中所述的/
和/*
?
非常感谢!
最佳, 勒
'springSecurityFilterChain'的映射中是否存在拼写错误?不应该是'/ app/*'而不是'/ app *'(缺少斜杠)? – sbordet
@sbordet:嗨,西蒙娜!哦,是的,你是对的。我测试了不同的变体。不幸的是,我没有任何区别。仍然无法找到'j_spring_security_check'。我编辑了上面的清单来解决这个问题 – rene