From e8b9a354945c62cd723287026e6e77b79eab76b6 Mon Sep 17 00:00:00 2001 From: Daniel Shuy Date: Wed, 28 Jun 2023 16:26:38 +0800 Subject: [PATCH] Fix Bearer Token RestTemplate Support example --- .../servlet/oauth2/resource-server/bearer-tokens.adoc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/modules/ROOT/pages/servlet/oauth2/resource-server/bearer-tokens.adoc b/docs/modules/ROOT/pages/servlet/oauth2/resource-server/bearer-tokens.adoc index c4b43a56c5..a805132c28 100644 --- a/docs/modules/ROOT/pages/servlet/oauth2/resource-server/bearer-tokens.adoc +++ b/docs/modules/ROOT/pages/servlet/oauth2/resource-server/bearer-tokens.adoc @@ -241,16 +241,15 @@ fun rest(): RestTemplate { val rest = RestTemplate() rest.interceptors.add(ClientHttpRequestInterceptor { request, body, execution -> val authentication: Authentication? = SecurityContextHolder.getContext().authentication - if (authentication != null) { - execution.execute(request, body) + if (authentication == null) { + return execution.execute(request, body) } - if (authentication!!.credentials !is AbstractOAuth2Token) { - execution.execute(request, body) + if (authentication.credentials !is AbstractOAuth2Token) { + return execution.execute(request, body) } - val token: AbstractOAuth2Token = authentication.credentials as AbstractOAuth2Token - request.headers.setBearerAuth(token.tokenValue) + request.headers.setBearerAuth(authentication.credentials.tokenValue) execution.execute(request, body) }) return rest