Initial commit.
This commit is contained in:
30
codiki-domain/pom.xml
Normal file
30
codiki-domain/pom.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codiki</groupId>
|
||||
<artifactId>codiki-parent</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<artifactId>codiki-domain</artifactId>
|
||||
|
||||
<name>codiki-domain</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
</project>
|
||||
@@ -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