【问题标题】:Disable Spring Security from spring-security.xml file从 spring-security.xml 文件中禁用 Spring Security
【发布时间】:2012-06-28 23:01:14
【问题描述】:

请帮助我的建议。

我需要通过 xml 文件中的某个变量在我的应用程序上禁用/启用 spring 安全性。

我的 spring-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>

这是怎么做到的? 谢谢。

【问题讨论】:

    标签: spring-security


    【解决方案1】:

    安全

    通过将此属性设置为无,可以将请求模式映射到空过滤器链。不会应用任何安全性,并且 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">
    

    和往常一样,“none”参数可以是 springEL 表达式(无论如何都是子集)。

    希望这就是你要找的东西

    编辑:

    忘了说它是 Spring Security 3.1 的一个新特性

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

    编辑2:

    要获得更动态的解决方案,请使用 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/

    【讨论】:

    • 感谢您的回复!但是还是有问题。添加 security="none" 时出现异常:org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 配置问题:如果你使用 定义不安全的模式,它不能包含子元素。还有其他方法可以做到吗?
    • 感谢您的帮助和参考!研究
    猜你喜欢
    • 2012-11-26
    • 2015-05-29
    • 1970-01-01
    • 2015-06-18
    • 2020-12-18
    • 2015-12-15
    • 2016-12-16
    • 2021-06-26
    • 2018-05-15
    相关资源
    最近更新 更多