java-使用Spring Security 3.1.3记住我-不建议使用的默认构造函数

我正在使用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最近已在几个类中转移到构造函数注入,因此不建议使用默认构造函数.

/**
* @deprecated Use constructor injection
*/

现在需要将所需的组件注入builder-arg:

<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个豆相同:

<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>
上一篇:Retrofit源码解析


下一篇:取消Apache日志的PHP mysql_ *不推荐使用的错误