While working with spring security I had a look at interesting thread in stackoverflow, there it was requirement to have authenticating two set of users against different authentication provider say employees against LDAP
and customer against DATABASE
. Thread came up with accepted solution to have a single login form with a radio button to distinguish employee from customer and to have custom authentication filter which differentiate login request based on userType and sets different authenticationToken(customerAuthToken/employeeAuthToken) and request is proceeded for authentication. There will be two AuthenticationProvider
implementation and authentication is done and decided by supporting token.
In this way thread was able to provide interesting solution to avoid fallback authentication which spring security provides by default.
Have a look at thread Configuring Spring Security 3.x to have multiple entry points
Since answer is completely in xml configuration. I just wanted to have the solution be available in java configuration. I will be posting that in answer.
Now my question, with evolution of spring version, is it possible to have the same functionality by any new features/ minimal configurations apart from my answer?
Since this thread given complete information, i am just posting codes for java configuration reference.
Here i am assuming following things
1. User's and Admin's as two set of users.
2. For simplicity using in memory authentication for both.
- If userType is User only user credential should work.
- If userType is Admin only admin credential should work. - And should be able to provide same application interface with different authorities.
And the codes
You can download working code from my github repository
CustomAuthenticationFilter
CustomAuthentictionTokens
CustomAuthentictionProvider - For Admin
CustomAuthentictionProvider - For User
CustomHandlers required for CustomFilter
And finally
SpringSecurityConfiguration
Hope it will help to understand configuring multiple authentication without fallback authentication.