Skip to content

Commit e05f86f

Browse files
committed
Merge branch 0.4.x into main
The following commits are merged using the default merge strategy. 0e50933 Assert unique identifiers in JdbcRegisteredClientRepository 8b0e757 Upgrade to JUnit 5
2 parents 9b252d8 + 8b0e757 commit e05f86f

File tree

92 files changed

+444
-361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+444
-361
lines changed

buildSrc/src/main/java/org/springframework/gradle/SpringJavaPlugin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.gradle.api.plugins.PluginManager;
3030
import org.gradle.api.tasks.compile.CompileOptions;
3131
import org.gradle.api.tasks.compile.JavaCompile;
32+
import org.gradle.api.tasks.testing.Test;
3233
import org.gradle.jvm.tasks.Jar;
3334
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper;
3435

@@ -92,5 +93,8 @@ public void apply(Project project) {
9293
attributes.put("Automatic-Module-Name", project.getName().replace("-", "."));
9394
manifest.attributes(attributes);
9495
}));
96+
project.getTasks().withType(Test.class, (test) -> {
97+
test.useJUnitPlatform();
98+
});
9599
}
96100
}

dependencies/spring-authorization-server-dependencies.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies {
1313
constraints {
1414
api "com.nimbusds:nimbus-jose-jwt:9.24.4"
1515
api "jakarta.servlet:jakarta.servlet-api:5.0.0"
16-
api "junit:junit:4.13.2"
16+
api "org.junit.jupiter:junit-jupiter:5.9.1"
1717
api "org.assertj:assertj-core:3.23.1"
1818
api "org.mockito:mockito-core:4.8.1"
1919
api "com.squareup.okhttp3:mockwebserver:4.10.0"

oauth2-authorization-server/spring-security-oauth2-authorization-server.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies {
2121

2222
testImplementation "org.springframework.security:spring-security-test"
2323
testImplementation "org.springframework:spring-webmvc"
24-
testImplementation "junit:junit"
24+
testImplementation "org.junit.jupiter:junit-jupiter"
2525
testImplementation "org.assertj:assertj-core"
2626
testImplementation "org.mockito:mockito-core"
2727
testImplementation "com.jayway.jsonpath:json-path"

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ public class JdbcRegisteredClientRepository implements RegisteredClientRepositor
100100
+ " WHERE " + PK_FILTER;
101101
// @formatter:on
102102

103+
private static final String COUNT_REGISTERED_CLIENT_SQL = "SELECT COUNT(*) FROM " + TABLE_NAME + " WHERE ";
104+
103105
private final JdbcOperations jdbcOperations;
104106
private RowMapper<RegisteredClient> registeredClientRowMapper;
105107
private Function<RegisteredClient, List<SqlParameterValue>> registeredClientParametersMapper;
@@ -141,11 +143,31 @@ private void updateRegisteredClient(RegisteredClient registeredClient) {
141143
}
142144

143145
private void insertRegisteredClient(RegisteredClient registeredClient) {
146+
assertUniqueIdentifiers(registeredClient);
144147
List<SqlParameterValue> parameters = this.registeredClientParametersMapper.apply(registeredClient);
145148
PreparedStatementSetter pss = new ArgumentPreparedStatementSetter(parameters.toArray());
146149
this.jdbcOperations.update(INSERT_REGISTERED_CLIENT_SQL, pss);
147150
}
148151

152+
private void assertUniqueIdentifiers(RegisteredClient registeredClient) {
153+
Integer count = this.jdbcOperations.queryForObject(
154+
COUNT_REGISTERED_CLIENT_SQL + "client_id = ?",
155+
Integer.class,
156+
registeredClient.getClientId());
157+
if (count != null && count > 0) {
158+
throw new IllegalArgumentException("Registered client must be unique. " +
159+
"Found duplicate client identifier: " + registeredClient.getClientId());
160+
}
161+
count = this.jdbcOperations.queryForObject(
162+
COUNT_REGISTERED_CLIENT_SQL + "client_secret = ?",
163+
Integer.class,
164+
registeredClient.getClientSecret());
165+
if (count != null && count > 0) {
166+
throw new IllegalArgumentException("Registered client must be unique. " +
167+
"Found duplicate client secret for identifier: " + registeredClient.getId());
168+
}
169+
}
170+
149171
@Override
150172
public RegisteredClient findById(String id) {
151173
Assert.hasText(id, "id cannot be empty");

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2021 the original author or authors.
2+
* Copyright 2020-2022 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,8 +17,8 @@
1717

1818
import java.util.List;
1919

20-
import org.junit.Before;
21-
import org.junit.Test;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.Test;
2222

2323
import org.springframework.security.core.authority.SimpleGrantedAuthority;
2424

@@ -40,7 +40,7 @@ public class InMemoryOAuth2AuthorizationConsentServiceTests {
4040

4141
private InMemoryOAuth2AuthorizationConsentService authorizationConsentService;
4242

43-
@Before
43+
@BeforeEach
4444
public void setUp() {
4545
this.authorizationConsentService = new InMemoryOAuth2AuthorizationConsentService();
4646
this.authorizationConsentService.save(AUTHORIZATION_CONSENT);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import java.time.temporal.ChronoUnit;
2020
import java.util.List;
2121

22-
import org.junit.Before;
23-
import org.junit.Test;
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
2424

2525
import org.springframework.security.oauth2.core.AuthorizationGrantType;
2626
import org.springframework.security.oauth2.core.OAuth2AccessToken;
@@ -49,7 +49,7 @@ public class InMemoryOAuth2AuthorizationServiceTests {
4949
private static final OAuth2TokenType STATE_TOKEN_TYPE = new OAuth2TokenType(OAuth2ParameterNames.STATE);
5050
private InMemoryOAuth2AuthorizationService authorizationService;
5151

52-
@Before
52+
@BeforeEach
5353
public void setup() {
5454
this.authorizationService = new InMemoryOAuth2AuthorizationService();
5555
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2021 the original author or authors.
2+
* Copyright 2020-2022 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.
@@ -20,9 +20,9 @@
2020
import java.sql.Types;
2121
import java.util.List;
2222

23-
import org.junit.After;
24-
import org.junit.Before;
25-
import org.junit.Test;
23+
import org.junit.jupiter.api.AfterEach;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
2626

2727
import org.springframework.dao.DataRetrievalFailureException;
2828
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
@@ -75,15 +75,15 @@ public class JdbcOAuth2AuthorizationConsentServiceTests {
7575
private RegisteredClientRepository registeredClientRepository;
7676
private JdbcOAuth2AuthorizationConsentService authorizationConsentService;
7777

78-
@Before
78+
@BeforeEach
7979
public void setUp() {
8080
this.db = createDb();
8181
this.jdbcOperations = new JdbcTemplate(this.db);
8282
this.registeredClientRepository = mock(RegisteredClientRepository.class);
8383
this.authorizationConsentService = new JdbcOAuth2AuthorizationConsentService(this.jdbcOperations, this.registeredClientRepository);
8484
}
8585

86-
@After
86+
@AfterEach
8787
public void tearDown() {
8888
this.db.shutdown();
8989
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
import java.util.function.Function;
3030

3131
import com.fasterxml.jackson.core.type.TypeReference;
32-
import org.junit.After;
33-
import org.junit.Before;
34-
import org.junit.Test;
32+
import org.junit.jupiter.api.AfterEach;
33+
import org.junit.jupiter.api.BeforeEach;
34+
import org.junit.jupiter.api.Test;
3535

3636
import org.springframework.dao.DataRetrievalFailureException;
3737
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
@@ -88,15 +88,15 @@ public class JdbcOAuth2AuthorizationServiceTests {
8888
private RegisteredClientRepository registeredClientRepository;
8989
private JdbcOAuth2AuthorizationService authorizationService;
9090

91-
@Before
91+
@BeforeEach
9292
public void setUp() {
9393
this.db = createDb();
9494
this.jdbcOperations = new JdbcTemplate(this.db);
9595
this.registeredClientRepository = mock(RegisteredClientRepository.class);
9696
this.authorizationService = new JdbcOAuth2AuthorizationService(this.jdbcOperations, this.registeredClientRepository);
9797
}
9898

99-
@After
99+
@AfterEach
100100
public void tearDown() {
101101
this.db.shutdown();
102102
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2021 the original author or authors.
2+
* Copyright 2020-2022 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.
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.security.oauth2.server.authorization;
1717

18-
import org.junit.Test;
18+
import org.junit.jupiter.api.Test;
1919

2020
import org.springframework.security.core.authority.SimpleGrantedAuthority;
2121

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.HashMap;
2222
import java.util.List;
2323

24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525

2626
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
2727
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationServerMetadata.Builder;

0 commit comments

Comments
 (0)