gpt4 book ai didi

java - Remember Me with Spring Security 3.1.3 - 弃用的默认构造函数

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:20:21 25 4
gpt4 key购买 nike

我正在使用 Spring Security 3.1 进行登录,但收到已弃用的警告并且我无法删除,看来此配置适用于 3.0 版

<?xml version="1.0" encoding="UTF-8"?>
<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.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">

<http auto-config="true" use-expressions="true">
<intercept-url pattern="/pages/admin/**" access="hasRole('ROLE_ADMIN')" />
<intercept-url pattern="/**" access="permitAll"/>
<form-login login-page="/pages/login.jsf"/>
<remember-me key="jsfspring-sec" services-ref="rememberMeServices"/>
<logout
invalidate-session="true"
delete-cookies="JSESSIONID,SPRING_SECURITY_REMEMBER_ME_COOKIE"
logout-success-url="/pages/login.jsf"/>
</http>

<authentication-manager alias="authenticationManager">
<authentication-provider ref="rememberMeAuthenticationProvider">
</authentication-provider>
<authentication-provider>
<user-service id="userDetailsService">
<user authorities="ROLE_ADMIN" name="admin" password="admin" />
</user-service>
</authentication-provider>
</authentication-manager>

<beans:bean id="rememberMeServices"
class="org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices">
<beans:property name="key" value="jsfspring-sec" />
<beans:property name="userDetailsService" ref="userDetailsService" />
<beans:property name="alwaysRemember" value="true" />
<beans:property name="tokenValiditySeconds" value="60" />
</beans:bean>


<beans:bean id="rememberMeAuthenticationProvider"
class="org.springframework.security.authentication.RememberMeAuthenticationProvider">
<beans:property name="key" value="jsfspring-sec"/>
</beans:bean>

<beans:bean id="rememberMeFilter"
class="org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter">
<beans:property name="rememberMeServices" ref="rememberMeServices"/>
<beans:property name="authenticationManager" ref="authenticationManager" />
</beans:bean>

</beans:beans>

我找不到如何使用 Spring 3.1 来做到这一点。有人能帮我吗?最后三个 bean 已弃用,我将不胜感激。这是 GitHub 中存储库的 URL:https://github.com/wmanriques/spring_template

最佳答案

默认构造函数已被弃用,因为 Spring Security 最近已在多个类中转向构造函数注入(inject)。

/**
* @deprecated Use constructor injection
*/

现在需要用constructor-arg注入(inject)所需的组件:

<beans:bean id="rememberMeServices"
class="org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices">
//First two with constructor - required elements
<beans:constructor-arg value="jsfspring-sec"/>
<beans:constructor-arg ref="userDetailsService"/>

//Last two with properties
<beans:property name="alwaysRemember" value="true"/>
<beans:property name="tokenValiditySeconds" value="60" />
</beans:bean>

与接下来的 2 个 bean 相同:

<beans:bean id="rememberMeAuthenticationProvider"
class="org.springframework.security.authentication.RememberMeAuthenticationProvider">
<beans:constructor-arg value="jsfspring-sec"/>
</beans:bean>

<beans:bean id="rememberMeFilter"
class="org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter">
<beans:constructor-arg ref="authenticationManager"/>
<beans:constructor-arg ref="rememberMeServices"/>
</beans:bean>

关于java - Remember Me with Spring Security 3.1.3 - 弃用的默认构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13244020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com