【问题标题】:Specifying Custom Authentication provider指定自定义身份验证提供程序
【发布时间】:2012-11-09 17:00:11
【问题描述】:

我正在使用 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 以后不再存在。

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

【问题讨论】:

标签: spring spring-security


【解决方案1】:

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

<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>

希望这对您有所帮助。干杯。

【讨论】:

  • 我不想创建新的身份验证管理器。我只想参考我创建的身份验证提供程序。
  • 我尝试了这种方法,但方法的问题是我无法指定 user-service-ref 属性,这是我想要的,因为我想在匹配之前使用自定义创建的加密算法加密传入密码针对 DB 的密码。
猜你喜欢
  • 2012-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-15
  • 2020-07-23
  • 2017-11-21
  • 2011-02-09
  • 2021-09-11
相关资源
最近更新 更多