|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright 2020-2023 the original author or authors.
|
|
|
|
|
|
+ * Copyright 2020-2024 the original author or authors.
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -63,7 +63,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|
@ExtendWith(SpringTestContextExtension.class)
|
|
@ExtendWith(SpringTestContextExtension.class)
|
|
public class OidcProviderConfigurationTests {
|
|
public class OidcProviderConfigurationTests {
|
|
private static final String DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI = "/.well-known/openid-configuration";
|
|
private static final String DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI = "/.well-known/openid-configuration";
|
|
- private static final String ISSUER_URL = "https://example.com";
|
|
|
|
|
|
+ private static final String ISSUER = "https://example.com";
|
|
|
|
|
|
public final SpringTestContext spring = new SpringTestContext();
|
|
public final SpringTestContext spring = new SpringTestContext();
|
|
|
|
|
|
@@ -77,9 +77,29 @@ public class OidcProviderConfigurationTests {
|
|
public void requestWhenConfigurationRequestAndIssuerSetThenReturnDefaultConfigurationResponse() throws Exception {
|
|
public void requestWhenConfigurationRequestAndIssuerSetThenReturnDefaultConfigurationResponse() throws Exception {
|
|
this.spring.register(AuthorizationServerConfiguration.class).autowire();
|
|
this.spring.register(AuthorizationServerConfiguration.class).autowire();
|
|
|
|
|
|
- this.mvc.perform(get(ISSUER_URL.concat(DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI)))
|
|
|
|
|
|
+ this.mvc.perform(get(ISSUER.concat(DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI)))
|
|
.andExpect(status().is2xxSuccessful())
|
|
.andExpect(status().is2xxSuccessful())
|
|
- .andExpectAll(defaultConfigurationMatchers());
|
|
|
|
|
|
+ .andExpectAll(defaultConfigurationMatchers(ISSUER));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void requestWhenConfigurationRequestIncludesIssuerPathThenConfigurationResponseHasIssuerPath() throws Exception {
|
|
|
|
+ this.spring.register(AuthorizationServerConfigurationWithIssuerNotSet.class).autowire();
|
|
|
|
+
|
|
|
|
+ String issuer = "https://example.com:8443/issuer1";
|
|
|
|
+ this.mvc.perform(get(issuer.concat(DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI)))
|
|
|
|
+ .andExpect(status().is2xxSuccessful())
|
|
|
|
+ .andExpectAll(defaultConfigurationMatchers(issuer));
|
|
|
|
+
|
|
|
|
+ issuer = "https://example.com:8443/path1/issuer2";
|
|
|
|
+ this.mvc.perform(get(issuer.concat(DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI)))
|
|
|
|
+ .andExpect(status().is2xxSuccessful())
|
|
|
|
+ .andExpectAll(defaultConfigurationMatchers(issuer));
|
|
|
|
+
|
|
|
|
+ issuer = "https://example.com:8443/path1/path2/issuer3";
|
|
|
|
+ this.mvc.perform(get(issuer.concat(DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI)))
|
|
|
|
+ .andExpect(status().is2xxSuccessful())
|
|
|
|
+ .andExpectAll(defaultConfigurationMatchers(issuer));
|
|
}
|
|
}
|
|
|
|
|
|
// gh-632
|
|
// gh-632
|
|
@@ -87,10 +107,10 @@ public class OidcProviderConfigurationTests {
|
|
public void requestWhenConfigurationRequestAndUserAuthenticatedThenReturnConfigurationResponse() throws Exception {
|
|
public void requestWhenConfigurationRequestAndUserAuthenticatedThenReturnConfigurationResponse() throws Exception {
|
|
this.spring.register(AuthorizationServerConfiguration.class).autowire();
|
|
this.spring.register(AuthorizationServerConfiguration.class).autowire();
|
|
|
|
|
|
- this.mvc.perform(get(ISSUER_URL.concat(DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI))
|
|
|
|
|
|
+ this.mvc.perform(get(ISSUER.concat(DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI))
|
|
.with(user("user")))
|
|
.with(user("user")))
|
|
.andExpect(status().is2xxSuccessful())
|
|
.andExpect(status().is2xxSuccessful())
|
|
- .andExpectAll(defaultConfigurationMatchers());
|
|
|
|
|
|
+ .andExpectAll(defaultConfigurationMatchers(ISSUER));
|
|
}
|
|
}
|
|
|
|
|
|
// gh-616
|
|
// gh-616
|
|
@@ -98,7 +118,7 @@ public class OidcProviderConfigurationTests {
|
|
public void requestWhenConfigurationRequestAndConfigurationCustomizerSetThenReturnCustomConfigurationResponse() throws Exception {
|
|
public void requestWhenConfigurationRequestAndConfigurationCustomizerSetThenReturnCustomConfigurationResponse() throws Exception {
|
|
this.spring.register(AuthorizationServerConfigurationWithProviderConfigurationCustomizer.class).autowire();
|
|
this.spring.register(AuthorizationServerConfigurationWithProviderConfigurationCustomizer.class).autowire();
|
|
|
|
|
|
- this.mvc.perform(get(ISSUER_URL.concat(DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI)))
|
|
|
|
|
|
+ this.mvc.perform(get(ISSUER.concat(DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI)))
|
|
.andExpect(status().is2xxSuccessful())
|
|
.andExpect(status().is2xxSuccessful())
|
|
.andExpect(jsonPath(OAuth2AuthorizationServerMetadataClaimNames.SCOPES_SUPPORTED,
|
|
.andExpect(jsonPath(OAuth2AuthorizationServerMetadataClaimNames.SCOPES_SUPPORTED,
|
|
hasItems(OidcScopes.OPENID, OidcScopes.PROFILE, OidcScopes.EMAIL)));
|
|
hasItems(OidcScopes.OPENID, OidcScopes.PROFILE, OidcScopes.EMAIL)));
|
|
@@ -108,35 +128,35 @@ public class OidcProviderConfigurationTests {
|
|
public void requestWhenConfigurationRequestAndClientRegistrationEnabledThenConfigurationResponseIncludesRegistrationEndpoint() throws Exception {
|
|
public void requestWhenConfigurationRequestAndClientRegistrationEnabledThenConfigurationResponseIncludesRegistrationEndpoint() throws Exception {
|
|
this.spring.register(AuthorizationServerConfigurationWithClientRegistrationEnabled.class).autowire();
|
|
this.spring.register(AuthorizationServerConfigurationWithClientRegistrationEnabled.class).autowire();
|
|
|
|
|
|
- this.mvc.perform(get(ISSUER_URL.concat(DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI)))
|
|
|
|
|
|
+ this.mvc.perform(get(ISSUER.concat(DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI)))
|
|
.andExpect(status().is2xxSuccessful())
|
|
.andExpect(status().is2xxSuccessful())
|
|
- .andExpectAll(defaultConfigurationMatchers())
|
|
|
|
- .andExpect(jsonPath("$.registration_endpoint").value(ISSUER_URL.concat(this.authorizationServerSettings.getOidcClientRegistrationEndpoint())));
|
|
|
|
|
|
+ .andExpectAll(defaultConfigurationMatchers(ISSUER))
|
|
|
|
+ .andExpect(jsonPath("$.registration_endpoint").value(ISSUER.concat(this.authorizationServerSettings.getOidcClientRegistrationEndpoint())));
|
|
}
|
|
}
|
|
|
|
|
|
- private ResultMatcher[] defaultConfigurationMatchers() {
|
|
|
|
|
|
+ private ResultMatcher[] defaultConfigurationMatchers(String issuer) {
|
|
// @formatter:off
|
|
// @formatter:off
|
|
return new ResultMatcher[] {
|
|
return new ResultMatcher[] {
|
|
- jsonPath("issuer").value(ISSUER_URL),
|
|
|
|
- jsonPath("authorization_endpoint").value(ISSUER_URL.concat(this.authorizationServerSettings.getAuthorizationEndpoint())),
|
|
|
|
- jsonPath("token_endpoint").value(ISSUER_URL.concat(this.authorizationServerSettings.getTokenEndpoint())),
|
|
|
|
|
|
+ jsonPath("issuer").value(issuer),
|
|
|
|
+ jsonPath("authorization_endpoint").value(issuer.concat(this.authorizationServerSettings.getAuthorizationEndpoint())),
|
|
|
|
+ jsonPath("token_endpoint").value(issuer.concat(this.authorizationServerSettings.getTokenEndpoint())),
|
|
jsonPath("$.token_endpoint_auth_methods_supported[0]").value(ClientAuthenticationMethod.CLIENT_SECRET_BASIC.getValue()),
|
|
jsonPath("$.token_endpoint_auth_methods_supported[0]").value(ClientAuthenticationMethod.CLIENT_SECRET_BASIC.getValue()),
|
|
jsonPath("$.token_endpoint_auth_methods_supported[1]").value(ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue()),
|
|
jsonPath("$.token_endpoint_auth_methods_supported[1]").value(ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue()),
|
|
jsonPath("$.token_endpoint_auth_methods_supported[2]").value(ClientAuthenticationMethod.CLIENT_SECRET_JWT.getValue()),
|
|
jsonPath("$.token_endpoint_auth_methods_supported[2]").value(ClientAuthenticationMethod.CLIENT_SECRET_JWT.getValue()),
|
|
jsonPath("$.token_endpoint_auth_methods_supported[3]").value(ClientAuthenticationMethod.PRIVATE_KEY_JWT.getValue()),
|
|
jsonPath("$.token_endpoint_auth_methods_supported[3]").value(ClientAuthenticationMethod.PRIVATE_KEY_JWT.getValue()),
|
|
- jsonPath("jwks_uri").value(ISSUER_URL.concat(this.authorizationServerSettings.getJwkSetEndpoint())),
|
|
|
|
- jsonPath("userinfo_endpoint").value(ISSUER_URL.concat(this.authorizationServerSettings.getOidcUserInfoEndpoint())),
|
|
|
|
- jsonPath("end_session_endpoint").value(ISSUER_URL.concat(this.authorizationServerSettings.getOidcLogoutEndpoint())),
|
|
|
|
|
|
+ jsonPath("jwks_uri").value(issuer.concat(this.authorizationServerSettings.getJwkSetEndpoint())),
|
|
|
|
+ jsonPath("userinfo_endpoint").value(issuer.concat(this.authorizationServerSettings.getOidcUserInfoEndpoint())),
|
|
|
|
+ jsonPath("end_session_endpoint").value(issuer.concat(this.authorizationServerSettings.getOidcLogoutEndpoint())),
|
|
jsonPath("response_types_supported").value(OAuth2AuthorizationResponseType.CODE.getValue()),
|
|
jsonPath("response_types_supported").value(OAuth2AuthorizationResponseType.CODE.getValue()),
|
|
jsonPath("$.grant_types_supported[0]").value(AuthorizationGrantType.AUTHORIZATION_CODE.getValue()),
|
|
jsonPath("$.grant_types_supported[0]").value(AuthorizationGrantType.AUTHORIZATION_CODE.getValue()),
|
|
jsonPath("$.grant_types_supported[1]").value(AuthorizationGrantType.CLIENT_CREDENTIALS.getValue()),
|
|
jsonPath("$.grant_types_supported[1]").value(AuthorizationGrantType.CLIENT_CREDENTIALS.getValue()),
|
|
jsonPath("$.grant_types_supported[2]").value(AuthorizationGrantType.REFRESH_TOKEN.getValue()),
|
|
jsonPath("$.grant_types_supported[2]").value(AuthorizationGrantType.REFRESH_TOKEN.getValue()),
|
|
- jsonPath("revocation_endpoint").value(ISSUER_URL.concat(this.authorizationServerSettings.getTokenRevocationEndpoint())),
|
|
|
|
|
|
+ jsonPath("revocation_endpoint").value(issuer.concat(this.authorizationServerSettings.getTokenRevocationEndpoint())),
|
|
jsonPath("$.revocation_endpoint_auth_methods_supported[0]").value(ClientAuthenticationMethod.CLIENT_SECRET_BASIC.getValue()),
|
|
jsonPath("$.revocation_endpoint_auth_methods_supported[0]").value(ClientAuthenticationMethod.CLIENT_SECRET_BASIC.getValue()),
|
|
jsonPath("$.revocation_endpoint_auth_methods_supported[1]").value(ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue()),
|
|
jsonPath("$.revocation_endpoint_auth_methods_supported[1]").value(ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue()),
|
|
jsonPath("$.revocation_endpoint_auth_methods_supported[2]").value(ClientAuthenticationMethod.CLIENT_SECRET_JWT.getValue()),
|
|
jsonPath("$.revocation_endpoint_auth_methods_supported[2]").value(ClientAuthenticationMethod.CLIENT_SECRET_JWT.getValue()),
|
|
jsonPath("$.revocation_endpoint_auth_methods_supported[3]").value(ClientAuthenticationMethod.PRIVATE_KEY_JWT.getValue()),
|
|
jsonPath("$.revocation_endpoint_auth_methods_supported[3]").value(ClientAuthenticationMethod.PRIVATE_KEY_JWT.getValue()),
|
|
- jsonPath("introspection_endpoint").value(ISSUER_URL.concat(this.authorizationServerSettings.getTokenIntrospectionEndpoint())),
|
|
|
|
|
|
+ jsonPath("introspection_endpoint").value(issuer.concat(this.authorizationServerSettings.getTokenIntrospectionEndpoint())),
|
|
jsonPath("$.introspection_endpoint_auth_methods_supported[0]").value(ClientAuthenticationMethod.CLIENT_SECRET_BASIC.getValue()),
|
|
jsonPath("$.introspection_endpoint_auth_methods_supported[0]").value(ClientAuthenticationMethod.CLIENT_SECRET_BASIC.getValue()),
|
|
jsonPath("$.introspection_endpoint_auth_methods_supported[1]").value(ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue()),
|
|
jsonPath("$.introspection_endpoint_auth_methods_supported[1]").value(ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue()),
|
|
jsonPath("$.introspection_endpoint_auth_methods_supported[2]").value(ClientAuthenticationMethod.CLIENT_SECRET_JWT.getValue()),
|
|
jsonPath("$.introspection_endpoint_auth_methods_supported[2]").value(ClientAuthenticationMethod.CLIENT_SECRET_JWT.getValue()),
|
|
@@ -218,7 +238,18 @@ public class OidcProviderConfigurationTests {
|
|
@Bean
|
|
@Bean
|
|
AuthorizationServerSettings authorizationServerSettings() {
|
|
AuthorizationServerSettings authorizationServerSettings() {
|
|
return AuthorizationServerSettings.builder()
|
|
return AuthorizationServerSettings.builder()
|
|
- .issuer(ISSUER_URL)
|
|
|
|
|
|
+ .issuer(ISSUER)
|
|
|
|
+ .build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @EnableWebSecurity
|
|
|
|
+ static class AuthorizationServerConfigurationWithIssuerNotSet extends AuthorizationServerConfiguration {
|
|
|
|
+
|
|
|
|
+ @Bean
|
|
|
|
+ AuthorizationServerSettings authorizationServerSettings() {
|
|
|
|
+ return AuthorizationServerSettings.builder()
|
|
.build();
|
|
.build();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -306,7 +337,7 @@ public class OidcProviderConfigurationTests {
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
AuthorizationServerSettings authorizationServerSettings() {
|
|
AuthorizationServerSettings authorizationServerSettings() {
|
|
- return AuthorizationServerSettings.builder().issuer(ISSUER_URL + "?param=value").build();
|
|
|
|
|
|
+ return AuthorizationServerSettings.builder().issuer(ISSUER + "?param=value").build();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -315,7 +346,7 @@ public class OidcProviderConfigurationTests {
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
AuthorizationServerSettings authorizationServerSettings() {
|
|
AuthorizationServerSettings authorizationServerSettings() {
|
|
- return AuthorizationServerSettings.builder().issuer(ISSUER_URL + "#fragment").build();
|
|
|
|
|
|
+ return AuthorizationServerSettings.builder().issuer(ISSUER + "#fragment").build();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -324,7 +355,7 @@ public class OidcProviderConfigurationTests {
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
AuthorizationServerSettings authorizationServerSettings() {
|
|
AuthorizationServerSettings authorizationServerSettings() {
|
|
- return AuthorizationServerSettings.builder().issuer(ISSUER_URL + "?param=value#fragment").build();
|
|
|
|
|
|
+ return AuthorizationServerSettings.builder().issuer(ISSUER + "?param=value#fragment").build();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -333,7 +364,7 @@ public class OidcProviderConfigurationTests {
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
AuthorizationServerSettings authorizationServerSettings() {
|
|
AuthorizationServerSettings authorizationServerSettings() {
|
|
- return AuthorizationServerSettings.builder().issuer(ISSUER_URL + "?").build();
|
|
|
|
|
|
+ return AuthorizationServerSettings.builder().issuer(ISSUER + "?").build();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -342,7 +373,7 @@ public class OidcProviderConfigurationTests {
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
AuthorizationServerSettings authorizationServerSettings() {
|
|
AuthorizationServerSettings authorizationServerSettings() {
|
|
- return AuthorizationServerSettings.builder().issuer(ISSUER_URL + "#").build();
|
|
|
|
|
|
+ return AuthorizationServerSettings.builder().issuer(ISSUER + "#").build();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|