-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add webClientToken interceptor
- Loading branch information
1 parent
b5520ff
commit 63e8e8d
Showing
6 changed files
with
50 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
...ava/fr/insee/publicenemy/api/configuration/rest/RestTemplateAddJsonHeaderInterceptor.java
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
src/main/java/fr/insee/publicenemy/api/configuration/rest/RestTemplateTokenInterceptor.java
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
src/main/java/fr/insee/publicenemy/api/configuration/rest/WebClientTokenInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package fr.insee.publicenemy.api.configuration.rest; | ||
|
||
import fr.insee.publicenemy.api.application.web.auth.AuthenticationHelper; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.web.reactive.function.client.ClientRequest; | ||
import org.springframework.web.reactive.function.client.ClientResponse; | ||
import org.springframework.web.reactive.function.client.ExchangeFilterFunction; | ||
import org.springframework.web.reactive.function.client.ExchangeFunction; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class WebClientTokenInterceptor implements ExchangeFilterFunction { | ||
|
||
private final AuthenticationHelper authenticationHelper; | ||
|
||
@Override | ||
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) { | ||
String jwt = authenticationHelper.getUserToken(); | ||
ClientRequest newRequest = ClientRequest.from(request) | ||
.headers(h -> h.setBearerAuth(jwt)) | ||
.build(); | ||
return next.exchange(newRequest); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters