Reputation: 25
How can I combine basic authorization (login + password) with authorization of other services (google, github, facebook) using Spring Boot and Spring Security? There is a lot of information and I don’t understand how to solve this problem correctly. I would be grateful for the tutorial or link to the material.
Upvotes: 2
Views: 305
Reputation: 8213
AuthenticationFilter
you will have a UsernamePasswordAuthenticationFilter
for username/password authentication mechanism and a OAuth2LoginAuthenticationFilter
for Oauth2 Login mechanism. And then for AuthenticationToken
s, you will have UsernamePasswordAuthenticationToken
and OAuth2LoginAuthenticationToken
. And so on for each stage.password
param (or you know it is always come from /login
url), at the AuthenticationFilter
, OAuth2LoginAuthenticationFilter
will satisfy it and it will create the UsernamePasswordAuthenticationToken
and pass it to third stage . But if the request comes with token, it will satisfy OAuth2LoginAuthenticationFilter
and it will create OAuth2LoginAuthenticationToken
and pass it to 3rd stage.I hope this gives you a high level picture, just implement an sample app with username and password only, put breakpoints in the source code spring security classes I mentioned and see how it is iterating at each stage.
Once you are confident how these filters are chained, then try to add something like ldap authentication as the second authentication mechanism for your app.
Once you are confident implementing these 2, then go for adding OAuth2 by following https://spring.io/guides/tutorials/spring-boot-oauth2/
Reference Diagram: https://springbootdev.com/2017/08/23/spring-security-authentication-architecture/
Upvotes: 1