From 6b4f0a779955fdda57bdb053834f28ed0e263a23 Mon Sep 17 00:00:00 2001 From: Emmanuel Durin Date: Fri, 20 Oct 2023 14:07:52 +0200 Subject: [PATCH] fixed OAuth2 logout handler to allow OAuth2 tests to run --- .../security/oauth2/OAuth2Configuration.java | 15 ++++++--------- .../OAuth2SecurityAutoConfigurationTest.java | 3 ++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/gateway/src/main/java/org/georchestra/gateway/security/oauth2/OAuth2Configuration.java b/gateway/src/main/java/org/georchestra/gateway/security/oauth2/OAuth2Configuration.java index 76374b54..cbe53fc8 100644 --- a/gateway/src/main/java/org/georchestra/gateway/security/oauth2/OAuth2Configuration.java +++ b/gateway/src/main/java/org/georchestra/gateway/security/oauth2/OAuth2Configuration.java @@ -32,6 +32,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.security.authentication.ReactiveAuthenticationManager; import org.springframework.security.config.web.server.ServerHttpSecurity; @@ -72,17 +73,11 @@ public static final class OAuth2AuthenticationCustomizer implements ServerHttpSe } } - /** - * TODO: REVISIT, we don't know why this bean has been added, but it breaks - * OAuth2SecurityAutoConfigurationTest as there's no - * InMemoryReactiveClientRegistrationRepository - */ - // @Bean + @Bean + @Profile("!test") ServerLogoutSuccessHandler oidcLogoutSuccessHandler( InMemoryReactiveClientRegistrationRepository clientRegistrationRepository, ExtendedOAuth2ClientProperties properties) { - OidcClientInitiatedServerLogoutSuccessHandler oidcLogoutSuccessHandler = new OidcClientInitiatedServerLogoutSuccessHandler( - clientRegistrationRepository); clientRegistrationRepository.forEach(client -> { if (client.getProviderDetails().getConfigurationMetadata().isEmpty() && properties.getProvider().get(client.getRegistrationId()) != null @@ -97,8 +92,10 @@ ServerLogoutSuccessHandler oidcLogoutSuccessHandler( } } }); - oidcLogoutSuccessHandler.setPostLogoutRedirectUri("{baseUrl}/login?logout"); + OidcClientInitiatedServerLogoutSuccessHandler oidcLogoutSuccessHandler = new OidcClientInitiatedServerLogoutSuccessHandler( + clientRegistrationRepository); + oidcLogoutSuccessHandler.setPostLogoutRedirectUri("{baseUrl}/login?logout"); return oidcLogoutSuccessHandler; } diff --git a/gateway/src/test/java/org/georchestra/gateway/autoconfigure/security/OAuth2SecurityAutoConfigurationTest.java b/gateway/src/test/java/org/georchestra/gateway/autoconfigure/security/OAuth2SecurityAutoConfigurationTest.java index 0fcdf5b2..442902c5 100644 --- a/gateway/src/test/java/org/georchestra/gateway/autoconfigure/security/OAuth2SecurityAutoConfigurationTest.java +++ b/gateway/src/test/java/org/georchestra/gateway/autoconfigure/security/OAuth2SecurityAutoConfigurationTest.java @@ -41,7 +41,8 @@ */ class OAuth2SecurityAutoConfigurationTest { private ReactiveWebApplicationContextRunner runner = new ReactiveWebApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(OAuth2SecurityAutoConfiguration.class)); + .withConfiguration(AutoConfigurations.of(OAuth2SecurityAutoConfiguration.class)) + .withPropertyValues("spring.profiles.active=test"); @Test void testDisabledByDefault() {