指定自定义验证提供程序

时间:2012-11-21 12:30:24

标签: spring spring-security

我使用spring security来验证用户。

我已经创建了一个自定义身份验证提供程序和UserDetails接口的实现。

以下是application-context.xml

<beans:bean id="authenticationProvider" class="com.utils.UserAuthenticationProvider" >
</beans:bean>

<beans:bean id="passwordEncoder" class="com.utils.PasswordUtil"/>
<beans:bean id="saltSource" class="org.springframework.security.authentication.dao.ReflectionSaltSource">
    <beans:property name="userPropertyToUse" value="lastChangeDate" />
</beans:bean>

<authentication-manager alias="authenticationManager" >
    <authentication-provider user-service-ref="userDetailsService" >
        <password-encoder ref="passwordEncoder">
             <salt-source ref="saltSource" />
        </password-encoder>
    </authentication-provider>
</authentication-manager>
<beans:bean id="userDetailsService" class="com.service.impl.UserDetailsServiceImpl" />

我无法将自定义身份验证提供程序链接到身份验证管理器标记。

我尝试使用“custom-authenitication-provider”标签,但似乎这个标签在Spring 3之后不存在。

请帮忙。如果需要进一步的信息,请告诉我

1 个答案:

答案 0 :(得分:0)

您可以通过以下方式尝试:

<bean id="authenticationFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"
        p:authenticationManager-ref="customAuthenticationManager"
        p:authenticationFailureHandler-ref="customAuthenticationFailureHandler"
        p:authenticationSuccessHandler-ref="customAuthenticationSuccessHandler" 
                p:sessionAuthenticationStrategy-ref="sas"/>

    <bean id="customAuthenticationManager" class="com.xxx.yyy.zzz.security.filters.CustomAuthenticationFilter">
        <constructor-arg type="org.hibernate.SessionFactory" ref="sessionFactory"/>
    </bean>

<强> - 编辑 -

如果您只想使用自定义身份验证提供程序,可以按以下方式指定。

<security:authentication-manager>
        <security:authentication-provider ref="authenticationProvider">
        </security:authentication-provider>
    </security:authentication-manager>

希望这会对你有所帮助。欢呼声。

相关问题