2013-01-10 134 views
0

運行應用程序時,它的行爲就好像沒有篩選器,我可以照常訪問所有頁面。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_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> 

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> 

由於所有的配置是論文的文件,我只張貼他們試圖讓事情變得簡單。我假設問題必須出現在這兩個之一中。

+0

也許它只是一個錯字,但在第一次看我在你正在尋找'springMVCTest-security.xml' web.xml中讀取,而文件名是springMVCTest-Security.xml,帶有大寫字母** S ** – ThanksForAllTheFish

+1

你不錯過'servlet.xml'中的'filter-mapping'嗎? – madth3

+0

對S很興奮,但它只是一個錯字。 – AlyoshaKaramazov

回答

3

您的spring安全篩選器未映射到任何URL。只需添加一個映射到你的web.xml:

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

我注意到了這一點,但是我主要從Spring in Action開始工作,它沒有提到使用過濾器映射,所以我只是假設它沒有提供映射時默認爲這個相同的URL。無論哪種方式,它的行爲方式都與其相同或不相同。 – AlyoshaKaramazov

+0

它停止後開始突然工作,並使用過濾器映射啓動服務器幾次。我想這畢竟是過濾器映射。 – AlyoshaKaramazov