【问题标题】:How to temporarily disable Spring Security in Spring Web App如何在 Spring Web App 中临时禁用 Spring Security
【发布时间】:2015-09-04 11:36:07
【问题描述】:

首先,谈到 Spring,我完全是个菜鸟。一个正在休假的同事留给我一个应用程序来处理。他告诉我不要管安全,因为最终的方法还没有决定,只需开发应用程序的其余部分。

但是启用了安全性并阻止访问主网页。我检查了几份文件,包括

Disable Spring Security from spring-security.xml file

Disable Basic Authentication while using Spring Security Java configuration

http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-security.html

http://docs.spring.io/spring-boot/docs/current/reference/html/howto-security.html

没有找到有效的答案。

我做了以下事情:

在 web.xml 中的 中添加了 index.html。这会将我引导至已包含在我接管的软件包中的登录页面。所以,我想我可以简单地禁用安全性。

在spring security.xml 中添加了属性security="none"。现在我不再获得登录页面。我得到一个空白页。

在 web.xml 中禁用

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

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

仍然是空白页。

我看到了很多其他建议,但它假设的 Spring 知识比我目前拥有的要多得多。

例如在上面的第 4 个链接中,我看到:

如果你在任何地方用@EnableWebSecurity 定义@Configuration 您的应用程序将关闭默认的 webapp 安全性 Spring Boot 中的设置。

我不知道它们是什么意思。我认为这意味着将这些注释放在某个方法上的某个地方,但我不敢相信这可以在应用程序的任何 java 类中的任何地方进行。有这样做的例子吗?

有人能指出我正确的方向吗?谢谢。

【问题讨论】:

    标签: spring spring-mvc spring-security


    【解决方案1】:

    注释掉安全 XML 文件中的 &lt;intercept-url pattern="" access="" /&gt; 标记并授予对所有页面的访问权限。这应该可以。

    【讨论】:

    • 是的,这与我发布的解决方案相同。
    • 太棒了。快乐编码:)
    【解决方案2】:

    这似乎有效(在 spring-security.xml 中)

    <!--        <intercept-url pattern="/**" access="hasRole('ROLE_USER')" /> -->
            <intercept-url pattern="/**" access="permitAll" />
    

    【讨论】:

      【解决方案3】:

      检查您的 web.xml 或您的 appContext.xml 以查找加载 spring security.xml bean 的位置(它将类似于 &lt;import resource=../spring security.xml&gt;)并将其注释掉,还要在禁用它之前检查从那里加载的 bean ,因为它可能会重定向或其他什么

      【讨论】:

        猜你喜欢
        • 2021-06-26
        • 2012-05-10
        • 1970-01-01
        • 2014-03-07
        • 2013-07-20
        • 2012-06-28
        • 2018-07-21
        • 1970-01-01
        • 2013-02-03
        相关资源
        最近更新 更多