1

我正在尝试在我的简单应用程序上配置弹簧安全性,但我不断收到此错误。

Caused by: java.lang.IllegalArgumentException: A universal match pattern ('/**') is defined  before other patterns in the filter chain, causing them to be ignored. Please check the ordering in your <security:http> namespace or FilterChainProxy bean configuration

我看过其他类似的帖子,但无法弄清楚为什么我会收到此错误。我似乎没有配置重复的 security:http 命名空间。

这是我的 web.xml

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
     version="2.4">

<display-name>sampler</display-name>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:**/sampler-context.xml
        classpath:**/sampler-security.xml
    </param-value>
</context-param>

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

<servlet>
    <servlet-name>sampler</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>sampler</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

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

弹簧安全配置:

<beans:beans xmlns="http://www.springframework.org/schema/security"
         xmlns:beans="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/security
       http://www.springframework.org/schema/security/spring-security-3.1.xsd">

<!-- Add Authentication Manager -->
<authentication-manager>
    <authentication-provider>
        <user-service>
            <user name="admin" authorities="ROLE_USER" password="test"/>
        </user-service>
    </authentication-provider>
</authentication-manager>

<!-- This would add login screen -->
<http auto-config="true">
    <intercept-url pattern="/admin/*" access="ROLE_USER"/>
</http>

它只是我现在想提供的一个简单的登录功能。非常感谢有关此问题的任何帮助。

4

1 回答 1

0

问题出在上下文参数中类路径的正则表达式中。

<param-value>
    classpath:**/sampler-context.xml
    classpath:**/sampler-security.xml
</param-value>

将其更改为

    <param-value>
        classpath*:sampler-context.xml
        classpath*:sampler-security.xml
    </param-value>

解决了这个问题。

于 2013-09-11T21:15:17.510 回答