0

I am using spring security for authentication of users.

I have created a custom authentication provider and implementation of UserDetails interface.

Following is 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" />

I am not able to link my custom authentication provider to authentication manager tag.

I tried using "custom-authenitication-provider" tag, but it seems that this tag is not present in Spring 3 onwards.

Please help. Let me know if any further info is reqd

Rachit Agrawal
  • 685
  • 4
  • 13
  • 35
  • 1
    Possible duplicate of [spring-security-custom-authentication-and-password-encoding](http://stackoverflow.com/questions/7658853/spring-security-custom-authentication-and-password-encoding) – Ravi Kadaboina Nov 21 '12 at 16:19

1 Answers1

0

You can try this in following way.

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

--Edit--

If you just want to use the custom authentication provider you can specify it the following way.

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

Hope this helps you. Cheers.

Japan Trivedi
  • 4,445
  • 2
  • 23
  • 44
  • I dont want to create a new authentication manager. I just want to refer to the auth provider i have created. – Rachit Agrawal Nov 21 '12 at 12:50
  • I tried this approach but the problem with approach is I cant specify the user-service-ref attribute, which I want to because I want to encrypt the incoming password with my custom created encryption algorithm before matching the password against DB. – Rachit Agrawal Nov 21 '12 at 13:01