From bff7fe3c42cf93eb5679e841405d21243bf21c5b Mon Sep 17 00:00:00 2001 From: veltrup Date: Thu, 2 Nov 2023 10:36:34 +0100 Subject: [PATCH] refactor: add Exception suffix for exception classes --- .../core/domain/entity/Anchor.java | 8 ++++---- ...sDenied.java => AccessDeniedException.java} | 6 +++--- ...d.java => AccessTokenExpiredException.java} | 6 +++--- ...java => AccessTokenNotActiveException.java} | 6 +++--- ...d.java => AccessTokenRevokedException.java} | 6 +++--- ....java => AnchorAlreadyExistsException.java} | 6 +++--- ...Found.java => AnchorNotFoundException.java} | 6 +++--- ...java => AuthenticationFailedException.java} | 8 ++++---- .../domain/exception/InvalidAccessToken.java | 14 -------------- .../exception/InvalidAccessTokenException.java | 14 ++++++++++++++ ...Anchor.java => InvalidAnchorException.java} | 6 +++--- ...s.java => LoginAlreadyExistsException.java} | 6 +++--- ...otFound.java => UserNotFoundException.java} | 6 +++--- .../core/usecase/AuthenticateByToken.java | 18 +++++++++--------- .../core/usecase/CreateImpersonationToken.java | 4 ++-- .../core/usecase/CreateUser.java | 12 ++++++------ .../userrepository/core/usecase/GetUser.java | 8 ++++---- .../userrepository/core/usecase/PurgeUser.java | 4 ++-- .../core/usecase/RevokeImpersonationToken.java | 4 ++-- .../core/usecase/UpdateUser.java | 16 ++++++++-------- .../core/domain/entity/AnchorTest.java | 6 +++--- .../core/usecase/AuthenticateByTokenTest.java | 18 +++++++++--------- .../usecase/CreateImpersonationTokenTest.java | 4 ++-- .../core/usecase/CreateUserTest.java | 12 ++++++------ .../core/usecase/GetUserTest.java | 8 ++++---- .../core/usecase/PurgeUserTest.java | 4 ++-- .../usecase/RevokeImpersonationTokenTest.java | 4 ++-- .../core/usecase/UpdateUserTest.java | 16 ++++++++-------- 28 files changed, 118 insertions(+), 118 deletions(-) rename src/main/java/com/sitepark/ies/userrepository/core/domain/exception/{AccessDenied.java => AccessDeniedException.java} (56%) rename src/main/java/com/sitepark/ies/userrepository/core/domain/exception/{AccessTokenExpired.java => AccessTokenExpiredException.java} (69%) rename src/main/java/com/sitepark/ies/userrepository/core/domain/exception/{AccessTokenNotActive.java => AccessTokenNotActiveException.java} (52%) rename src/main/java/com/sitepark/ies/userrepository/core/domain/exception/{AccessTokenRevoked.java => AccessTokenRevokedException.java} (50%) rename src/main/java/com/sitepark/ies/userrepository/core/domain/exception/{AnchorAlreadyExists.java => AnchorAlreadyExistsException.java} (72%) rename src/main/java/com/sitepark/ies/userrepository/core/domain/exception/{AnchorNotFound.java => AnchorNotFoundException.java} (71%) rename src/main/java/com/sitepark/ies/userrepository/core/domain/exception/{AuthenticationFailed.java => AuthenticationFailedException.java} (50%) delete mode 100644 src/main/java/com/sitepark/ies/userrepository/core/domain/exception/InvalidAccessToken.java create mode 100644 src/main/java/com/sitepark/ies/userrepository/core/domain/exception/InvalidAccessTokenException.java rename src/main/java/com/sitepark/ies/userrepository/core/domain/exception/{InvalidAnchor.java => InvalidAnchorException.java} (65%) rename src/main/java/com/sitepark/ies/userrepository/core/domain/exception/{LoginAlreadyExists.java => LoginAlreadyExistsException.java} (71%) rename src/main/java/com/sitepark/ies/userrepository/core/domain/exception/{UserNotFound.java => UserNotFoundException.java} (67%) diff --git a/src/main/java/com/sitepark/ies/userrepository/core/domain/entity/Anchor.java b/src/main/java/com/sitepark/ies/userrepository/core/domain/entity/Anchor.java index 91bab3c..93f4900 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/domain/entity/Anchor.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/domain/entity/Anchor.java @@ -5,7 +5,7 @@ import java.util.regex.Pattern; import com.fasterxml.jackson.annotation.JsonValue; -import com.sitepark.ies.userrepository.core.domain.exception.InvalidAnchor; +import com.sitepark.ies.userrepository.core.domain.exception.InvalidAnchorException; /** *

@@ -76,16 +76,16 @@ public String getName() { } /** - * @throws InvalidAnchor + * @throws InvalidAnchorException */ private static void validate(String name) { if (ONLY_NUMBERS_PATTERN.matcher(name).matches()) { - throw new InvalidAnchor(name, "Anchor must not only consist of numbers"); + throw new InvalidAnchorException(name, "Anchor must not only consist of numbers"); } if (!VALIDATOR_PATTERN.matcher(name).matches()) { - throw new InvalidAnchor(name, "Anchor contains Spaces"); + throw new InvalidAnchorException(name, "Anchor contains Spaces"); } } diff --git a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessDenied.java b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessDeniedException.java similarity index 56% rename from src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessDenied.java rename to src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessDeniedException.java index d6a7053..843b5ee 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessDenied.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessDeniedException.java @@ -1,14 +1,14 @@ package com.sitepark.ies.userrepository.core.domain.exception; /** - * The AccessDenied exception is thrown when a user or + * The AccessDeniedException exception is thrown when a user or * process is denied access to a resource or operation due to * insufficient permissions or authorization. */ -public class AccessDenied extends UserRepositoryException { +public class AccessDeniedException extends UserRepositoryException { private static final long serialVersionUID = 1L; - public AccessDenied(String message) { + public AccessDeniedException(String message) { super(message); } } \ No newline at end of file diff --git a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenExpired.java b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenExpiredException.java similarity index 69% rename from src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenExpired.java rename to src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenExpiredException.java index 36299b0..c709ff0 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenExpired.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenExpiredException.java @@ -3,17 +3,17 @@ import java.time.OffsetDateTime; /** - * The AccessTokenExpired exception is thrown when + * The AccessTokenExpiredException exception is thrown when * an access token has expired and is no longer valid for * authentication purposes. */ -public class AccessTokenExpired extends AuthenticationFailed { +public class AccessTokenExpiredException extends AuthenticationFailedException { private static final long serialVersionUID = 1L; private final OffsetDateTime expiredAt; - public AccessTokenExpired(OffsetDateTime expiredAt) { + public AccessTokenExpiredException(OffsetDateTime expiredAt) { super(); this.expiredAt = expiredAt; } diff --git a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenNotActive.java b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenNotActiveException.java similarity index 52% rename from src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenNotActive.java rename to src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenNotActiveException.java index 3a764f8..4711a9a 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenNotActive.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenNotActiveException.java @@ -1,15 +1,15 @@ package com.sitepark.ies.userrepository.core.domain.exception; /** - * The AccessTokenNotActive exception is thrown + * The AccessTokenNotActiveException exception is thrown * when an access token is not active, making * it invalid for authentication. */ -public class AccessTokenNotActive extends AuthenticationFailed { +public class AccessTokenNotActiveException extends AuthenticationFailedException { private static final long serialVersionUID = 1L; - public AccessTokenNotActive() { + public AccessTokenNotActiveException() { super(); } } \ No newline at end of file diff --git a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenRevoked.java b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenRevokedException.java similarity index 50% rename from src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenRevoked.java rename to src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenRevokedException.java index 63245e4..c3056ca 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenRevoked.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AccessTokenRevokedException.java @@ -1,14 +1,14 @@ package com.sitepark.ies.userrepository.core.domain.exception; /** - * The AccessTokenRevoked exception is thrown when an access token has been + * The AccessTokenRevokedException exception is thrown when an access token has been * explicitly revoked, rendering it unusable for authentication or authorization. */ -public class AccessTokenRevoked extends AuthenticationFailed { +public class AccessTokenRevokedException extends AuthenticationFailedException { private static final long serialVersionUID = 1L; - public AccessTokenRevoked() { + public AccessTokenRevokedException() { super(); } } \ No newline at end of file diff --git a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AnchorAlreadyExists.java b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AnchorAlreadyExistsException.java similarity index 72% rename from src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AnchorAlreadyExists.java rename to src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AnchorAlreadyExistsException.java index 4918267..8abf228 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AnchorAlreadyExists.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AnchorAlreadyExistsException.java @@ -3,10 +3,10 @@ import com.sitepark.ies.userrepository.core.domain.entity.Anchor; /** - * The AnchorAlreadyExists exception is thrown when attempting to create + * The AnchorAlreadyExistsException exception is thrown when attempting to create * a new anchor that already exists, violating the uniqueness constraint for anchors. */ -public class AnchorAlreadyExists extends UserRepositoryException { +public class AnchorAlreadyExistsException extends UserRepositoryException { private static final long serialVersionUID = 1L; @@ -14,7 +14,7 @@ public class AnchorAlreadyExists extends UserRepositoryException { private final long owner; - public AnchorAlreadyExists(Anchor anchor, long owner) { + public AnchorAlreadyExistsException(Anchor anchor, long owner) { super(); this.anchor = anchor; this.owner = owner; diff --git a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AnchorNotFound.java b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AnchorNotFoundException.java similarity index 71% rename from src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AnchorNotFound.java rename to src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AnchorNotFoundException.java index c07bcd6..5c07c97 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AnchorNotFound.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AnchorNotFoundException.java @@ -3,17 +3,17 @@ import com.sitepark.ies.userrepository.core.domain.entity.Anchor; /** - * The AnchorNotFound exception is thrown when an anchor cannot be found + * The AnchorNotFoundException exception is thrown when an anchor cannot be found * or does not exist in the system, typically when trying to access or manipulate an * anchor that is not present. */ -public class AnchorNotFound extends UserRepositoryException { +public class AnchorNotFoundException extends UserRepositoryException { private static final long serialVersionUID = 1L; private final Anchor anchor; - public AnchorNotFound(Anchor anchor) { + public AnchorNotFoundException(Anchor anchor) { super(); this.anchor = anchor; } diff --git a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AuthenticationFailed.java b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AuthenticationFailedException.java similarity index 50% rename from src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AuthenticationFailed.java rename to src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AuthenticationFailedException.java index aa13abf..206bfde 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AuthenticationFailed.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/AuthenticationFailedException.java @@ -1,18 +1,18 @@ package com.sitepark.ies.userrepository.core.domain.exception; /** - * The AuthenticationFailed exception is thrown when an authentication + * The AuthenticationFailedException exception is thrown when an authentication * process fails, indicating that the provided credentials are invalid or authentication * was unsuccessful for some reason. */ -public abstract class AuthenticationFailed extends UserRepositoryException { +public abstract class AuthenticationFailedException extends UserRepositoryException { private static final long serialVersionUID = 1L; - public AuthenticationFailed() { + public AuthenticationFailedException() { super(); } - public AuthenticationFailed(String msg) { + public AuthenticationFailedException(String msg) { super(msg); } diff --git a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/InvalidAccessToken.java b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/InvalidAccessToken.java deleted file mode 100644 index c4d0bee..0000000 --- a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/InvalidAccessToken.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.sitepark.ies.userrepository.core.domain.exception; - -/** - * The InvalidAccessToken exception is thrown when an access token provided - * for authentication is invalid. - */ -public class InvalidAccessToken extends AuthenticationFailed { - - private static final long serialVersionUID = 1L; - - public InvalidAccessToken(String msg) { - super(msg); - } -} \ No newline at end of file diff --git a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/InvalidAccessTokenException.java b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/InvalidAccessTokenException.java new file mode 100644 index 0000000..20bdc72 --- /dev/null +++ b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/InvalidAccessTokenException.java @@ -0,0 +1,14 @@ +package com.sitepark.ies.userrepository.core.domain.exception; + +/** + * The InvalidAccessTokenException exception is thrown when an access token provided + * for authentication is invalid. + */ +public class InvalidAccessTokenException extends AuthenticationFailedException { + + private static final long serialVersionUID = 1L; + + public InvalidAccessTokenException(String msg) { + super(msg); + } +} \ No newline at end of file diff --git a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/InvalidAnchor.java b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/InvalidAnchorException.java similarity index 65% rename from src/main/java/com/sitepark/ies/userrepository/core/domain/exception/InvalidAnchor.java rename to src/main/java/com/sitepark/ies/userrepository/core/domain/exception/InvalidAnchorException.java index e3e7895..21adda2 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/InvalidAnchor.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/InvalidAnchorException.java @@ -1,16 +1,16 @@ package com.sitepark.ies.userrepository.core.domain.exception; /** - * The InvalidAnchor exception is thrown when an anchor provided as a reference + * The InvalidAnchorException exception is thrown when an anchor provided as a reference * is invalid, not recognized, or does not conform to the expected format or criteria. */ -public class InvalidAnchor extends UserRepositoryException { +public class InvalidAnchorException extends UserRepositoryException { private final String name; private static final long serialVersionUID = 1L; - public InvalidAnchor(String name, String message) { + public InvalidAnchorException(String name, String message) { super(message); this.name = name; } diff --git a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/LoginAlreadyExists.java b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/LoginAlreadyExistsException.java similarity index 71% rename from src/main/java/com/sitepark/ies/userrepository/core/domain/exception/LoginAlreadyExists.java rename to src/main/java/com/sitepark/ies/userrepository/core/domain/exception/LoginAlreadyExistsException.java index e283f90..ab897b0 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/LoginAlreadyExists.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/LoginAlreadyExistsException.java @@ -1,11 +1,11 @@ package com.sitepark.ies.userrepository.core.domain.exception; /** - * The LoginAlreadyExists exception is thrown when attempting to create + * The LoginAlreadyExistsException exception is thrown when attempting to create * a user with a login or username that already exists in the system, violating the * uniqueness constraint for user logins. */ -public class LoginAlreadyExists extends UserRepositoryException { +public class LoginAlreadyExistsException extends UserRepositoryException { private static final long serialVersionUID = 1L; @@ -13,7 +13,7 @@ public class LoginAlreadyExists extends UserRepositoryException { private final long owner; - public LoginAlreadyExists(String login, long owner) { + public LoginAlreadyExistsException(String login, long owner) { super(); this.login = login; this.owner = owner; diff --git a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/UserNotFound.java b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/UserNotFoundException.java similarity index 67% rename from src/main/java/com/sitepark/ies/userrepository/core/domain/exception/UserNotFound.java rename to src/main/java/com/sitepark/ies/userrepository/core/domain/exception/UserNotFoundException.java index ac0df2a..4be091f 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/UserNotFound.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/domain/exception/UserNotFoundException.java @@ -1,17 +1,17 @@ package com.sitepark.ies.userrepository.core.domain.exception; /** - * The UserNotFound exception is thrown when a user cannot be found or does not exist + * The UserNotFoundException exception is thrown when a user cannot be found or does not exist * in the system, typically when attempting to access or manipulate user-related information for * a user that is not present. */ -public class UserNotFound extends UserRepositoryException { +public class UserNotFoundException extends UserRepositoryException { private static final long serialVersionUID = 1L; private final long id; - public UserNotFound(long id) { + public UserNotFoundException(long id) { super(); this.id = id; } diff --git a/src/main/java/com/sitepark/ies/userrepository/core/usecase/AuthenticateByToken.java b/src/main/java/com/sitepark/ies/userrepository/core/usecase/AuthenticateByToken.java index a03dedc..be8f85b 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/usecase/AuthenticateByToken.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/usecase/AuthenticateByToken.java @@ -7,10 +7,10 @@ import com.sitepark.ies.userrepository.core.domain.entity.AccessToken; import com.sitepark.ies.userrepository.core.domain.entity.User; -import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenExpired; -import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenNotActive; -import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenRevoked; -import com.sitepark.ies.userrepository.core.domain.exception.InvalidAccessToken; +import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenExpiredException; +import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenNotActiveException; +import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenRevokedException; +import com.sitepark.ies.userrepository.core.domain.exception.InvalidAccessTokenException; import com.sitepark.ies.userrepository.core.port.AccessTokenRepository; import com.sitepark.ies.userrepository.core.port.UserRepository; @@ -32,21 +32,21 @@ public User authenticateByToken(String token) { Optional accessTokenOptinal = this.accessTokenRepository.getByToken(token); if (accessTokenOptinal.isEmpty()) { - throw new InvalidAccessToken("Token not found"); + throw new InvalidAccessTokenException("Token not found"); } AccessToken accessToken = accessTokenOptinal.get(); if (!accessToken.isActive()) { - throw new AccessTokenNotActive(); + throw new AccessTokenNotActiveException(); } if (accessToken.isRevoked()) { - throw new AccessTokenRevoked(); + throw new AccessTokenRevokedException(); } this.checkExpirationDate(accessToken.getExpiresAt()); Optional user = this.userRepository.get(accessToken.getUser()); if (user.isEmpty()) { - throw new InvalidAccessToken("User " + accessToken.getUser() + " not found"); + throw new InvalidAccessTokenException("User " + accessToken.getUser() + " not found"); } return user.get(); @@ -60,7 +60,7 @@ public void checkExpirationDate(Optional expiredAt) { OffsetDateTime now = OffsetDateTime.now(); if (expiredAt.get().isBefore(now)) { - throw new AccessTokenExpired(expiredAt.get()); + throw new AccessTokenExpiredException(expiredAt.get()); } } } diff --git a/src/main/java/com/sitepark/ies/userrepository/core/usecase/CreateImpersonationToken.java b/src/main/java/com/sitepark/ies/userrepository/core/usecase/CreateImpersonationToken.java index a31e7fe..13f0e7e 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/usecase/CreateImpersonationToken.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/usecase/CreateImpersonationToken.java @@ -6,7 +6,7 @@ import org.apache.logging.log4j.Logger; import com.sitepark.ies.userrepository.core.domain.entity.AccessToken; -import com.sitepark.ies.userrepository.core.domain.exception.AccessDenied; +import com.sitepark.ies.userrepository.core.domain.exception.AccessDeniedException; import com.sitepark.ies.userrepository.core.port.AccessControl; import com.sitepark.ies.userrepository.core.port.AccessTokenRepository; @@ -33,7 +33,7 @@ public AccessToken createPersonalAccessToken(AccessToken accessToken) { .build(); if (!this.accessControl.isImpersonationTokensManageable()) { - throw new AccessDenied("Not allowed manage impersonation tokens"); + throw new AccessDeniedException("Not allowed manage impersonation tokens"); } if (LOGGER.isInfoEnabled()) { diff --git a/src/main/java/com/sitepark/ies/userrepository/core/usecase/CreateUser.java b/src/main/java/com/sitepark/ies/userrepository/core/usecase/CreateUser.java index 0a01603..c328b62 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/usecase/CreateUser.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/usecase/CreateUser.java @@ -9,9 +9,9 @@ import org.apache.logging.log4j.Logger; import com.sitepark.ies.userrepository.core.domain.entity.User; -import com.sitepark.ies.userrepository.core.domain.exception.AccessDenied; -import com.sitepark.ies.userrepository.core.domain.exception.AnchorAlreadyExists; -import com.sitepark.ies.userrepository.core.domain.exception.LoginAlreadyExists; +import com.sitepark.ies.userrepository.core.domain.exception.AccessDeniedException; +import com.sitepark.ies.userrepository.core.domain.exception.AnchorAlreadyExistsException; +import com.sitepark.ies.userrepository.core.domain.exception.LoginAlreadyExistsException; import com.sitepark.ies.userrepository.core.port.AccessControl; import com.sitepark.ies.userrepository.core.port.ExtensionsNotifier; import com.sitepark.ies.userrepository.core.port.IdGenerator; @@ -57,7 +57,7 @@ public long createUser(User newUser) { this.validateLogin(newUser); if (!this.accessControl.isUserCreateable()) { - throw new AccessDenied("Not allowed to create user " + newUser); + throw new AccessDeniedException("Not allowed to create user " + newUser); } long generatedId = this.idGenerator.generate(); @@ -83,7 +83,7 @@ private void validateAnchor(User newUser) { if (newUser.getAnchor().isPresent()) { Optional anchorOwner = this.repository.resolveAnchor(newUser.getAnchor().get()); if (anchorOwner.isPresent()) { - throw new AnchorAlreadyExists(newUser.getAnchor().get(), anchorOwner.get()); + throw new AnchorAlreadyExistsException(newUser.getAnchor().get(), anchorOwner.get()); } } } @@ -91,7 +91,7 @@ private void validateAnchor(User newUser) { private void validateLogin(User newUser) { Optional resolveLogin = this.repository.resolveLogin(newUser.getLogin()); if (resolveLogin.isPresent()) { - throw new LoginAlreadyExists(newUser.getLogin(), resolveLogin.get()); + throw new LoginAlreadyExistsException(newUser.getLogin(), resolveLogin.get()); } } } diff --git a/src/main/java/com/sitepark/ies/userrepository/core/usecase/GetUser.java b/src/main/java/com/sitepark/ies/userrepository/core/usecase/GetUser.java index cf42d1b..071fca2 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/usecase/GetUser.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/usecase/GetUser.java @@ -6,8 +6,8 @@ import com.sitepark.ies.userrepository.core.domain.entity.Role; import com.sitepark.ies.userrepository.core.domain.entity.User; -import com.sitepark.ies.userrepository.core.domain.exception.AccessDenied; -import com.sitepark.ies.userrepository.core.domain.exception.UserNotFound; +import com.sitepark.ies.userrepository.core.domain.exception.AccessDeniedException; +import com.sitepark.ies.userrepository.core.domain.exception.UserNotFoundException; import com.sitepark.ies.userrepository.core.port.AccessControl; import com.sitepark.ies.userrepository.core.port.RoleAssigner; import com.sitepark.ies.userrepository.core.port.UserRepository; @@ -33,10 +33,10 @@ protected GetUser( public User getUser(long id) { if (!this.accessControl.isUserReadable(id)) { - throw new AccessDenied("Not allowed to reat user " + id); + throw new AccessDeniedException("Not allowed to reat user " + id); } - User user = this.repository.get(id).orElseThrow(() -> new UserNotFound(id)); + User user = this.repository.get(id).orElseThrow(() -> new UserNotFoundException(id)); List roleList = this.roleAssigner.getRolesAssignByUser(id); diff --git a/src/main/java/com/sitepark/ies/userrepository/core/usecase/PurgeUser.java b/src/main/java/com/sitepark/ies/userrepository/core/usecase/PurgeUser.java index 3ec94c2..a604812 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/usecase/PurgeUser.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/usecase/PurgeUser.java @@ -5,7 +5,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.sitepark.ies.userrepository.core.domain.exception.AccessDenied; +import com.sitepark.ies.userrepository.core.domain.exception.AccessDeniedException; import com.sitepark.ies.userrepository.core.port.AccessControl; import com.sitepark.ies.userrepository.core.port.AccessTokenRepository; import com.sitepark.ies.userrepository.core.port.ExtensionsNotifier; @@ -39,7 +39,7 @@ protected PurgeUser( public void purgeUser(long id) { if (!this.accessControl.isUserRemovable(id)) { - throw new AccessDenied("Not allowed to remove user " + id); + throw new AccessDeniedException("Not allowed to remove user " + id); } if (LOGGER.isInfoEnabled()) { diff --git a/src/main/java/com/sitepark/ies/userrepository/core/usecase/RevokeImpersonationToken.java b/src/main/java/com/sitepark/ies/userrepository/core/usecase/RevokeImpersonationToken.java index 826f633..4998961 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/usecase/RevokeImpersonationToken.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/usecase/RevokeImpersonationToken.java @@ -5,7 +5,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.sitepark.ies.userrepository.core.domain.exception.AccessDenied; +import com.sitepark.ies.userrepository.core.domain.exception.AccessDeniedException; import com.sitepark.ies.userrepository.core.port.AccessControl; import com.sitepark.ies.userrepository.core.port.AccessTokenRepository; @@ -28,7 +28,7 @@ protected RevokeImpersonationToken( public void revokeImpersonationToken(long user, long id) { if (!this.accessControl.isImpersonationTokensManageable()) { - throw new AccessDenied("Not allowed manage impersonation tokens"); + throw new AccessDeniedException("Not allowed manage impersonation tokens"); } if (LOGGER.isInfoEnabled()) { diff --git a/src/main/java/com/sitepark/ies/userrepository/core/usecase/UpdateUser.java b/src/main/java/com/sitepark/ies/userrepository/core/usecase/UpdateUser.java index 213c5b4..164a239 100644 --- a/src/main/java/com/sitepark/ies/userrepository/core/usecase/UpdateUser.java +++ b/src/main/java/com/sitepark/ies/userrepository/core/usecase/UpdateUser.java @@ -11,10 +11,10 @@ import com.sitepark.ies.userrepository.core.domain.entity.Role; import com.sitepark.ies.userrepository.core.domain.entity.User; -import com.sitepark.ies.userrepository.core.domain.exception.AccessDenied; -import com.sitepark.ies.userrepository.core.domain.exception.AnchorNotFound; -import com.sitepark.ies.userrepository.core.domain.exception.LoginAlreadyExists; -import com.sitepark.ies.userrepository.core.domain.exception.UserNotFound; +import com.sitepark.ies.userrepository.core.domain.exception.AccessDeniedException; +import com.sitepark.ies.userrepository.core.domain.exception.AnchorNotFoundException; +import com.sitepark.ies.userrepository.core.domain.exception.LoginAlreadyExistsException; +import com.sitepark.ies.userrepository.core.domain.exception.UserNotFoundException; import com.sitepark.ies.userrepository.core.port.AccessControl; import com.sitepark.ies.userrepository.core.port.ExtensionsNotifier; import com.sitepark.ies.userrepository.core.port.RoleAssigner; @@ -81,7 +81,7 @@ private User buildUserWithId(User user) { return user; } else if (user.getAnchor().isPresent()) { long id = this.repository.resolveAnchor(user.getAnchor().get()) - .orElseThrow(() -> new AnchorNotFound(user.getAnchor().get())); + .orElseThrow(() -> new AnchorNotFoundException(user.getAnchor().get())); return user.toBuilder().id(id).build(); } else { throw new IllegalArgumentException("For users to be updated neither an id nor an anchor is set"); @@ -90,13 +90,13 @@ private User buildUserWithId(User user) { private void validateWritable(long id) { if (!this.accessControl.isUserWritable(id)) { - throw new AccessDenied("Not allowed to update user " + id); + throw new AccessDeniedException("Not allowed to update user " + id); } } private User loadStoredUser(long id) { User storedUser = this.repository.get(id) - .orElseThrow(() -> new UserNotFound(id)); + .orElseThrow(() -> new UserNotFoundException(id)); List roleList = this.roleAssigner.getRolesAssignByUser(storedUser.getId().get()); return storedUser.toBuilder() @@ -107,7 +107,7 @@ private User loadStoredUser(long id) { private void validateLogin(User user) { Optional resolveLogin = this.repository.resolveLogin(user.getLogin()); if (resolveLogin.isPresent() && !resolveLogin.equals(user.getId())) { - throw new LoginAlreadyExists(user.getLogin(), resolveLogin.get()); + throw new LoginAlreadyExistsException(user.getLogin(), resolveLogin.get()); } } diff --git a/src/test/java/com/sitepark/ies/userrepository/core/domain/entity/AnchorTest.java b/src/test/java/com/sitepark/ies/userrepository/core/domain/entity/AnchorTest.java index 9137403..19a9444 100644 --- a/src/test/java/com/sitepark/ies/userrepository/core/domain/entity/AnchorTest.java +++ b/src/test/java/com/sitepark/ies/userrepository/core/domain/entity/AnchorTest.java @@ -9,7 +9,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.sitepark.ies.userrepository.core.domain.exception.InvalidAnchor; +import com.sitepark.ies.userrepository.core.domain.exception.InvalidAnchorException; import nl.jqno.equalsverifier.EqualsVerifier; @@ -43,7 +43,7 @@ void testValidateValidAnchor() { @Test void testValidateOnlyDigits() { - InvalidAnchor thrown = assertThrows(InvalidAnchor.class, () -> { + InvalidAnchorException thrown = assertThrows(InvalidAnchorException.class, () -> { Anchor.ofString("1234556789012345"); }); assertEquals("1234556789012345", thrown.getName(), "unexpected name"); @@ -51,7 +51,7 @@ void testValidateOnlyDigits() { @Test void testValidateInvalidChars() { - InvalidAnchor thrown = assertThrows(InvalidAnchor.class, () -> { + InvalidAnchorException thrown = assertThrows(InvalidAnchorException.class, () -> { Anchor.ofString("a.b,c"); }); assertEquals("a.b,c", thrown.getName(), "unexpected name"); diff --git a/src/test/java/com/sitepark/ies/userrepository/core/usecase/AuthenticateByTokenTest.java b/src/test/java/com/sitepark/ies/userrepository/core/usecase/AuthenticateByTokenTest.java index 7dcad60..673a659 100644 --- a/src/test/java/com/sitepark/ies/userrepository/core/usecase/AuthenticateByTokenTest.java +++ b/src/test/java/com/sitepark/ies/userrepository/core/usecase/AuthenticateByTokenTest.java @@ -14,10 +14,10 @@ import com.sitepark.ies.userrepository.core.domain.entity.AccessToken; import com.sitepark.ies.userrepository.core.domain.entity.User; -import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenExpired; -import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenNotActive; -import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenRevoked; -import com.sitepark.ies.userrepository.core.domain.exception.InvalidAccessToken; +import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenExpiredException; +import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenNotActiveException; +import com.sitepark.ies.userrepository.core.domain.exception.AccessTokenRevokedException; +import com.sitepark.ies.userrepository.core.domain.exception.InvalidAccessTokenException; import com.sitepark.ies.userrepository.core.port.AccessTokenRepository; import com.sitepark.ies.userrepository.core.port.UserRepository; @@ -38,7 +38,7 @@ void testTokenNotFound() { accessTokenRepository, userRepository); - assertThrows(InvalidAccessToken.class, () -> { + assertThrows(InvalidAccessTokenException.class, () -> { authenticateByToken.authenticateByToken(TOKEN_STRING); }); } @@ -61,7 +61,7 @@ void testTokenNotActive() { accessTokenRepository, userRepository); - assertThrows(AccessTokenNotActive.class, () -> { + assertThrows(AccessTokenNotActiveException.class, () -> { authenticateByToken.authenticateByToken(TOKEN_STRING); }); } @@ -84,7 +84,7 @@ void testTokenRevoked() { accessTokenRepository, userRepository); - assertThrows(AccessTokenRevoked.class, () -> { + assertThrows(AccessTokenRevokedException.class, () -> { authenticateByToken.authenticateByToken("abc"); }); } @@ -109,7 +109,7 @@ void testTokenExpired() { accessTokenRepository, userRepository); - assertThrows(AccessTokenExpired.class, () -> { + assertThrows(AccessTokenExpiredException.class, () -> { authenticateByToken.authenticateByToken(TOKEN_STRING); }); } @@ -134,7 +134,7 @@ void testUserNotFound() { accessTokenRepository, userRepository); - assertThrows(InvalidAccessToken.class, () -> { + assertThrows(InvalidAccessTokenException.class, () -> { authenticateByToken.authenticateByToken(TOKEN_STRING); }); } diff --git a/src/test/java/com/sitepark/ies/userrepository/core/usecase/CreateImpersonationTokenTest.java b/src/test/java/com/sitepark/ies/userrepository/core/usecase/CreateImpersonationTokenTest.java index d324164..bfcdea4 100644 --- a/src/test/java/com/sitepark/ies/userrepository/core/usecase/CreateImpersonationTokenTest.java +++ b/src/test/java/com/sitepark/ies/userrepository/core/usecase/CreateImpersonationTokenTest.java @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test; import com.sitepark.ies.userrepository.core.domain.entity.AccessToken; -import com.sitepark.ies.userrepository.core.domain.exception.AccessDenied; +import com.sitepark.ies.userrepository.core.domain.exception.AccessDeniedException; import com.sitepark.ies.userrepository.core.port.AccessControl; import com.sitepark.ies.userrepository.core.port.AccessTokenRepository; @@ -28,7 +28,7 @@ void testAccessDenied() { accessTokenRepository, accessControl); - assertThrows(AccessDenied.class, () -> { + assertThrows(AccessDeniedException.class, () -> { createImpersonationToken.createPersonalAccessToken(accessToken); }); diff --git a/src/test/java/com/sitepark/ies/userrepository/core/usecase/CreateUserTest.java b/src/test/java/com/sitepark/ies/userrepository/core/usecase/CreateUserTest.java index 3f7c36b..8d64553 100644 --- a/src/test/java/com/sitepark/ies/userrepository/core/usecase/CreateUserTest.java +++ b/src/test/java/com/sitepark/ies/userrepository/core/usecase/CreateUserTest.java @@ -18,9 +18,9 @@ import com.sitepark.ies.userrepository.core.domain.entity.User; import com.sitepark.ies.userrepository.core.domain.entity.role.Ref; import com.sitepark.ies.userrepository.core.domain.entity.role.UserLevelRoles; -import com.sitepark.ies.userrepository.core.domain.exception.AccessDenied; -import com.sitepark.ies.userrepository.core.domain.exception.AnchorAlreadyExists; -import com.sitepark.ies.userrepository.core.domain.exception.LoginAlreadyExists; +import com.sitepark.ies.userrepository.core.domain.exception.AccessDeniedException; +import com.sitepark.ies.userrepository.core.domain.exception.AnchorAlreadyExistsException; +import com.sitepark.ies.userrepository.core.domain.exception.LoginAlreadyExistsException; import com.sitepark.ies.userrepository.core.port.AccessControl; import com.sitepark.ies.userrepository.core.port.ExtensionsNotifier; import com.sitepark.ies.userrepository.core.port.IdGenerator; @@ -48,7 +48,7 @@ void testAccessDeniedCreate() { accessControl, null, extensionsNotifier); - assertThrows(AccessDenied.class, () -> { + assertThrows(AccessDeniedException.class, () -> { createUserUseCase.createUser(user); }); @@ -97,7 +97,7 @@ void testAnchorAlreadyExists() { null, extensionsNotifier); - AnchorAlreadyExists thrown = assertThrows(AnchorAlreadyExists.class, () -> { + AnchorAlreadyExistsException thrown = assertThrows(AnchorAlreadyExistsException.class, () -> { createUserUseCase.createUser(user); }); @@ -209,7 +209,7 @@ void testCreateWithExistsLogin() { idGenerator, extensionsNotifier); - assertThrows(LoginAlreadyExists.class, () -> { + assertThrows(LoginAlreadyExistsException.class, () -> { createUserUseCase.createUser(user); }); } diff --git a/src/test/java/com/sitepark/ies/userrepository/core/usecase/GetUserTest.java b/src/test/java/com/sitepark/ies/userrepository/core/usecase/GetUserTest.java index dd10870..59843e4 100644 --- a/src/test/java/com/sitepark/ies/userrepository/core/usecase/GetUserTest.java +++ b/src/test/java/com/sitepark/ies/userrepository/core/usecase/GetUserTest.java @@ -14,8 +14,8 @@ import com.sitepark.ies.userrepository.core.domain.entity.User; import com.sitepark.ies.userrepository.core.domain.entity.role.Ref; import com.sitepark.ies.userrepository.core.domain.entity.role.UserLevelRoles; -import com.sitepark.ies.userrepository.core.domain.exception.AccessDenied; -import com.sitepark.ies.userrepository.core.domain.exception.UserNotFound; +import com.sitepark.ies.userrepository.core.domain.exception.AccessDeniedException; +import com.sitepark.ies.userrepository.core.domain.exception.UserNotFoundException; import com.sitepark.ies.userrepository.core.port.AccessControl; import com.sitepark.ies.userrepository.core.port.RoleAssigner; import com.sitepark.ies.userrepository.core.port.UserRepository; @@ -35,7 +35,7 @@ void testAccessDeniedGet() { roleAssigner, accessControl); - assertThrows(AccessDenied.class, () -> { + assertThrows(AccessDeniedException.class, () -> { getUserUseCase.getUser(123L); }); } @@ -86,7 +86,7 @@ void testGetUserNotFound() { roleAssigner, accessControl); - assertThrows(UserNotFound.class, () -> { + assertThrows(UserNotFoundException.class, () -> { getUserUseCase.getUser(123L); }); } diff --git a/src/test/java/com/sitepark/ies/userrepository/core/usecase/PurgeUserTest.java b/src/test/java/com/sitepark/ies/userrepository/core/usecase/PurgeUserTest.java index 4df0abc..b63efc0 100644 --- a/src/test/java/com/sitepark/ies/userrepository/core/usecase/PurgeUserTest.java +++ b/src/test/java/com/sitepark/ies/userrepository/core/usecase/PurgeUserTest.java @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test; -import com.sitepark.ies.userrepository.core.domain.exception.AccessDenied; +import com.sitepark.ies.userrepository.core.domain.exception.AccessDeniedException; import com.sitepark.ies.userrepository.core.port.AccessControl; import com.sitepark.ies.userrepository.core.port.AccessTokenRepository; import com.sitepark.ies.userrepository.core.port.ExtensionsNotifier; @@ -29,7 +29,7 @@ void testAccessDenied() { extensionsNotifier, accessControl, accessTokenRepository); - assertThrows(AccessDenied.class, () -> { + assertThrows(AccessDeniedException.class, () -> { purgeEntity.purgeUser(10L); }); } diff --git a/src/test/java/com/sitepark/ies/userrepository/core/usecase/RevokeImpersonationTokenTest.java b/src/test/java/com/sitepark/ies/userrepository/core/usecase/RevokeImpersonationTokenTest.java index 80ad16d..a00e308 100644 --- a/src/test/java/com/sitepark/ies/userrepository/core/usecase/RevokeImpersonationTokenTest.java +++ b/src/test/java/com/sitepark/ies/userrepository/core/usecase/RevokeImpersonationTokenTest.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test; -import com.sitepark.ies.userrepository.core.domain.exception.AccessDenied; +import com.sitepark.ies.userrepository.core.domain.exception.AccessDeniedException; import com.sitepark.ies.userrepository.core.port.AccessControl; import com.sitepark.ies.userrepository.core.port.AccessTokenRepository; @@ -24,7 +24,7 @@ void testAccessDenied() { accessTokenRepository, accessControl); - assertThrows(AccessDenied.class, () -> { + assertThrows(AccessDeniedException.class, () -> { revokeImpersonationToken.revokeImpersonationToken(1L, 2L); }); diff --git a/src/test/java/com/sitepark/ies/userrepository/core/usecase/UpdateUserTest.java b/src/test/java/com/sitepark/ies/userrepository/core/usecase/UpdateUserTest.java index d9f3f4b..55f1c2f 100644 --- a/src/test/java/com/sitepark/ies/userrepository/core/usecase/UpdateUserTest.java +++ b/src/test/java/com/sitepark/ies/userrepository/core/usecase/UpdateUserTest.java @@ -17,10 +17,10 @@ import com.sitepark.ies.userrepository.core.domain.entity.Anchor; import com.sitepark.ies.userrepository.core.domain.entity.User; -import com.sitepark.ies.userrepository.core.domain.exception.AccessDenied; -import com.sitepark.ies.userrepository.core.domain.exception.AnchorNotFound; -import com.sitepark.ies.userrepository.core.domain.exception.LoginAlreadyExists; -import com.sitepark.ies.userrepository.core.domain.exception.UserNotFound; +import com.sitepark.ies.userrepository.core.domain.exception.AccessDeniedException; +import com.sitepark.ies.userrepository.core.domain.exception.AnchorNotFoundException; +import com.sitepark.ies.userrepository.core.domain.exception.LoginAlreadyExistsException; +import com.sitepark.ies.userrepository.core.domain.exception.UserNotFoundException; import com.sitepark.ies.userrepository.core.port.AccessControl; import com.sitepark.ies.userrepository.core.port.ExtensionsNotifier; import com.sitepark.ies.userrepository.core.port.RoleAssigner; @@ -46,7 +46,7 @@ void testAccessDeniedUpdate() { null, accessControl, extensionsNotifier); - assertThrows(AccessDenied.class, () -> { + assertThrows(AccessDeniedException.class, () -> { updateUserUseCase.updateUser(user); }); @@ -92,7 +92,7 @@ void testUpdateUserNotFound() { .login("test") .build(); - UserNotFound thrown = assertThrows(UserNotFound.class, () -> { + UserNotFoundException thrown = assertThrows(UserNotFoundException.class, () -> { updateUserUseCase.updateUser(user); }); @@ -131,7 +131,7 @@ void testChangeLoginToAlreadyExistsLogin() { .login("test2") .build(); - LoginAlreadyExists thrown = assertThrows(LoginAlreadyExists.class, () -> { + LoginAlreadyExistsException thrown = assertThrows(LoginAlreadyExistsException.class, () -> { updateUserUseCase.updateUser(user); }); @@ -388,7 +388,7 @@ void testUpdateAnchorNotFound() { .anchor("user.test2") .build(); - AnchorNotFound thrown = assertThrows(AnchorNotFound.class, () -> { + AnchorNotFoundException thrown = assertThrows(AnchorNotFoundException.class, () -> { updateUserUseCase.updateUser(user); });