Issue
I have a working project with limit login attempts i just need to add Bcrypt password encryptation. I have the following beans:
<beans:bean id="customUserDetailsService"
class="com.setelog.spring.service.CustomUserDetailsService">
<beans:property name="usersByUsernameQuery" value="select * from users where username = ?"/>
<beans:property name="authoritiesByUsernameQuery" value="select username, role from user_roles where username =?" />
<beans:property name="dataSource" ref="dataSource" />
</beans:bean>
<beans:bean id="userDetailsDao" class="com.setelog.spring.dao.UserDetailsDaoImpl" >
<beans:property name="dataSource" ref="dataSource" />
</beans:bean>
<beans:bean id="authenticationProvider"
class="com.setelog.spring.handler.LimitLoginAuthenticationProvider">
<beans:property name="userDetailsService" ref="customUserDetailsService" />
<beans:property name="userDetailsDao" ref="userDetailsDao" />
</beans:bean>
<authentication-manager>
<authentication-provider ref="authenticationProvider" />
</authentication-manager>
I had a project and it had the following which enabled Bcrypt:
<authentication-manager>
<authentication-provider user-service-ref="myUserDetailsService" >
<password-encoder hash="bcrypt" />
</authentication-provider>
</authentication-manager>
But i can't seem to get it working this way. Maybe because of "ref" instead of "user-service-ref" in authentication-provider.
Any help is appreciated.
Solution
I managed to solve it! I just had to add an encoder bean to authenticationProvider:
<beans:bean id="encoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/>
<beans:bean id="authenticationProvider"
class="com.setelog.spring.handler.LimitLoginAuthenticationProvider">
<beans:property name="userDetailsService" ref="customUserDetailsService" />
<beans:property name="userDetailsDao" ref="userDetailsDao" />
<beans:property name="passwordEncoder" ref="encoder" />
</beans:bean>
Answered By - Kunal