From 4df9db4ae8f98ab44c805167b3e91c3f515763e5 Mon Sep 17 00:00:00 2001 From: rayankonecny Date: Thu, 18 Dec 2025 01:56:26 +0000 Subject: [PATCH] Fix commons lib --- auth-service-api/build.gradle | 4 ++++ .../configs/SecurityConfig.java | 2 +- .../controllers/AuthController.java | 7 +++--- .../controllers/impl/AuthControllerImpl.java | 4 +--- .../authserviceapi/models/RefreshToken.java | 22 ++++++++++++------- .../services/RefreshTokenService.java | 7 +++--- .../models/requests/RefreshTokenRequest.java | 2 +- rest.http | 4 ++-- 8 files changed, 30 insertions(+), 22 deletions(-) diff --git a/auth-service-api/build.gradle b/auth-service-api/build.gradle index c764dd0..96d4c93 100644 --- a/auth-service-api/build.gradle +++ b/auth-service-api/build.gradle @@ -39,4 +39,8 @@ tasks.named('test') { tasks.withType(org.springframework.boot.gradle.tasks.aot.ProcessAot).configureEach { enabled = false +} + +tasks.withType(JavaCompile).configureEach { + options.compilerArgs += "-parameters" } \ No newline at end of file diff --git a/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/configs/SecurityConfig.java b/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/configs/SecurityConfig.java index aec922b..e5cc4ae 100644 --- a/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/configs/SecurityConfig.java +++ b/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/configs/SecurityConfig.java @@ -14,7 +14,7 @@ public class SecurityConfig { public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http.authorizeHttpRequests(auth -> auth.requestMatchers("/auth/login", "/v3/api-docs/**", "/swagger-ui/**", - "/swagger-ui.html", "/swagger-ui/index.html").permitAll().anyRequest().authenticated()) + "/swagger-ui.html","/auth/refreshtoken", "/swagger-ui/index.html").permitAll().anyRequest().authenticated()) // API pura → sem Basic .httpBasic(httpBasic -> httpBasic.disable()) diff --git a/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/controllers/AuthController.java b/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/controllers/AuthController.java index 2c01aed..f4715b1 100644 --- a/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/controllers/AuthController.java +++ b/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/controllers/AuthController.java @@ -29,7 +29,8 @@ public interface AuthController { @ApiResponse(responseCode = "400", description = "Bad request", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = StandardError.class))), @ApiResponse(responseCode = "401", description = "Bad credentials", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = StandardError.class))), @ApiResponse(responseCode = "404", description = "Username not found", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = StandardError.class))), - @ApiResponse(responseCode = "500", description = "Internal server error", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = StandardError.class))), }) + @ApiResponse(responseCode = "500", description = "Internal server error", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = StandardError.class))), + }) @PostMapping("/login") ResponseEntity authenticate(@RequestBody @Valid @@ -43,8 +44,6 @@ public interface AuthController { @ApiResponse(responseCode = "404", description = "Username not found", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = StandardError.class))), @ApiResponse(responseCode = "500", description = "Internal server error", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = StandardError.class))) }) @PostMapping("/refreshtoken") - ResponseEntity refreshToken(@Valid - @RequestBody - final RefreshTokenRequest refreshToken) throws Exception; + ResponseEntity refreshToken(@RequestBody @Valid final RefreshTokenRequest refreshToken) throws Exception; } diff --git a/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/controllers/impl/AuthControllerImpl.java b/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/controllers/impl/AuthControllerImpl.java index 8fa2b3e..fea9e64 100644 --- a/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/controllers/impl/AuthControllerImpl.java +++ b/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/controllers/impl/AuthControllerImpl.java @@ -4,7 +4,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; import br.com.rayankonecny.authserviceapi.controllers.AuthController; -import br.com.rayankonecny.authserviceapi.models.RefreshToken; import br.com.rayankonecny.authserviceapi.services.AuthService; import br.com.rayankonecny.authserviceapi.services.RefreshTokenService; import br.com.rayankonecny.hdcommoslib.models.requests.AuthenticateRequest; @@ -29,8 +28,7 @@ public class AuthControllerImpl implements AuthController { } @Override - public ResponseEntity refreshToken(@Valid - RefreshTokenRequest request) throws Exception { + public ResponseEntity refreshToken(@Valid RefreshTokenRequest request) throws Exception { return ResponseEntity.ok().body(refreshService.refreshToken(request.refreshToken())); } diff --git a/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/models/RefreshToken.java b/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/models/RefreshToken.java index 07896ad..786c31c 100644 --- a/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/models/RefreshToken.java +++ b/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/models/RefreshToken.java @@ -5,18 +5,24 @@ import java.time.LocalDateTime; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; -import lombok.Builder; +import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; + -@Builder -@Getter @Document +@Getter +@AllArgsConstructor +@NoArgsConstructor(force = true) public class RefreshToken { - @Id - private String id; - private String username; - private LocalDateTime createdAt; - private LocalDateTime expiresAt; + @Id + private String id; + private String username; + + private LocalDateTime createdAt; + + private LocalDateTime expiresAt; } + diff --git a/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/services/RefreshTokenService.java b/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/services/RefreshTokenService.java index 4450c8a..0fb0579 100644 --- a/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/services/RefreshTokenService.java +++ b/auth-service-api/src/main/java/br/com/rayankonecny/authserviceapi/services/RefreshTokenService.java @@ -15,6 +15,7 @@ import lombok.RequiredArgsConstructor; import static java.time.LocalDateTime.now; +import java.time.ZoneOffset; import java.util.UUID; @Service @@ -29,9 +30,9 @@ public class RefreshTokenService { private final JWTUtils jwtUtils; public RefreshToken save(final String username) { - return repository.save(RefreshToken.builder().id(UUID.randomUUID().toString()) - .expiresAt(now().plusSeconds(refreshTokenExpirationSec)).username(username).build()); - } + return repository.save(new RefreshToken(UUID.randomUUID().toString(), username, now(ZoneOffset.UTC), + now(ZoneOffset.UTC).plusSeconds(refreshTokenExpirationSec))); + }; public RefreshTokenResponse refreshToken(final String refreshTokenId) { final var refreshToken = repository.findById(refreshTokenId) diff --git a/hd-commons-lib/src/main/java/br/com/rayankonecny/hdcommoslib/models/requests/RefreshTokenRequest.java b/hd-commons-lib/src/main/java/br/com/rayankonecny/hdcommoslib/models/requests/RefreshTokenRequest.java index 8a17198..6ee23ee 100644 --- a/hd-commons-lib/src/main/java/br/com/rayankonecny/hdcommoslib/models/requests/RefreshTokenRequest.java +++ b/hd-commons-lib/src/main/java/br/com/rayankonecny/hdcommoslib/models/requests/RefreshTokenRequest.java @@ -4,7 +4,7 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; public record RefreshTokenRequest( - @Size(min = 16, max = 30, message = "Refresh token must be between 16 and 30 characters") + @Size(min = 16, max = 1024, message = "Refresh token must be between 16 and 30 characters") @NotBlank(message = "Refresh token is required") String refreshToken ) { diff --git a/rest.http b/rest.http index 4b0f688..4c07543 100644 --- a/rest.http +++ b/rest.http @@ -47,11 +47,11 @@ Accept: application/json } -POST http://175.15.15.91:8080/auth/refresh-token +POST http://175.15.15.91:8080/auth/refreshtoken Content-Type: application/json Accept: application/json # Authorization: Bearer {{token}} { - "refreshToken": "73b32ec3-9933-4a60-ae06-b23c965dd1b2" + "refreshToken": "8e7d2ada-7fcd-4b0d-92f0-55b5d8e6fc87" } \ No newline at end of file