Skip to content

Commit e8b9a35

Browse files
daniel-shuyjzheaux
authored andcommitted
Fix Bearer Token RestTemplate Support example
1 parent 82e5f62 commit e8b9a35

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

docs/modules/ROOT/pages/servlet/oauth2/resource-server/bearer-tokens.adoc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,15 @@ fun rest(): RestTemplate {
241241
val rest = RestTemplate()
242242
rest.interceptors.add(ClientHttpRequestInterceptor { request, body, execution ->
243243
val authentication: Authentication? = SecurityContextHolder.getContext().authentication
244-
if (authentication != null) {
245-
execution.execute(request, body)
244+
if (authentication == null) {
245+
return execution.execute(request, body)
246246
}
247247
248-
if (authentication!!.credentials !is AbstractOAuth2Token) {
249-
execution.execute(request, body)
248+
if (authentication.credentials !is AbstractOAuth2Token) {
249+
return execution.execute(request, body)
250250
}
251251
252-
val token: AbstractOAuth2Token = authentication.credentials as AbstractOAuth2Token
253-
request.headers.setBearerAuth(token.tokenValue)
252+
request.headers.setBearerAuth(authentication.credentials.tokenValue)
254253
execution.execute(request, body)
255254
})
256255
return rest

0 commit comments

Comments
 (0)