Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring安全不拦截_Java_Spring Mvc_Spring Security - Fatal编程技术网

Java Spring安全不拦截

Java Spring安全不拦截,java,spring-mvc,spring-security,Java,Spring Mvc,Spring Security,运行应用程序时,它的行为就像没有过滤器一样,我可以像往常一样访问所有页面 Web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app

运行应用程序时,它的行为就像没有过滤器一样,我可以像往常一样访问所有页面

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>SpringMVCTest</display-name>

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

    <servlet-mapping>
        <servlet-name>springMVCTest</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>


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

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/springMVCTest-security.xml</param-value>
    </context-param>



</web-app>

春季测试
春季测试
org.springframework.web.servlet.DispatcherServlet
1.
春季测试
/
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
org.springframework.web.context.ContextLoaderListener
上下文配置位置
/WEB-INF/springMVCTest-security.xml
springMVCTest-Security.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns="http://www.springframework.org/schema/security"
    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.1.xsd
    http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security-3.1.xsd">

    <http auto-config="true">
        <intercept-url pattern="/**" access="ROLE_ADMIN" />
    </http>

    <authentication-manager>
        <authentication-provider>
            <user-service id="userService">
                <user name="admin" password="admin" authorities="ROLE_ADMIN" />
            </user-service>
        </authentication-provider>
    </authentication-manager>
</beans:beans>


由于所有的配置都在这些文件中,所以我只发布了它们,试图让事情变得简单。我想问题一定出在这两个问题中的一个

您的spring安全筛选器未映射到任何URL。只需将映射添加到web.xml:

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

springSecurityFilterChain
/*

您的spring安全筛选器未映射到任何URL。只需将映射添加到web.xml:

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

springSecurityFilterChain
/*

也许这只是一个输入错误,但我在web.xml中第一眼看到的是您正在查找
springMVCTest security.xml
,而文件名是springMVCTest-security.xml,带有大写字母SAren,您是否缺少
servlet.xml
中的
过滤器映射,但这只是一个输入错误。在代码中的任意位置放置断点并检查堆栈。SpringSecurityFilterChain在堆栈中吗?可能只是一个输入错误,但我在web.xml中第一眼看到的是
springMVCTest security.xml
,而文件名是springMVCTest-security.xml,带有大写字母SAren,您在
servlet.xml
中没有
过滤器映射
,对此感到兴奋,但这只是一个输入错误。在代码中的任意位置放置断点并检查堆栈。SpringSecurityFilterChain在堆栈中吗?我注意到了这一点,但是我主要是从Spring中工作的,它没有提到使用过滤器映射,所以我只是假设如果没有提供映射,它默认为这个url。无论采用哪种方式,它的行为都与使用或不使用它时的行为相同。在使用过滤器映射停止和启动服务器几次后,它突然开始工作。我想这毕竟是过滤器映射。我注意到了这一点,但是我主要是从Spring in Action工作的,它没有提到使用过滤器映射,所以我只是假设如果没有提供映射,它默认为这个url。无论采用哪种方式,它的行为都与使用或不使用它时的行为相同。在使用过滤器映射停止和启动服务器几次后,它突然开始工作。我猜这毕竟是过滤器映射。