Fix commons lib
This commit is contained in:
parent
ec150cd642
commit
4df9db4ae8
8 changed files with 30 additions and 22 deletions
|
|
@ -40,3 +40,7 @@ tasks.named('test') {
|
||||||
tasks.withType(org.springframework.boot.gradle.tasks.aot.ProcessAot).configureEach {
|
tasks.withType(org.springframework.boot.gradle.tasks.aot.ProcessAot).configureEach {
|
||||||
enabled = false
|
enabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
options.compilerArgs += "-parameters"
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,7 @@ public class SecurityConfig {
|
||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
|
|
||||||
http.authorizeHttpRequests(auth -> auth.requestMatchers("/auth/login", "/v3/api-docs/**", "/swagger-ui/**",
|
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
|
// API pura → sem Basic
|
||||||
.httpBasic(httpBasic -> httpBasic.disable())
|
.httpBasic(httpBasic -> httpBasic.disable())
|
||||||
|
|
|
||||||
|
|
@ -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 = "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 = "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 = "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")
|
@PostMapping("/login")
|
||||||
ResponseEntity<AuthenticationResponse> authenticate(@RequestBody
|
ResponseEntity<AuthenticationResponse> authenticate(@RequestBody
|
||||||
@Valid
|
@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 = "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("/refreshtoken")
|
@PostMapping("/refreshtoken")
|
||||||
ResponseEntity<RefreshTokenResponse> refreshToken(@Valid
|
ResponseEntity<RefreshTokenResponse> refreshToken(@RequestBody @Valid final RefreshTokenRequest refreshToken) throws Exception;
|
||||||
@RequestBody
|
|
||||||
final RefreshTokenRequest refreshToken) throws Exception;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import br.com.rayankonecny.authserviceapi.controllers.AuthController;
|
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.AuthService;
|
||||||
import br.com.rayankonecny.authserviceapi.services.RefreshTokenService;
|
import br.com.rayankonecny.authserviceapi.services.RefreshTokenService;
|
||||||
import br.com.rayankonecny.hdcommoslib.models.requests.AuthenticateRequest;
|
import br.com.rayankonecny.hdcommoslib.models.requests.AuthenticateRequest;
|
||||||
|
|
@ -29,8 +28,7 @@ public class AuthControllerImpl implements AuthController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<RefreshTokenResponse> refreshToken(@Valid
|
public ResponseEntity<RefreshTokenResponse> refreshToken(@Valid RefreshTokenRequest request) throws Exception {
|
||||||
RefreshTokenRequest request) throws Exception {
|
|
||||||
return ResponseEntity.ok().body(refreshService.refreshToken(request.refreshToken()));
|
return ResponseEntity.ok().body(refreshService.refreshToken(request.refreshToken()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,24 @@ import java.time.LocalDateTime;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
import lombok.Builder;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
|
||||||
@Builder
|
|
||||||
@Getter
|
|
||||||
@Document
|
@Document
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor(force = true)
|
||||||
public class RefreshToken {
|
public class RefreshToken {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
private String id;
|
private String id;
|
||||||
private String username;
|
|
||||||
private LocalDateTime createdAt;
|
|
||||||
private LocalDateTime expiresAt;
|
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
private LocalDateTime expiresAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
import static java.time.LocalDateTime.now;
|
import static java.time.LocalDateTime.now;
|
||||||
|
|
||||||
|
import java.time.ZoneOffset;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|
@ -29,9 +30,9 @@ public class RefreshTokenService {
|
||||||
private final JWTUtils jwtUtils;
|
private final JWTUtils jwtUtils;
|
||||||
|
|
||||||
public RefreshToken save(final String username) {
|
public RefreshToken save(final String username) {
|
||||||
return repository.save(RefreshToken.builder().id(UUID.randomUUID().toString())
|
return repository.save(new RefreshToken(UUID.randomUUID().toString(), username, now(ZoneOffset.UTC),
|
||||||
.expiresAt(now().plusSeconds(refreshTokenExpirationSec)).username(username).build());
|
now(ZoneOffset.UTC).plusSeconds(refreshTokenExpirationSec)));
|
||||||
}
|
};
|
||||||
|
|
||||||
public RefreshTokenResponse refreshToken(final String refreshTokenId) {
|
public RefreshTokenResponse refreshToken(final String refreshTokenId) {
|
||||||
final var refreshToken = repository.findById(refreshTokenId)
|
final var refreshToken = repository.findById(refreshTokenId)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
|
||||||
public record RefreshTokenRequest(
|
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")
|
@NotBlank(message = "Refresh token is required")
|
||||||
String refreshToken
|
String refreshToken
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -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
|
Content-Type: application/json
|
||||||
Accept: application/json
|
Accept: application/json
|
||||||
# Authorization: Bearer {{token}}
|
# Authorization: Bearer {{token}}
|
||||||
|
|
||||||
{
|
{
|
||||||
"refreshToken": "73b32ec3-9933-4a60-ae06-b23c965dd1b2"
|
"refreshToken": "8e7d2ada-7fcd-4b0d-92f0-55b5d8e6fc87"
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue