Skip to content

Commit 9b14465

Browse files
committed
Align Assertions in Builder with Deprecated Constructor
The deprecated (introspectionUri, clientId, clientSecret) constructors that the builders replaced explicitly asserted non-null clientId and clientSecret. Bring the builder's build() in line with that contract by asserting at the API boundary rather than relying on downstream classes to enforce it. Closes gh-19201 Signed-off-by: Josh Cummings <3627351+jzheaux@users.noreply.github.com>
1 parent b075f0d commit 9b14465

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/SpringOpaqueTokenIntrospector.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ public Builder clientSecret(String clientSecret) {
361361
* @since 6.5
362362
*/
363363
public SpringOpaqueTokenIntrospector build() {
364+
Assert.notNull(this.clientId, "clientId cannot be null");
365+
Assert.notNull(this.clientSecret, "clientSecret cannot be null");
364366
RestTemplate restTemplate = new RestTemplate();
365367
restTemplate.getInterceptors().add(new BasicAuthenticationInterceptor(this.clientId, this.clientSecret));
366368
return new SpringOpaqueTokenIntrospector(this.introspectionUri, restTemplate);

oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/SpringReactiveOpaqueTokenIntrospector.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ public Builder clientSecret(String clientSecret) {
314314
* @since 6.5
315315
*/
316316
public SpringReactiveOpaqueTokenIntrospector build() {
317+
Assert.notNull(this.clientId, "clientId cannot be null");
318+
Assert.notNull(this.clientSecret, "clientSecret cannot be null");
317319
WebClient webClient = WebClient.builder()
318320
.defaultHeaders((h) -> h.setBasicAuth(this.clientId, this.clientSecret))
319321
.build();

oauth2/oauth2-resource-server/src/test/java/org/springframework/security/oauth2/server/resource/introspection/SpringOpaqueTokenIntrospectorTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ public void introspectWithEncodeClientCredentialsThenOk() throws Exception {
383383
}
384384
}
385385

386+
// gh-19201
387+
@Test
388+
public void builderWhenMissingClientCredentialsThenThrowsException() {
389+
assertThatExceptionOfType(IllegalArgumentException.class)
390+
.isThrownBy(() -> SpringOpaqueTokenIntrospector.withIntrospectionUri(INTROSPECTION_URL).build());
391+
}
392+
386393
private static ResponseEntity<Map<String, Object>> response(String content) {
387394
HttpHeaders headers = new HttpHeaders();
388395
headers.setContentType(MediaType.APPLICATION_JSON);

oauth2/oauth2-resource-server/src/test/java/org/springframework/security/oauth2/server/resource/introspection/SpringReactiveOpaqueTokenIntrospectorTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ public void introspectWithEncodeClientCredentialsThenOk() throws Exception {
308308
}
309309
}
310310

311+
// gh-19201
312+
@Test
313+
public void builderWhenMissingClientCredentialsThenThrowsException() {
314+
assertThatExceptionOfType(IllegalArgumentException.class)
315+
.isThrownBy(() -> SpringReactiveOpaqueTokenIntrospector.withIntrospectionUri(INTROSPECTION_URL).build());
316+
}
317+
311318
private WebClient mockResponse(String response) {
312319
return mockResponse(toMap(response));
313320
}

0 commit comments

Comments
 (0)