Skip to content

Commit b7ff40e

Browse files
committed
Merge pull request #41355 from opcooc
* gh-41355: Polish "Add configuration property to allow multiple issuers" Add configuration property to allow multiple issuers Closes gh-41355
2 parents f7780b4 + 1a6760e commit b7ff40e

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/server/servlet/OAuth2AuthorizationServerProperties.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,6 +42,13 @@ public class OAuth2AuthorizationServerProperties implements InitializingBean {
4242
*/
4343
private String issuer;
4444

45+
/**
46+
* Whether multiple issuers are allowed per host. Using path components in the URL of
47+
* the issuer identifier enables supporting multiple issuers per host in a
48+
* multi-tenant hosting configuration.
49+
*/
50+
private boolean multipleIssuersAllowed = false;
51+
4552
/**
4653
* Registered clients of the Authorization Server.
4754
*/
@@ -52,6 +59,14 @@ public class OAuth2AuthorizationServerProperties implements InitializingBean {
5259
*/
5360
private final Endpoint endpoint = new Endpoint();
5461

62+
public boolean isMultipleIssuersAllowed() {
63+
return this.multipleIssuersAllowed;
64+
}
65+
66+
public void setMultipleIssuersAllowed(boolean multipleIssuersAllowed) {
67+
this.multipleIssuersAllowed = multipleIssuersAllowed;
68+
}
69+
5570
public String getIssuer() {
5671
return this.issuer;
5772
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/server/servlet/OAuth2AuthorizationServerPropertiesMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,6 +52,7 @@ AuthorizationServerSettings asAuthorizationServerSettings() {
5252
OAuth2AuthorizationServerProperties.OidcEndpoint oidc = endpoint.getOidc();
5353
AuthorizationServerSettings.Builder builder = AuthorizationServerSettings.builder();
5454
map.from(this.properties::getIssuer).to(builder::issuer);
55+
map.from(this.properties::isMultipleIssuersAllowed).to(builder::multipleIssuersAllowed);
5556
map.from(endpoint::getAuthorizationUri).to(builder::authorizationEndpoint);
5657
map.from(endpoint::getDeviceAuthorizationUri).to(builder::deviceAuthorizationEndpoint);
5758
map.from(endpoint::getDeviceVerificationUri).to(builder::deviceVerificationEndpoint);

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/server/servlet/OAuth2AuthorizationServerPropertiesMapperTests.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -113,6 +113,37 @@ void getAuthorizationServerSettingsWhenValidParametersShouldAdapt() {
113113
oidc.setUserInfoUri("/user");
114114
AuthorizationServerSettings settings = this.mapper.asAuthorizationServerSettings();
115115
assertThat(settings.getIssuer()).isEqualTo("https://example.com");
116+
assertThat(settings.isMultipleIssuersAllowed()).isFalse();
117+
assertThat(settings.getAuthorizationEndpoint()).isEqualTo("/authorize");
118+
assertThat(settings.getDeviceAuthorizationEndpoint()).isEqualTo("/device_authorization");
119+
assertThat(settings.getDeviceVerificationEndpoint()).isEqualTo("/device_verification");
120+
assertThat(settings.getTokenEndpoint()).isEqualTo("/token");
121+
assertThat(settings.getJwkSetEndpoint()).isEqualTo("/jwks");
122+
assertThat(settings.getTokenRevocationEndpoint()).isEqualTo("/revoke");
123+
assertThat(settings.getTokenIntrospectionEndpoint()).isEqualTo("/introspect");
124+
assertThat(settings.getOidcLogoutEndpoint()).isEqualTo("/logout");
125+
assertThat(settings.getOidcClientRegistrationEndpoint()).isEqualTo("/register");
126+
assertThat(settings.getOidcUserInfoEndpoint()).isEqualTo("/user");
127+
}
128+
129+
@Test
130+
void getAuthorizationServerSettingsWhenMultipleIssuersAllowedShouldAdapt() {
131+
this.properties.setMultipleIssuersAllowed(true);
132+
OAuth2AuthorizationServerProperties.Endpoint endpoints = this.properties.getEndpoint();
133+
endpoints.setAuthorizationUri("/authorize");
134+
endpoints.setDeviceAuthorizationUri("/device_authorization");
135+
endpoints.setDeviceVerificationUri("/device_verification");
136+
endpoints.setTokenUri("/token");
137+
endpoints.setJwkSetUri("/jwks");
138+
endpoints.setTokenRevocationUri("/revoke");
139+
endpoints.setTokenIntrospectionUri("/introspect");
140+
OAuth2AuthorizationServerProperties.OidcEndpoint oidc = endpoints.getOidc();
141+
oidc.setLogoutUri("/logout");
142+
oidc.setClientRegistrationUri("/register");
143+
oidc.setUserInfoUri("/user");
144+
AuthorizationServerSettings settings = this.mapper.asAuthorizationServerSettings();
145+
assertThat(settings.getIssuer()).isNull();
146+
assertThat(settings.isMultipleIssuersAllowed()).isTrue();
116147
assertThat(settings.getAuthorizationEndpoint()).isEqualTo("/authorize");
117148
assertThat(settings.getDeviceAuthorizationEndpoint()).isEqualTo("/device_authorization");
118149
assertThat(settings.getDeviceVerificationEndpoint()).isEqualTo("/device_verification");

0 commit comments

Comments
 (0)