Initial commit.
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package org.codiki.domain.exception;
|
||||
|
||||
public abstract class FunctionnalException extends RuntimeException {
|
||||
public FunctionnalException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.codiki.domain.exception;
|
||||
|
||||
public class LoginFailureException extends FunctionnalException {
|
||||
public LoginFailureException() {
|
||||
super("Login or password incorrect.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.codiki.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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.codiki.domain.exception;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class RefreshTokenExpiredException extends FunctionnalException {
|
||||
public RefreshTokenExpiredException(UUID refreshTokenValue) {
|
||||
super(String.format("Refresh token \"%s\" is expired.", refreshTokenValue));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.codiki.domain.exception;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class UserDoesNotExistException extends FunctionnalException {
|
||||
public UserDoesNotExistException(UUID userId) {
|
||||
super(String.format("User \"%s\" does not exist.", userId));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.codiki.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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.codiki.domain.user.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public record User(
|
||||
UUID id,
|
||||
String password,
|
||||
List<UserRole> roles
|
||||
) {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.codiki.domain.user.model;
|
||||
|
||||
public record UserAuthenticationData(
|
||||
String tokenType,
|
||||
String accessToken,
|
||||
RefreshToken refreshToken
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package org.codiki.domain.user.model;
|
||||
|
||||
public enum UserRole {
|
||||
STANDARD,
|
||||
ADMIN
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.codiki.domain.user.port;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.codiki.domain.user.model.RefreshToken;
|
||||
import org.codiki.domain.user.model.User;
|
||||
|
||||
public interface UserPort {
|
||||
Optional<User> findById(UUID userId);
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user