|
@@ -100,6 +100,8 @@ public class JdbcRegisteredClientRepository implements RegisteredClientRepositor
|
|
|
+ " WHERE " + PK_FILTER;
|
|
|
// @formatter:on
|
|
|
|
|
|
+ private static final String COUNT_REGISTERED_CLIENT_SQL = "SELECT COUNT(*) FROM " + TABLE_NAME + " WHERE ";
|
|
|
+
|
|
|
private final JdbcOperations jdbcOperations;
|
|
|
private RowMapper<RegisteredClient> registeredClientRowMapper;
|
|
|
private Function<RegisteredClient, List<SqlParameterValue>> registeredClientParametersMapper;
|
|
@@ -141,11 +143,31 @@ public class JdbcRegisteredClientRepository implements RegisteredClientRepositor
|
|
|
}
|
|
|
|
|
|
private void insertRegisteredClient(RegisteredClient registeredClient) {
|
|
|
+ assertUniqueIdentifiers(registeredClient);
|
|
|
List<SqlParameterValue> parameters = this.registeredClientParametersMapper.apply(registeredClient);
|
|
|
PreparedStatementSetter pss = new ArgumentPreparedStatementSetter(parameters.toArray());
|
|
|
this.jdbcOperations.update(INSERT_REGISTERED_CLIENT_SQL, pss);
|
|
|
}
|
|
|
|
|
|
+ private void assertUniqueIdentifiers(RegisteredClient registeredClient) {
|
|
|
+ Integer count = this.jdbcOperations.queryForObject(
|
|
|
+ COUNT_REGISTERED_CLIENT_SQL + "client_id = ?",
|
|
|
+ Integer.class,
|
|
|
+ registeredClient.getClientId());
|
|
|
+ if (count != null && count > 0) {
|
|
|
+ throw new IllegalArgumentException("Registered client must be unique. " +
|
|
|
+ "Found duplicate client identifier: " + registeredClient.getClientId());
|
|
|
+ }
|
|
|
+ count = this.jdbcOperations.queryForObject(
|
|
|
+ COUNT_REGISTERED_CLIENT_SQL + "client_secret = ?",
|
|
|
+ Integer.class,
|
|
|
+ registeredClient.getClientSecret());
|
|
|
+ if (count != null && count > 0) {
|
|
|
+ throw new IllegalArgumentException("Registered client must be unique. " +
|
|
|
+ "Found duplicate client secret for identifier: " + registeredClient.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public RegisteredClient findById(String id) {
|
|
|
Assert.hasText(id, "id cannot be empty");
|