2

我目前正在编写一个 Spring MVC 应用程序,由 Spring Security 保护。对于登录,使用了基本表单身份验证,并且由于我没有添加进一步的配置,因此将凭据发布到http://www.localhost:8080/myWebApp/j_spring_security_check.

到目前为止一切顺利,但现在我介绍了第二个 servlet (CometD),它不受 Spring 或 Spring Security 的影响。为此,我尝试更改将servlet-mappingsSpring 和 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 配置为仅处理特定映射的请求,而不是/文档/*中描述的请求?

提前非常感谢!

最好的,勒内

4

1 回答 1

1

将您的 springSecurityFilterChain 映射到 /。更改您的安全配置:

<http use-expressions="true">
    <intercept-url pattern="/cometd/**" access="permitAll" />
    <intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
</http>
于 2013-01-09T14:09:01.283 回答