Skip to content

Commit 656ad72

Browse files
committed
Merge branch '6.3.x' into 6.4.x
Closes gh-17016
2 parents d76ccc6 + 0e84f31 commit 656ad72

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/registration/ClientRegistrations.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -17,6 +17,7 @@
1717
package org.springframework.security.oauth2.client.registration;
1818

1919
import java.net.URI;
20+
import java.util.ArrayList;
2021
import java.util.Collections;
2122
import java.util.LinkedHashMap;
2223
import java.util.List;
@@ -49,6 +50,7 @@
4950
* @author Rob Winch
5051
* @author Josh Cummings
5152
* @author Rafiullah Hamedy
53+
* @author Evgeniy Cheban
5254
* @since 5.1
5355
*/
5456
public final class ClientRegistrations {
@@ -251,6 +253,7 @@ private static Supplier<ClientRegistration.Builder> getRfc8414Builder(URI issuer
251253
private static ClientRegistration.Builder getBuilder(String issuer,
252254
Supplier<ClientRegistration.Builder>... suppliers) {
253255
String errorMessage = "Unable to resolve Configuration with the provided Issuer of \"" + issuer + "\"";
256+
List<String> errors = new ArrayList<>();
254257
for (Supplier<ClientRegistration.Builder> supplier : suppliers) {
255258
try {
256259
return supplier.get();
@@ -259,6 +262,7 @@ private static ClientRegistration.Builder getBuilder(String issuer,
259262
if (!ex.getStatusCode().is4xxClientError()) {
260263
throw ex;
261264
}
265+
errors.add(ex.getMessage());
262266
// else try another endpoint
263267
}
264268
catch (IllegalArgumentException | IllegalStateException ex) {
@@ -268,6 +272,9 @@ private static ClientRegistration.Builder getBuilder(String issuer,
268272
throw new IllegalArgumentException(errorMessage, ex);
269273
}
270274
}
275+
if (!errors.isEmpty()) {
276+
throw new IllegalArgumentException(errorMessage + ", errors: " + errors);
277+
}
271278
throw new IllegalArgumentException(errorMessage);
272279
}
273280

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/registration/ClientRegistrationsTests.java

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -36,12 +36,14 @@
3636
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
3737

3838
import static org.assertj.core.api.Assertions.assertThat;
39+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3940
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
4041
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
4142

4243
/**
4344
* @author Rob Winch
4445
* @author Rafiullah Hamedy
46+
* @author Evgeniy Cheban
4547
* @since 5.1
4648
*/
4749
public class ClientRegistrationsTests {
@@ -569,6 +571,33 @@ public void issuerWhenOidcConfigurationTlsClientAuthMethodThenSuccess() throws E
569571
.isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
570572
}
571573

574+
@Test
575+
public void issuerWhenAllEndpointsFailedThenExceptionIncludesFailureInformation() {
576+
this.issuer = createIssuerFromServer("issuer1");
577+
this.server.setDispatcher(new Dispatcher() {
578+
@Override
579+
public MockResponse dispatch(RecordedRequest request) {
580+
int responseCode = switch (request.getPath()) {
581+
case "/issuer1/.well-known/openid-configuration" -> 405;
582+
case "/.well-known/openid-configuration/issuer1" -> 400;
583+
default -> 404;
584+
};
585+
return new MockResponse().setResponseCode(responseCode);
586+
}
587+
});
588+
String message = """
589+
Unable to resolve Configuration with the provided Issuer of "%s", errors: [\
590+
405 Client Error on GET request for "%s": [no body], \
591+
400 Client Error on GET request for "%s": [no body], \
592+
404 Client Error on GET request for "%s": [no body]]\
593+
""".formatted(this.issuer, this.server.url("/issuer1/.well-known/openid-configuration"),
594+
this.server.url("/.well-known/openid-configuration/issuer1"),
595+
this.server.url("/.well-known/oauth-authorization-server/issuer1"));
596+
assertThatExceptionOfType(IllegalArgumentException.class)
597+
.isThrownBy(() -> ClientRegistrations.fromIssuerLocation(this.issuer).build())
598+
.withMessage(message);
599+
}
600+
572601
private ClientRegistration.Builder registration(String path) throws Exception {
573602
this.issuer = createIssuerFromServer(path);
574603
this.response.put("issuer", this.issuer);

0 commit comments

Comments
 (0)