Skip to content

Commit 520fe25

Browse files
committed
Fix to allow multiple public client registrations
Closes spring-projectsgh-1641
1 parent 8797590 commit 520fe25

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/client/JdbcRegisteredClientRepository.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 the original author or authors.
2+
* Copyright 2020-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.
@@ -174,11 +174,13 @@ private void assertUniqueIdentifiers(RegisteredClient registeredClient) {
174174
throw new IllegalArgumentException("Registered client must be unique. "
175175
+ "Found duplicate client identifier: " + registeredClient.getClientId());
176176
}
177-
count = this.jdbcOperations.queryForObject(COUNT_REGISTERED_CLIENT_SQL + "client_secret = ?", Integer.class,
178-
registeredClient.getClientSecret());
179-
if (count != null && count > 0) {
180-
throw new IllegalArgumentException("Registered client must be unique. "
181-
+ "Found duplicate client secret for identifier: " + registeredClient.getId());
177+
if (StringUtils.hasText(registeredClient.getClientSecret())) {
178+
count = this.jdbcOperations.queryForObject(COUNT_REGISTERED_CLIENT_SQL + "client_secret = ?", Integer.class,
179+
registeredClient.getClientSecret());
180+
if (count != null && count > 0) {
181+
throw new IllegalArgumentException("Registered client must be unique. "
182+
+ "Found duplicate client secret for identifier: " + registeredClient.getId());
183+
}
182184
}
183185
}
184186

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/client/JdbcRegisteredClientRepositoryTests.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 the original author or authors.
2+
* Copyright 2020-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.
@@ -168,6 +168,23 @@ public void saveWhenClientSecretNullThenSaved() {
168168
assertThat(registeredClient).isEqualTo(expectedRegisteredClient);
169169
}
170170

171+
// gh-1641
172+
@Test
173+
public void saveWhenMultipleWithClientSecretEmptyThenSaved() {
174+
RegisteredClient registeredClient1 = TestRegisteredClients.registeredClient()
175+
.id("registration-1")
176+
.clientId("client-1")
177+
.clientSecret("")
178+
.build();
179+
this.registeredClientRepository.save(registeredClient1);
180+
RegisteredClient registeredClient2 = TestRegisteredClients.registeredClient()
181+
.id("registration-2")
182+
.clientId("client-2")
183+
.clientSecret("")
184+
.build();
185+
this.registeredClientRepository.save(registeredClient2);
186+
}
187+
171188
@Test
172189
public void saveWhenExistingClientIdThenThrowIllegalArgumentException() {
173190
RegisteredClient registeredClient1 = TestRegisteredClients.registeredClient()

0 commit comments

Comments
 (0)