2012-06-27 45 views
7

請幫我諮詢一下。從spring-security.xml文件中禁用Spring Security

我需要通過xml文件中的某些變量禁用/啓用我的應用程序的彈簧安全性。

我的彈簧security.xml文件

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

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

<authentication-manager> 
    <authentication-provider> 
     <user-service> 
      <user name="hey" password="there" authorities="ROLE_ADMIN" /> 
     </user-service> 
    </authentication-provider> 
</authentication-manager> 

怎麼可以這樣perfomed? 謝謝。

回答

11

安全

的請求模式可以被映射到一個空的過濾器鏈,通過設置該屬性爲無。沒有安全性將被應用,Spring Security的功能都不可用。

http://static.springsource.org/spring-security/site/docs/3.1.x/reference/appendix-namespace.html#nsa-http-security

這樣:

<http auto-config="true" security="none"> 

和往常一樣的 「無」 參數可以是springEL表達(以及一個子集反正)。

希望這就是你要找的

編輯:

忘了提,這是一個新的特點是春季安全3.1

http://static.springsource.org/spring-security/site/docs/3.1.x/reference/new-3.1.html#new-3.1-highlevel

EDIT2:

對於更動態的解決方案使用bean配置文件。 http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/new-in-3.1.html#d0e1293http://blog.springsource.com/2011/02/11/spring-framework-3-1-m1-released/

+0

感謝您的回覆!但仍然有問題。當添加security =「none」時,會出現以下異常:org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置問題:如果使用定義不安全模式,則不能包含子元素。有沒有其他方式來執行? – me1111

+0

@ me1111:我已更新答案 –

+0

感謝您的幫助和參考!研究 – me1111