Skip to content

Commit e8e4110

Browse files
committed
Wrap RuntimeException in fromOidcConfiguration
This commit makes so that fromOidcConfiguration throws the same exception caused by chain as other configuration methods. Specifically, if parsing throws a RuntimeException, this method will now wrap it in an IllegalArgumentException as other configuration methods do. This makes specific sense here since the RuntimeException is almost certainly caused by a malformed configuration set handed in as a method parameter. Signed-off-by: Josh Cummings <3627351+jzheaux@users.noreply.github.com>
1 parent 17e3684 commit e8e4110

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private ClientRegistrations() {
105105
* @return the {@link ClientRegistration} built from the configuration
106106
*/
107107
public static ClientRegistration.Builder fromOidcConfiguration(Map<String, Object> configuration) {
108-
OIDCProviderMetadata metadata = parse(configuration, OIDCProviderMetadata::parse);
108+
OIDCProviderMetadata metadata = parseInput(configuration, OIDCProviderMetadata::parse);
109109
ClientRegistration.Builder builder = withProviderConfiguration(metadata, metadata.getIssuer().getValue());
110110
builder.jwkSetUri(metadata.getJWKSetURI().toASCIIString());
111111
if (metadata.getUserInfoEndpointURI() != null) {
@@ -292,6 +292,15 @@ private static ClientRegistration.Builder getBuilder(String issuer,
292292
throw new IllegalArgumentException(errorMessage);
293293
}
294294

295+
private static <T> T parseInput(Map<String, Object> body, ThrowingFunction<JSONObject, T, ParseException> parser) {
296+
try {
297+
return parse(body, parser);
298+
}
299+
catch (RuntimeException ex) {
300+
throw new IllegalArgumentException(ex);
301+
}
302+
}
303+
295304
private static <T> T parse(Map<String, Object> body, ThrowingFunction<JSONObject, T, ParseException> parser) {
296305
try {
297306
return parser.apply(new JSONObject(body));

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4141
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
4242
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
43-
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
4443

4544
/**
4645
* @author Rob Winch
@@ -475,7 +474,7 @@ private ClientRegistration.Builder registration(Map<String, Object> configuratio
475474
@Test
476475
public void issuerWhenOidcConfigurationResponseMissingJwksUriThenThrowsIllegalArgumentException() throws Exception {
477476
this.response.remove("jwks_uri");
478-
assertThatNullPointerException().isThrownBy(() -> registration(this.response).build());
477+
assertThatIllegalArgumentException().isThrownBy(() -> registration(this.response).build());
479478
}
480479

481480
@Test

0 commit comments

Comments
 (0)