I have a reactive Spring Boot 2 application, which acts as a web agent that initiates user authentication using Spring Security. The end users, who reach this application, come from either public or private domains and the web agent should accordingly redirect them to either identity-provider.com (public) or identity-provider.biz (private) for login. The redirect_uri post authentication remains the same in both cases.
We have configured 2 Oauth2 identity providers and 2 corresponding Oauth2 clients inside the application.yaml.
spring:
security:
oauth2:
client:
provider:
idpcom:
issuer-uri: https://identity-provider.com
idpbiz:
issuer-uri: https://identity-provider.biz
registration:
idpcom:
provider: idpcom
client-id: clientid
client-secret: clientsecret
authorization-grant-type: authorization_code
redirect-uri: https://my-domain.com/login/oauth2/code/idpcom
scope:
- openid
idpbiz:
provider: idpbiz
client-id: clientid
client-secret: clientsecret
authorization-grant-type: authorization_code
redirect-uri: https://my-domain.com/login/oauth2/code/idpbiz
scope:
- openid
With this configuration, when application receives a request, the end user is presented with links to both identity providers. The user is forced to choose one of them and start the authentication flow. what end user sees
We found that following code in Spring security is building the HTML page shown above
ServerHttpSecurity.setDefaultEntryPoints(ServerHttpSecurity http)
Our requirement is to programmatically resolve the identity provider at runtime and directly show the corresponding login page to the end user. The decision to use identity-provider.com or identity-provider.biz is based on end users IP address (captured in X-Forwarded-For header).
We need suggestions to implement this functionality.
According to the manual, when defining
You could write something like that in a servlet:
In a reactive application, the controller method would use
ServerWebExchangeinstead ofHttpServletRequest:the
SecurityWebFilterChainwould be configured slightly differently too: