For an existing working app, I want to provide a secondary AuthenticationProvider, probably with a DaoAuthenticationProvider. Let’s say it’s for authenticating a “back up” password, or a prior password that was changed due to strict password policies and the user forgot the new password. 😉
For proof of concept, what would the implementation look like for this secondaryAuthenticationProvider that will always authenticate the user regardless of the incoming credentials? (something that returns an authenticated Authentication object)
Which one of the MANY org.springframework.security.providers & subpackage classes and methods should I look at?
Example config:
<bean id="authenticationManager" class="org.springframework.security.providers.ProviderManager">
<property name="providers">
<list>
<ref local="daoAuthenticationProvider"/>
<ref local="secondaryAuthenticationProvider"/> <!-- new AuthProv -->
<ref local="rememberMeAuthenticationProvider"/>
</list>
</property>
</bean>
If you have only one alternative password, you can declare a second
DaoAuthenticationProviderbacked by a specialUserDetailsService, which will produceUserDetailswith that alternative password.Otherwise, you can create a custom
AuthenticationProvider. Credentials check inDaoAuthenticationProvideroccurs inadditionalAuthenticationChecks(), so if you want to change that logic you can create a subclass ofDaoAuthenticationProviderand override this method with your implementation.For example, if you want to authenticate the user regardless of its credentials, you can override this method with an empty implementation.