Skip to content

Commit fe6ddd0

Browse files
committed
Merge branch '6.4.x'
2 parents d0a9791 + 656ad72 commit fe6ddd0

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

Lines changed: 8 additions & 1 deletion
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.LinkedHashMap;
2122
import java.util.List;
2223
import java.util.Map;
@@ -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 {
@@ -265,6 +267,7 @@ private static Supplier<ClientRegistration.Builder> getRfc8414Builder(String iss
265267
private static ClientRegistration.Builder getBuilder(String issuer,
266268
Supplier<ClientRegistration.Builder>... suppliers) {
267269
String errorMessage = "Unable to resolve Configuration with the provided Issuer of \"" + issuer + "\"";
270+
List<String> errors = new ArrayList<>();
268271
for (Supplier<ClientRegistration.Builder> supplier : suppliers) {
269272
try {
270273
return supplier.get();
@@ -273,6 +276,7 @@ private static ClientRegistration.Builder getBuilder(String issuer,
273276
if (!ex.getStatusCode().is4xxClientError()) {
274277
throw ex;
275278
}
279+
errors.add(ex.getMessage());
276280
// else try another endpoint
277281
}
278282
catch (IllegalArgumentException | IllegalStateException ex) {
@@ -282,6 +286,9 @@ private static ClientRegistration.Builder getBuilder(String issuer,
282286
throw new IllegalArgumentException(errorMessage, ex);
283287
}
284288
}
289+
if (!errors.isEmpty()) {
290+
throw new IllegalArgumentException(errorMessage + ", errors: " + errors);
291+
}
285292
throw new IllegalArgumentException(errorMessage);
286293
}
287294

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

Lines changed: 30 additions & 1 deletion
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.
@@ -37,12 +37,14 @@
3737
import org.springframework.web.util.UriComponents;
3838

3939
import static org.assertj.core.api.Assertions.assertThat;
40+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4041
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
4142
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
4243

4344
/**
4445
* @author Rob Winch
4546
* @author Rafiullah Hamedy
47+
* @author Evgeniy Cheban
4648
* @since 5.1
4749
*/
4850
public class ClientRegistrationsTests {
@@ -581,6 +583,33 @@ public void oidcWhenHostContainsUnderscoreThenRetains() {
581583
assertThat(oidcRfc8414.getHost()).isEqualTo("elated_sutherland");
582584
}
583585

586+
@Test
587+
public void issuerWhenAllEndpointsFailedThenExceptionIncludesFailureInformation() {
588+
this.issuer = createIssuerFromServer("issuer1");
589+
this.server.setDispatcher(new Dispatcher() {
590+
@Override
591+
public MockResponse dispatch(RecordedRequest request) {
592+
int responseCode = switch (request.getPath()) {
593+
case "/issuer1/.well-known/openid-configuration" -> 405;
594+
case "/.well-known/openid-configuration/issuer1" -> 400;
595+
default -> 404;
596+
};
597+
return new MockResponse().setResponseCode(responseCode);
598+
}
599+
});
600+
String message = """
601+
Unable to resolve Configuration with the provided Issuer of "%s", errors: [\
602+
405 Client Error on GET request for "%s": [no body], \
603+
400 Client Error on GET request for "%s": [no body], \
604+
404 Client Error on GET request for "%s": [no body]]\
605+
""".formatted(this.issuer, this.server.url("/issuer1/.well-known/openid-configuration"),
606+
this.server.url("/.well-known/openid-configuration/issuer1"),
607+
this.server.url("/.well-known/oauth-authorization-server/issuer1"));
608+
assertThatExceptionOfType(IllegalArgumentException.class)
609+
.isThrownBy(() -> ClientRegistrations.fromIssuerLocation(this.issuer).build())
610+
.withMessage(message);
611+
}
612+
584613
private ClientRegistration.Builder registration(String path) throws Exception {
585614
this.issuer = createIssuerFromServer(path);
586615
this.response.put("issuer", this.issuer);

0 commit comments

Comments
 (0)