Implementation of refresh token.

This commit is contained in:
Florian THIERRY
2023-12-01 11:37:04 +01:00
parent 4a7b0b2daf
commit 367676f6d8
22 changed files with 305 additions and 93 deletions

View File

@@ -0,0 +1,9 @@
package org.sportshub.domain.exception;
import java.util.UUID;
public class RefreshTokenDoesNotExistException extends FunctionnalException {
public RefreshTokenDoesNotExistException(UUID refreshTokenValue) {
super(String.format("Refresh token \"%s\" does not exist.", refreshTokenValue));
}
}

View File

@@ -0,0 +1,9 @@
package org.sportshub.domain.exception;
import java.util.UUID;
public class RefreshTokenExpiredException extends FunctionnalException {
public RefreshTokenExpiredException(UUID refreshTokenValue) {
super(String.format("Refresh token \"%s\" is expired.", refreshTokenValue));
}
}

View File

@@ -0,0 +1,9 @@
package org.sportshub.domain.exception;
import java.util.UUID;
public class UserDoesNotExistException extends FunctionnalException {
public UserDoesNotExistException(UUID userId) {
super(String.format("User \"%s\" does not exist.", userId));
}
}

View File

@@ -0,0 +1,22 @@
package org.sportshub.domain.user.model;
import java.time.ZonedDateTime;
import java.util.UUID;
public record RefreshToken(
UUID userId,
UUID value,
ZonedDateTime expirationDate
) {
public RefreshToken(UUID userId, ZonedDateTime exporationDate) {
this(userId, UUID.randomUUID(), exporationDate);
}
public boolean isExpired() {
return ZonedDateTime.now().isAfter(expirationDate);
}
public boolean isNotExpired() {
return !isExpired();
}
}

View File

@@ -0,0 +1,8 @@
package org.sportshub.domain.user.model;
public record UserAuthenticationData(
String tokenType,
String accessToken,
RefreshToken refreshToken
) {
}

View File

@@ -4,6 +4,7 @@ import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.sportshub.domain.user.model.RefreshToken;
import org.sportshub.domain.user.model.User;
public interface UserPort {
@@ -12,4 +13,12 @@ public interface UserPort {
List<User> findAll();
void save(User user);
boolean existsById(UUID userId);
Optional<RefreshToken> findRefreshTokenByUserId(UUID userId);
Optional<RefreshToken> findRefreshTokenById(UUID refreshTokenId);
void save(RefreshToken refreshToken);
}