2013-12-16 231 views
1

我的web應用程序中有多個servlet。我想用Spring Security來實現某種多層次的安全機制。我擁有:多級彈簧安全性

  1. /portal/* - >此級別將由ROLE_ADMIN(在XML中配置並且密碼保存在屬性文件中)訪問。

  2. /portal/Edrive/* - 此級別將由經過身份驗證的用戶從數據庫訪問。

其他位於/ portal /下的servlet可作爲ROLE_ADMIN訪問(請參見第1頁)。換句話說,所有級別都在ROLE_STAFF之下,只有Edrive是ROLE_USER(或者像這樣的smth。)。

我現在我越來越:

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 

這裏是我的applicationContext-security.xml文件:

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

<security:http auto-config="true" pattern="/portal/*"> 
    <security:intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY"/> 
    <security:intercept-url pattern="/**" access="ROLE_ADMIN" /> 
    <security:form-login login-page="/login" default-target-url="/portal" authentication-failure-url="/loginfailed" /> 
    <security:logout logout-success-url="/logout" /> 
</security:http> 

<security:authentication-manager> 
    <security:authentication-provider> 
     <security:password-encoder hash="md5"/> 
     <security:user-service id="userDetailsService" properties="classpath:users.properties"/> 
    </security:authentication-provider> 
</security:authentication-manager> 

電驅動-servlet.xml中:

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

<context:annotation-config/> 
<context:component-scan base-package="edrive"/> 
<mvc:default-servlet-handler/> 
<mvc:annotation-driven/> 

<security:http auto-config="true" pattern="/portal/Edrive/*"> 
    <security:intercept-url pattern="/myCarLogin" access="IS_AUTHENTICATED_ANONYMOUSLY"/> 
    <security:intercept-url pattern="/myCar*" access="ROLE_USER" /> 
    <security:form-login login-page="/myCarLogin" default-target-url="/myCarServices" authentication-failure-url="/myCarloginfailed" /> 
    <security:logout logout-success-url="/myCarlogout" /> 
</security:http> 

<security:authentication-manager> 
    <security:authentication-provider> 
     <security:password-encoder hash="md5"/> 
     <security:jdbc-user-service 
       data-source-ref="edriveDataSource" 
       users-by-username-query="select name from account where name=? and password=?"/> 
    </security:authentication-provider> 
</security:authentication-manager> 

在此先感謝。

回答

0

在以下線的applicationContext您-security.xml文件導致錯誤

<security:intercept-url pattern="/**" access="ROLE_ADMIN" /> 

改變它

<security:intercept-url pattern="/portal*" access="ROLE_ADMIN" /> 

然後它會正常工作。

關於Shrikant。