diff --git a/pom.xml b/pom.xml index 65d0c8a..9fdbd43 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.3.4 + 3.4.0 @@ -18,7 +18,7 @@ 21 - 1.5.5.Final + 1.6.2 3.13.0 2.5.0 4.4.0 diff --git a/src/main/java/com/alura/aluraflixapi/controller/authentication/AuthenticationControllerAdvice.java b/src/main/java/com/alura/aluraflixapi/controller/authentication/AuthenticationControllerAdvice.java index d752dd9..fb748f6 100644 --- a/src/main/java/com/alura/aluraflixapi/controller/authentication/AuthenticationControllerAdvice.java +++ b/src/main/java/com/alura/aluraflixapi/controller/authentication/AuthenticationControllerAdvice.java @@ -4,7 +4,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.authentication.BadCredentialsException; -import org.springframework.security.authentication.InsufficientAuthenticationException; +import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @@ -19,13 +19,11 @@ public ResponseEntity handlerAuthenticationException(UsernameNot @ExceptionHandler(BadCredentialsException.class) public ResponseEntity handleBadCredentialsException(BadCredentialsException ex) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorMessageVO("Invalid username " + - "or password", HttpStatus.BAD_REQUEST)); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorMessageVO("Invalid username or password", HttpStatus.BAD_REQUEST)); } - @ExceptionHandler(InsufficientAuthenticationException.class) - public ResponseEntity handleInvalidTokenException(InsufficientAuthenticationException ex) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorMessageVO("Invalid token, " + - "please verify expiration", HttpStatus.BAD_REQUEST)); + @ExceptionHandler(AuthenticationException.class) + public ResponseEntity handleInvalidTokenException(AuthenticationException ex) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorMessageVO("Invalid token, please verify expiration", HttpStatus.BAD_REQUEST)); } } diff --git a/src/main/java/com/alura/aluraflixapi/infraestructure/security/SecurityConfigurations.java b/src/main/java/com/alura/aluraflixapi/infraestructure/security/SecurityConfigurations.java index 31c8f1a..83cf4b7 100644 --- a/src/main/java/com/alura/aluraflixapi/infraestructure/security/SecurityConfigurations.java +++ b/src/main/java/com/alura/aluraflixapi/infraestructure/security/SecurityConfigurations.java @@ -47,7 +47,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { ) //tell to spring to use our filter SecurityFilter.class instead their .addFilterBefore(securityFilter, UsernamePasswordAuthenticationFilter.class) -// //tell to spring to use this filter to handle any exception about JWT exception + //tell to spring to use this filter to handle any exception about JWT exception .exceptionHandling(exceptionHandler -> exceptionHandler.authenticationEntryPoint(jwtAuthenticationEntryPoint)) .build(); diff --git a/src/main/java/com/alura/aluraflixapi/infraestructure/security/TokenService.java b/src/main/java/com/alura/aluraflixapi/infraestructure/security/TokenService.java index ab4711e..6c30a32 100644 --- a/src/main/java/com/alura/aluraflixapi/infraestructure/security/TokenService.java +++ b/src/main/java/com/alura/aluraflixapi/infraestructure/security/TokenService.java @@ -62,7 +62,7 @@ public String verifyTokenJWT(String tokenJWT) { public void isRefreshTokenExpired(String tokenJWT) { if (JWT.decode(tokenJWT).getExpiresAt().toInstant().compareTo(Instant.now()) < 0) { - throw new JwtRefreshTokenExpiredException("Refresh token expired, please login again"); + throw new RuntimeException("Refresh token expired, please login again"); } } diff --git a/src/test/java/com/alura/aluraflixapi/infraestructure/repository/VideoRepositoryTest.java b/src/test/java/com/alura/aluraflixapi/infraestructure/repository/VideoRepositoryTest.java index d1c7f17..523e9e3 100644 --- a/src/test/java/com/alura/aluraflixapi/infraestructure/repository/VideoRepositoryTest.java +++ b/src/test/java/com/alura/aluraflixapi/infraestructure/repository/VideoRepositoryTest.java @@ -26,7 +26,6 @@ class VideoRepositoryTest extends ParseJson { @AfterEach void after() { - //TODO: search another way to delete all data without call this methods. videoRepository.deleteAll(); categoryRepository.deleteAll(); } diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index 517acf5..4b622cf 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -8,4 +8,4 @@ spring: mongodb: database: alura-flix-test # always commit the uri like this: ${DATABASE_TEST} - uri: ${DATABASE_TEST:mongodb+srv://laurosilveira:283TlfZiOW4nNOnN@alura-flix-test.qixe2kd.mongodb.net/?retryWrites=true&w=majority&appName=alura-flix-test} \ No newline at end of file + uri: ${DATABASE_TEST}