Skip to content

Commit 7c11ada

Browse files
committed
Merge branch '7.0.x'
2 parents aaaa9b9 + 944149b commit 7c11ada

4 files changed

Lines changed: 24 additions & 11 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,10 @@ public Builder postProcessor(Consumer<SpringOpaqueTokenIntrospector> postProcess
380380
* @since 6.5
381381
*/
382382
public SpringOpaqueTokenIntrospector build() {
383+
Assert.notNull(this.clientId, "clientId cannot be null");
384+
Assert.notNull(this.clientSecret, "clientSecret cannot be null");
383385
RestTemplate restTemplate = new RestTemplate();
384-
if (this.clientId != null && this.clientSecret != null) {
385-
restTemplate.getInterceptors()
386-
.add(new BasicAuthenticationInterceptor(this.clientId, this.clientSecret));
387-
}
386+
restTemplate.getInterceptors().add(new BasicAuthenticationInterceptor(this.clientId, this.clientSecret));
388387
SpringOpaqueTokenIntrospector introspector = new SpringOpaqueTokenIntrospector(this.introspectionUri,
389388
restTemplate);
390389
this.postProcessors.forEach((postProcessor) -> postProcessor.accept(introspector));

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,13 @@ public Builder postProcessor(Consumer<SpringReactiveOpaqueTokenIntrospector> pos
334334
* @since 6.5
335335
*/
336336
public SpringReactiveOpaqueTokenIntrospector build() {
337-
WebClient.Builder builder = WebClient.builder();
338-
if (this.clientId != null && this.clientSecret != null) {
339-
String clientId = this.clientId;
340-
String clientSecret = this.clientSecret;
341-
builder.defaultHeaders((h) -> h.setBasicAuth(clientId, clientSecret));
342-
}
343-
WebClient webClient = builder.build();
337+
Assert.notNull(this.clientId, "clientId cannot be null");
338+
Assert.notNull(this.clientSecret, "clientSecret cannot be null");
339+
String clientId = this.clientId;
340+
String clientSecret = this.clientSecret;
341+
WebClient webClient = WebClient.builder()
342+
.defaultHeaders((h) -> h.setBasicAuth(clientId, clientSecret))
343+
.build();
344344
SpringReactiveOpaqueTokenIntrospector introspector = new SpringReactiveOpaqueTokenIntrospector(
345345
this.introspectionUri, webClient);
346346
this.postProcessors.forEach((postProcessor) -> postProcessor.accept(introspector));

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
@@ -402,6 +402,13 @@ public void builderWhenPostProcessorSetThenApplied() throws Exception {
402402
}
403403
}
404404

405+
// gh-19201
406+
@Test
407+
public void builderWhenMissingClientCredentialsThenThrowsException() {
408+
assertThatExceptionOfType(IllegalArgumentException.class)
409+
.isThrownBy(() -> SpringOpaqueTokenIntrospector.withIntrospectionUri(INTROSPECTION_URL).build());
410+
}
411+
405412
private static ResponseEntity<Map<String, Object>> response(String content) {
406413
HttpHeaders headers = new HttpHeaders();
407414
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
@@ -328,6 +328,13 @@ public void builderWhenPostProcessorSetThenApplied() throws Exception {
328328
}
329329
}
330330

331+
// gh-19201
332+
@Test
333+
public void builderWhenMissingClientCredentialsThenThrowsException() {
334+
assertThatExceptionOfType(IllegalArgumentException.class)
335+
.isThrownBy(() -> SpringReactiveOpaqueTokenIntrospector.withIntrospectionUri(INTROSPECTION_URL).build());
336+
}
337+
331338
private WebClient mockResponse(String response) {
332339
return mockResponse(toMap(response));
333340
}

0 commit comments

Comments
 (0)