Skip to content

Commit 1a6760e

Browse files
committed
Polish "Add configuration property to allow multiple issuers"
See gh-41355
1 parent b0b97fb commit 1a6760e

File tree

3 files changed

+46
-24
lines changed

3 files changed

+46
-24
lines changed

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

Lines changed: 12 additions & 21 deletions
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.
@@ -43,26 +43,9 @@ public class OAuth2AuthorizationServerProperties implements InitializingBean {
4343
private String issuer;
4444

4545
/**
46-
* Set to {@code true} if multiple issuers are allowed per host. Using path
47-
* components in the URL of the issuer identifier enables supporting multiple
48-
* issuers per host in a multi-tenant hosting configuration.
49-
*
50-
* <p>
51-
* For example:
52-
* <ul>
53-
* <li>{@code https://example.com/issuer1}</li>
54-
* <li>{@code https://example.com/authz/issuer2}</li>
55-
* </ul>
56-
*
57-
* <p>
58-
* <b>NOTE:</b> Explicitly configuring the issuer identifier via
59-
* {@link #issuer(String)} forces to a single-tenant configuration. Avoid
60-
* configuring the issuer identifier when using a multi-tenant hosting
61-
* configuration, allowing the issuer identifier to be resolved from the
62-
* <i>"current"</i> request.
63-
* @param multipleIssuersAllowed {@code true} if multiple issuers are allowed per
64-
* host, {@code false} otherwise
65-
* @return the {@link Builder} for further configuration
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.
6649
*/
6750
private boolean multipleIssuersAllowed = false;
6851

@@ -76,6 +59,14 @@ public class OAuth2AuthorizationServerProperties implements InitializingBean {
7659
*/
7760
private final Endpoint endpoint = new Endpoint();
7861

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

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

Lines changed: 2 additions & 2 deletions
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.
@@ -51,7 +51,7 @@ AuthorizationServerSettings asAuthorizationServerSettings() {
5151
OAuth2AuthorizationServerProperties.Endpoint endpoint = this.properties.getEndpoint();
5252
OAuth2AuthorizationServerProperties.OidcEndpoint oidc = endpoint.getOidc();
5353
AuthorizationServerSettings.Builder builder = AuthorizationServerSettings.builder();
54-
map.from(this.properties::getIssuer).whenHasText().to(builder::issuer);
54+
map.from(this.properties::getIssuer).to(builder::issuer);
5555
map.from(this.properties::isMultipleIssuersAllowed).to(builder::multipleIssuersAllowed);
5656
map.from(endpoint::getAuthorizationUri).to(builder::authorizationEndpoint);
5757
map.from(endpoint::getDeviceAuthorizationUri).to(builder::deviceAuthorizationEndpoint);

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)