【问题标题】:Spring Security 3.2.0.RC1 - <http> element and deprecated methodSpring Security 3.2.0.RC1 - <http> 元素和不推荐使用的方法
【发布时间】:2013-09-05 07:34:21
【问题描述】:

升级到 Spring Security 3.2.0.RC1 后,我在我的 xml 配置中收到 &lt;http auto-config="true"&gt; 的警告“方法 'setFilterProcessesUrl' 已标记为弃用”。即使是非常简单的配置,我也会收到此警告:

<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.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security.xsd">

    <http auto-config="true">
        <intercept-url pattern="/myurl*" access="ROLE_USER" />
    </http>

    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="user1" password="12345" authorities="ROLE_USER" />
            </user-service>
        </authentication-provider>
    </authentication-manager>

</beans:beans>


根据 Spring Security 3.2 API documentation setFilterProcessesUrl 已被弃用,而应使用 setRequiresAuthenticationRequestMatcher(RequestMatcher) 。如何更改此基本 XML 配置,使其不使用已弃用的方法?我正在使用带有 Spring Tool Suite 插件的 Eclipse Kepler。

更新:

如果我删除 &lt;http auto-config="true"&gt; 并将 &lt;form-login /&gt; 添加到 http 元素

<http>
    <intercept-url pattern="/myurl*" access="ROLE_USER" />
    <form-login />
</http>

我还收到“方法'setFilterProcessesUrl'被标记为已弃用”警告,如果我添加&lt;logout /&gt;,我第二次收到相同的警告。 另一方面,如果我用&lt;http-basic /&gt; 替换&lt;form-login /&gt;&lt;logout /&gt;,警告就会消失。

【问题讨论】:

  • 与 Spring Security 3.2.0.RC2 相同的问题。我真的不明白,他们为什么要弃用他们自己的命名空间仍在使用的方法?目前唯一的解决方案似乎是回滚到 3.2.0.M2。

标签: java eclipse spring spring-security spring-tool-suite


【解决方案1】:

如果您使用命名空间,那么像这样的 IDE 错误并不重要,因为您可以保证 Spring Security 将支持该功能。您实际上并没有自己使用该方法。

auto-config 通常是个坏主意。查看该配置的人不会轻易知道它实际上做了什么。例如,您真的想要基本身份验证吗?您最好删除 auto-config 并明确添加您想要的功能。

【讨论】:

  • 谢谢卢克,你说得对,auto-config 是个坏主意,我只是在我的示例中使用它以使其不那么冗长。我用&lt;form-login /&gt;&lt;logout /&gt; 替换了它,但警告仍然存在。我知道警告只是警告,但如果有办法修复它,我更愿意这样做,特别是因为它是我项目中唯一的警告,而我在 Spring Security 3.2.0 中没有得到它。 M2.
【解决方案2】:

在 Spring Security 3.2.1 中修复。警告是由使用不推荐使用的方法的 XML 命名空间引起的。 https://jira.springsource.org/browse/SEC-2455

【讨论】:

  • 感谢您的回答。正在寻找有关如何解决此问题的解决方案。
猜你喜欢
  • 2013-09-18
  • 1970-01-01
  • 1970-01-01
  • 2014-01-18
  • 2015-10-26
  • 2021-02-01
  • 2020-09-08
  • 2015-12-03
  • 2011-02-21
相关资源
最近更新 更多