forked from provectus/kafka-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Make Okta authentication respects proxy
- Loading branch information
1 parent
92e718e
commit 3b88135
Showing
2 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
.../main/java/com/provectus/kafka/ui/config/auth/CustomOidcAuthenticationManagerBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.provectus.kafka.ui.config.auth; | ||
|
||
import com.provectus.kafka.ui.util.WebClientConfigurator; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.security.oauth2.client.endpoint.WebClientReactiveAuthorizationCodeTokenResponseClient; | ||
import org.springframework.security.oauth2.client.oidc.authentication.OidcAuthorizationCodeReactiveAuthenticationManager; | ||
import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserRequest; | ||
import org.springframework.security.oauth2.client.registration.ClientRegistration; | ||
import org.springframework.security.oauth2.client.userinfo.ReactiveOAuth2UserService; | ||
import org.springframework.security.oauth2.core.oidc.user.OidcUser; | ||
import org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder; | ||
import org.springframework.security.oauth2.jwt.ReactiveJwtDecoderFactory; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
@Component | ||
@ConditionalOnProperty(value = "auth.type", havingValue = "OAUTH2") | ||
public class CustomOidcAuthenticationManagerBuilder { | ||
private WebClient webClient = new WebClientConfigurator().build(); | ||
// Reuse customOidcUserService bean from `OAuthSecurityConfig` | ||
private ReactiveOAuth2UserService<OidcUserRequest, OidcUser> oidcUserService; | ||
@Value("${auth.oauth2.client.okta.jwk-set-uri}") | ||
private String jwkUri; | ||
|
||
public CustomOidcAuthenticationManagerBuilder(ReactiveOAuth2UserService<OidcUserRequest, OidcUser> oidcUserService) { | ||
this.oidcUserService = oidcUserService; | ||
} | ||
|
||
public OidcAuthorizationCodeReactiveAuthenticationManager build() { | ||
// Use WebClient that respects proxy settings to get token | ||
WebClientReactiveAuthorizationCodeTokenResponseClient client = | ||
new WebClientReactiveAuthorizationCodeTokenResponseClient(); | ||
client.setWebClient(webClient); | ||
|
||
// Use WebClient that respects proxy settings to get JWT | ||
ReactiveJwtDecoderFactory<ClientRegistration> idTokenDecoderFactory = | ||
(clientRegistration) -> NimbusReactiveJwtDecoder.withJwkSetUri(jwkUri) | ||
.webClient(webClient) | ||
.build(); | ||
|
||
OidcAuthorizationCodeReactiveAuthenticationManager manager = | ||
new OidcAuthorizationCodeReactiveAuthenticationManager(client, oidcUserService); | ||
manager.setJwtDecoderFactory(idTokenDecoderFactory); | ||
|
||
return manager; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters