Skip to content

Commit

Permalink
fixed OAuth2 logout handler to allow OAuth2 tests to run
Browse files Browse the repository at this point in the history
  • Loading branch information
emmdurin committed Oct 20, 2023
1 parent a7bafa0 commit 6b4f0a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -97,8 +92,10 @@ ServerLogoutSuccessHandler oidcLogoutSuccessHandler(
}
}
});
oidcLogoutSuccessHandler.setPostLogoutRedirectUri("{baseUrl}/login?logout");

OidcClientInitiatedServerLogoutSuccessHandler oidcLogoutSuccessHandler = new OidcClientInitiatedServerLogoutSuccessHandler(
clientRegistrationRepository);
oidcLogoutSuccessHandler.setPostLogoutRedirectUri("{baseUrl}/login?logout");
return oidcLogoutSuccessHandler;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 6b4f0a7

Please sign in to comment.