Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into feature/add-refresh-token
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/com/alura/aluraflixapi/controller/authentication/AuthenticationControllerAdvice.java
#	src/main/java/com/alura/aluraflixapi/infraestructure/security/SecurityConfigurations.java
#	src/main/java/com/alura/aluraflixapi/infraestructure/security/TokenService.java
  • Loading branch information
LauroSilveira committed Nov 24, 2024
2 parents b62b1a7 + cd10597 commit a8f81f5
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.4</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand All @@ -18,7 +18,7 @@

<properties>
<java.version>21</java.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<mapstruct.version>1.6.2</mapstruct.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<springdoc.version>2.5.0</springdoc.version>
<jwt.version>4.4.0</jwt.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,13 +19,11 @@ public ResponseEntity<ErrorMessageVO> handlerAuthenticationException(UsernameNot

@ExceptionHandler(BadCredentialsException.class)
public ResponseEntity<ErrorMessageVO> 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<ErrorMessageVO> 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<ErrorMessageVO> handleInvalidTokenException(AuthenticationException ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ErrorMessageVO("Invalid token, please verify expiration", HttpStatus.BAD_REQUEST));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
uri: ${DATABASE_TEST}

0 comments on commit a8f81f5

Please sign in to comment.