如何在Spring Web应用程序中临时禁用Spring Security

3
首先,我对Spring一窍不通。一个同事现在正在度假,留下了一个应用程序让我处理。他告诉我不要管安全性,因为最终的方法还没有确定,只需开发其余部分的应用程序即可。
然而,安全性已经启用并阻止访问主网页。我已经检查了几份文档,包括: 从spring-security.xml文件禁用Spring Security 在使用Spring Security Java配置时禁用基本身份验证

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

找不到可行的答案。

我做了以下步骤:

将index.html添加到web.xml中的<welcome-file-list>。这将使我进入登录页面,该页面已经包含在我接手的程序包中。所以,我想我可以简单地禁用安全性。

在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,则会关闭Spring Boot中默认的Web应用程序安全设置。

我不知道他们的意思。我认为这意味着将这些注释放在某个方法上,但我无法相信这可以放在应用程序中任何Java类的任何地方。有没有做到这一点的示例?

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

3个回答

2

在安全XML文件中注释掉<intercept-url pattern="" access="" />标签,并允许访问所有页面。这应该可以解决问题。


是的,那就是我发布的相同解决方案。 - Steve Cohen
太好了。愉快地编码吧 :) - Jeevan Patil

1

这似乎起作用了(在spring-security.xml中)

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

0

请检查您的web.xml或appContext.xml文件,找到加载spring security.xml beans的位置(类似于<import resource=../spring security.xml>),并将其注释掉。在禁用它之前,请检查从那里加载的bean,因为它可能会重定向或执行其他操作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接