From 206c28704fa6a797a24300555558235c300312b1 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Thu, 12 Sep 2024 14:19:03 +0200 Subject: [PATCH] Put registration id in validation error message Closes gh-42278 --- .../security/oauth2/client/OAuth2ClientProperties.java | 7 ++++--- .../oauth2/client/OAuth2ClientPropertiesTests.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientProperties.java index 22effd124982..36fa40eeda44 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientProperties.java @@ -31,6 +31,7 @@ * @author Phillip Webb * @author Artsiom Yudovin * @author MyeongHyeon Lee + * @author Moritz Halbritter * @since 2.0.0 */ @ConfigurationProperties(prefix = "spring.security.oauth2.client") @@ -60,12 +61,12 @@ public void afterPropertiesSet() { } public void validate() { - getRegistration().values().forEach(this::validateRegistration); + getRegistration().forEach(this::validateRegistration); } - private void validateRegistration(Registration registration) { + private void validateRegistration(String id, Registration registration) { if (!StringUtils.hasText(registration.getClientId())) { - throw new IllegalStateException("Client id must not be empty."); + throw new IllegalStateException("Client id of registration '%s' must not be empty.".formatted(id)); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesTests.java index fd04c1b14fc3..7e12b24b18e8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesTests.java @@ -37,7 +37,7 @@ void clientIdAbsentThrowsException() { registration.setProvider("google"); this.properties.getRegistration().put("foo", registration); assertThatIllegalStateException().isThrownBy(this.properties::validate) - .withMessageContaining("Client id must not be empty."); + .withMessageContaining("Client id of registration 'foo' must not be empty."); } @Test