From d993580ab39732bbf057cd7a1077482bf1ce5ec7 Mon Sep 17 00:00:00 2001 From: "DESKTOP-E7L6HLO\\Noyan" Date: Thu, 18 Jul 2024 14:29:05 +0300 Subject: [PATCH] Task 42 : Define validate token for UserServiceClient with its controller in user service --- .../productservice/client/UserServiceClient.java | 5 +++++ .../userservice/controller/UserController.java | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/productservice/src/main/java/com/springbootmicroservices/productservice/client/UserServiceClient.java b/productservice/src/main/java/com/springbootmicroservices/productservice/client/UserServiceClient.java index 4adb057..bce85b8 100644 --- a/productservice/src/main/java/com/springbootmicroservices/productservice/client/UserServiceClient.java +++ b/productservice/src/main/java/com/springbootmicroservices/productservice/client/UserServiceClient.java @@ -1,6 +1,8 @@ package com.springbootmicroservices.productservice.client; import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -10,4 +12,7 @@ public interface UserServiceClient { @PostMapping("/validate-token") void validateToken(@RequestParam String token); + @GetMapping("/authenticate") + UsernamePasswordAuthenticationToken getAuthentication(@RequestParam String token); + } diff --git a/userservice/src/main/java/com/springbootmicroservices/userservice/controller/UserController.java b/userservice/src/main/java/com/springbootmicroservices/userservice/controller/UserController.java index 93cf166..c6c1324 100644 --- a/userservice/src/main/java/com/springbootmicroservices/userservice/controller/UserController.java +++ b/userservice/src/main/java/com/springbootmicroservices/userservice/controller/UserController.java @@ -13,6 +13,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -71,4 +72,10 @@ public CustomResponse logout(@RequestBody @Valid final TokenInvalidateRequ return CustomResponse.SUCCESS; } + @GetMapping("/authenticate") + public ResponseEntity getAuthentication(@RequestParam String token) { + UsernamePasswordAuthenticationToken authentication = tokenService.getAuthentication(token); + return ResponseEntity.ok(authentication); + } + }