-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/docker/maven-3.9.8-amazoncorretto-21
- Loading branch information
Showing
18 changed files
with
273 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/com/alura/aluraflixapi/controller/dto/token/RefreshTokenVO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.alura.aluraflixapi.controller.dto.token; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record RefreshTokenVO(@NotBlank String refreshToken) { | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/alura/aluraflixapi/domain/token/RefreshToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.alura.aluraflixapi.domain.token; | ||
|
||
import com.alura.aluraflixapi.domain.user.User; | ||
import com.auth0.jwt.JWT; | ||
import lombok.*; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
import java.time.Instant; | ||
|
||
@Document | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@Builder | ||
public class RefreshToken { | ||
@Id | ||
private String id; | ||
private String token; | ||
private String userName; | ||
private Instant expiryDate; | ||
|
||
public static RefreshToken buildRefreshTokenEntity(User user, String accessToken) { | ||
return RefreshToken.builder() | ||
.userName(user.getUsername()) | ||
.token(accessToken) | ||
.expiryDate(JWT.decode(accessToken).getExpiresAtAsInstant()) | ||
.build(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ava/com/alura/aluraflixapi/infraestructure/exception/JwtRefreshTokenExpiredException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.alura.aluraflixapi.infraestructure.exception; | ||
|
||
public class JwtRefreshTokenExpiredException extends RuntimeException { | ||
public JwtRefreshTokenExpiredException(String message) { | ||
super(message); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/alura/aluraflixapi/infraestructure/repository/RefreshTokenRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.alura.aluraflixapi.infraestructure.repository; | ||
|
||
import com.alura.aluraflixapi.domain.token.RefreshToken; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
|
||
public interface RefreshTokenRepository extends MongoRepository<RefreshToken, String> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...ain/java/com/alura/aluraflixapi/infraestructure/security/JwtAuthenticationEntryPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.alura.aluraflixapi.infraestructure.security; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.web.AuthenticationEntryPoint; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerExceptionResolver; | ||
|
||
/** | ||
* This class handles unsuccessful JWT exceptions | ||
*/ | ||
@Slf4j | ||
@Component | ||
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { | ||
@Qualifier("handlerExceptionResolver") | ||
private final HandlerExceptionResolver resolver; | ||
|
||
public JwtAuthenticationEntryPoint(HandlerExceptionResolver handlerExceptionResolver) { | ||
this.resolver = handlerExceptionResolver; | ||
} | ||
|
||
@Override | ||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) { | ||
resolver.resolveException(request, response, null, authException); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.