diff --git a/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/NimbusOAuth2TokenIntrospectionClient.java b/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/NimbusOAuth2TokenIntrospectionClient.java index bbf81772a8..f7ad7ee3b8 100644 --- a/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/NimbusOAuth2TokenIntrospectionClient.java +++ b/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/NimbusOAuth2TokenIntrospectionClient.java @@ -74,7 +74,7 @@ public class NimbusOAuth2TokenIntrospectionClient implements OAuth2TokenIntrospe Assert.notNull(clientId, "clientId cannot be null"); Assert.notNull(clientSecret, "clientSecret cannot be null"); - this.requestEntityConverter = this.defaultRequestEntityConverter(introspectionUri); + this.requestEntityConverter = this.defaultRequestEntityConverter(URI.create(introspectionUri)); RestTemplate restTemplate = new RestTemplate(); restTemplate.getInterceptors().add(new BasicAuthenticationInterceptor(clientId, clientSecret)); this.restOperations = restTemplate; @@ -93,10 +93,30 @@ public class NimbusOAuth2TokenIntrospectionClient implements OAuth2TokenIntrospe Assert.notNull(introspectionUri, "introspectionUri cannot be null"); Assert.notNull(restOperations, "restOperations cannot be null"); - this.requestEntityConverter = this.defaultRequestEntityConverter(introspectionUri); + this.requestEntityConverter = this.defaultRequestEntityConverter(URI.create(introspectionUri)); this.restOperations = restOperations; } + private Converter> defaultRequestEntityConverter(URI introspectionUri) { + return token -> { + HttpHeaders headers = requestHeaders(); + MultiValueMap body = requestBody(token); + return new RequestEntity<>(body, headers, HttpMethod.POST, introspectionUri); + }; + } + + private HttpHeaders requestHeaders() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON_UTF8)); + return headers; + } + + private MultiValueMap requestBody(String token) { + MultiValueMap body = new LinkedMultiValueMap<>(); + body.add("token", token); + return body; + } + /** * {@inheritDoc} */ @@ -127,26 +147,6 @@ public class NimbusOAuth2TokenIntrospectionClient implements OAuth2TokenIntrospe this.requestEntityConverter = requestEntityConverter; } - private Converter> defaultRequestEntityConverter(String introspectionUri) { - return token -> { - HttpHeaders headers = requestHeaders(); - MultiValueMap body = requestBody(token); - return new RequestEntity<>(body, headers, HttpMethod.POST, URI.create(introspectionUri)); - }; - } - - private HttpHeaders requestHeaders() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON_UTF8)); - return headers; - } - - private MultiValueMap requestBody(String token) { - MultiValueMap body = new LinkedMultiValueMap<>(); - body.add("token", token); - return body; - } - private ResponseEntity makeRequest(RequestEntity requestEntity) { try { return this.restOperations.exchange(requestEntity, String.class);