|
|
@@ -5,8 +5,6 @@ import com.danielbohry.authservice.api.dto.AuthenticationResponse;
|
|
|
import com.danielbohry.authservice.domain.ApplicationUser;
|
|
|
import com.danielbohry.authservice.service.auth.AuthService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
|
import org.springframework.security.core.context.SecurityContext;
|
|
|
@@ -14,6 +12,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import static org.springframework.http.HttpStatus.CREATED;
|
|
|
+import static org.springframework.http.HttpStatus.FORBIDDEN;
|
|
|
|
|
|
@RestController
|
|
|
@AllArgsConstructor
|
|
|
@@ -45,7 +44,21 @@ public class AuthController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
|
+ return ResponseEntity.status(FORBIDDEN).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("refresh")
|
|
|
+ public ResponseEntity<Object> refresh() {
|
|
|
+ SecurityContext context = SecurityContextHolder.getContext();
|
|
|
+ Object principal = context.getAuthentication().getPrincipal();
|
|
|
+ if (principal instanceof ApplicationUser user) {
|
|
|
+ AuthenticationResponse response = service.refresh(user);
|
|
|
+ return response != null
|
|
|
+ ? ResponseEntity.ok(response)
|
|
|
+ : ResponseEntity.status(FORBIDDEN).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResponseEntity.status(FORBIDDEN).build();
|
|
|
}
|
|
|
|
|
|
@PostMapping("forgot-password")
|