From 6b6e0ebc71a0c59aaca90e8021621ebc3d953266 Mon Sep 17 00:00:00 2001 From: Hai Phuc Nguyen Date: Sun, 5 Jan 2025 23:17:03 -0800 Subject: [PATCH] Update --- .../rest/errors => }/EmailAlreadyUsedException.java | 2 +- .../{web/rest/errors => }/InvalidLoginException.java | 2 +- .../rest/errors => }/InvalidPasswordException.java | 2 +- .../service/EmailAlreadyUsedException.java | 10 ---------- .../service/InvalidPasswordException.java | 10 ---------- .../modules/usermanagement/service/UserService.java | 2 ++ .../usermanagement/web/rest/LoginController.java | 2 +- .../usermanagement/web/rest/PublicUserController.java | 2 +- .../usermanagement/web/rest/UserAccountController.java | 4 ++-- .../web/rest/errors/ExceptionStatusMapper.java | 6 ++++++ 10 files changed, 15 insertions(+), 27 deletions(-) rename commons/src/main/java/io/flowinquiry/modules/usermanagement/{web/rest/errors => }/EmailAlreadyUsedException.java (76%) rename commons/src/main/java/io/flowinquiry/modules/usermanagement/{web/rest/errors => }/InvalidLoginException.java (74%) rename commons/src/main/java/io/flowinquiry/modules/usermanagement/{web/rest/errors => }/InvalidPasswordException.java (75%) delete mode 100644 commons/src/main/java/io/flowinquiry/modules/usermanagement/service/EmailAlreadyUsedException.java delete mode 100644 commons/src/main/java/io/flowinquiry/modules/usermanagement/service/InvalidPasswordException.java diff --git a/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/errors/EmailAlreadyUsedException.java b/commons/src/main/java/io/flowinquiry/modules/usermanagement/EmailAlreadyUsedException.java similarity index 76% rename from commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/errors/EmailAlreadyUsedException.java rename to commons/src/main/java/io/flowinquiry/modules/usermanagement/EmailAlreadyUsedException.java index cddd2e6..7cbd3e4 100644 --- a/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/errors/EmailAlreadyUsedException.java +++ b/commons/src/main/java/io/flowinquiry/modules/usermanagement/EmailAlreadyUsedException.java @@ -1,4 +1,4 @@ -package io.flowinquiry.modules.usermanagement.web.rest.errors; +package io.flowinquiry.modules.usermanagement; import io.flowinquiry.exceptions.UserException; diff --git a/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/errors/InvalidLoginException.java b/commons/src/main/java/io/flowinquiry/modules/usermanagement/InvalidLoginException.java similarity index 74% rename from commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/errors/InvalidLoginException.java rename to commons/src/main/java/io/flowinquiry/modules/usermanagement/InvalidLoginException.java index b378714..8d80ba6 100644 --- a/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/errors/InvalidLoginException.java +++ b/commons/src/main/java/io/flowinquiry/modules/usermanagement/InvalidLoginException.java @@ -1,4 +1,4 @@ -package io.flowinquiry.modules.usermanagement.web.rest.errors; +package io.flowinquiry.modules.usermanagement; import io.flowinquiry.exceptions.UserException; diff --git a/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/errors/InvalidPasswordException.java b/commons/src/main/java/io/flowinquiry/modules/usermanagement/InvalidPasswordException.java similarity index 75% rename from commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/errors/InvalidPasswordException.java rename to commons/src/main/java/io/flowinquiry/modules/usermanagement/InvalidPasswordException.java index 7803ab1..c64c365 100644 --- a/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/errors/InvalidPasswordException.java +++ b/commons/src/main/java/io/flowinquiry/modules/usermanagement/InvalidPasswordException.java @@ -1,4 +1,4 @@ -package io.flowinquiry.modules.usermanagement.web.rest.errors; +package io.flowinquiry.modules.usermanagement; import io.flowinquiry.exceptions.UserException; diff --git a/commons/src/main/java/io/flowinquiry/modules/usermanagement/service/EmailAlreadyUsedException.java b/commons/src/main/java/io/flowinquiry/modules/usermanagement/service/EmailAlreadyUsedException.java deleted file mode 100644 index 36a7847..0000000 --- a/commons/src/main/java/io/flowinquiry/modules/usermanagement/service/EmailAlreadyUsedException.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.flowinquiry.modules.usermanagement.service; - -public class EmailAlreadyUsedException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public EmailAlreadyUsedException() { - super("Email is already in use!"); - } -} diff --git a/commons/src/main/java/io/flowinquiry/modules/usermanagement/service/InvalidPasswordException.java b/commons/src/main/java/io/flowinquiry/modules/usermanagement/service/InvalidPasswordException.java deleted file mode 100644 index 055aadb..0000000 --- a/commons/src/main/java/io/flowinquiry/modules/usermanagement/service/InvalidPasswordException.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.flowinquiry.modules.usermanagement.service; - -public class InvalidPasswordException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public InvalidPasswordException() { - super("Incorrect password"); - } -} diff --git a/commons/src/main/java/io/flowinquiry/modules/usermanagement/service/UserService.java b/commons/src/main/java/io/flowinquiry/modules/usermanagement/service/UserService.java index f58c8fd..a513dde 100644 --- a/commons/src/main/java/io/flowinquiry/modules/usermanagement/service/UserService.java +++ b/commons/src/main/java/io/flowinquiry/modules/usermanagement/service/UserService.java @@ -4,6 +4,8 @@ import io.flowinquiry.exceptions.ResourceNotFoundException; import io.flowinquiry.modules.usermanagement.AuthoritiesConstants; +import io.flowinquiry.modules.usermanagement.EmailAlreadyUsedException; +import io.flowinquiry.modules.usermanagement.InvalidPasswordException; import io.flowinquiry.modules.usermanagement.domain.Authority; import io.flowinquiry.modules.usermanagement.domain.Permission; import io.flowinquiry.modules.usermanagement.domain.User; diff --git a/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/LoginController.java b/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/LoginController.java index 0300ed9..2a678f9 100644 --- a/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/LoginController.java +++ b/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/LoginController.java @@ -5,11 +5,11 @@ import static io.flowinquiry.security.SecurityUtils.USER_ID; import com.fasterxml.jackson.annotation.JsonProperty; +import io.flowinquiry.modules.usermanagement.InvalidLoginException; import io.flowinquiry.modules.usermanagement.repository.UserRepository; import io.flowinquiry.modules.usermanagement.service.UserService; import io.flowinquiry.modules.usermanagement.service.dto.FwUserDetails; import io.flowinquiry.modules.usermanagement.service.dto.UserDTO; -import io.flowinquiry.modules.usermanagement.web.rest.errors.InvalidLoginException; import jakarta.validation.Valid; import java.time.Instant; import java.time.LocalDateTime; diff --git a/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/PublicUserController.java b/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/PublicUserController.java index b678923..d29e58e 100644 --- a/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/PublicUserController.java +++ b/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/PublicUserController.java @@ -2,13 +2,13 @@ import io.flowinquiry.modules.fss.service.StorageService; import io.flowinquiry.modules.usermanagement.AuthoritiesConstants; +import io.flowinquiry.modules.usermanagement.EmailAlreadyUsedException; import io.flowinquiry.modules.usermanagement.domain.User; import io.flowinquiry.modules.usermanagement.repository.UserRepository; import io.flowinquiry.modules.usermanagement.service.UserService; import io.flowinquiry.modules.usermanagement.service.dto.ResourcePermissionDTO; import io.flowinquiry.modules.usermanagement.service.dto.UserDTO; import io.flowinquiry.modules.usermanagement.service.dto.UserHierarchyDTO; -import io.flowinquiry.modules.usermanagement.web.rest.errors.EmailAlreadyUsedException; import io.flowinquiry.query.Filter; import io.flowinquiry.query.QueryDTO; import io.flowinquiry.utils.Obfuscator; diff --git a/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/UserAccountController.java b/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/UserAccountController.java index 522643b..1712ed3 100644 --- a/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/UserAccountController.java +++ b/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/UserAccountController.java @@ -1,6 +1,8 @@ package io.flowinquiry.modules.usermanagement.web.rest; import io.flowinquiry.modules.collab.service.MailService; +import io.flowinquiry.modules.usermanagement.EmailAlreadyUsedException; +import io.flowinquiry.modules.usermanagement.InvalidPasswordException; import io.flowinquiry.modules.usermanagement.domain.User; import io.flowinquiry.modules.usermanagement.repository.UserRepository; import io.flowinquiry.modules.usermanagement.service.UserService; @@ -8,8 +10,6 @@ import io.flowinquiry.modules.usermanagement.service.dto.UserDTO; import io.flowinquiry.modules.usermanagement.service.dto.UserKey; import io.flowinquiry.modules.usermanagement.service.mapper.UserMapper; -import io.flowinquiry.modules.usermanagement.web.rest.errors.EmailAlreadyUsedException; -import io.flowinquiry.modules.usermanagement.web.rest.errors.InvalidPasswordException; import io.flowinquiry.security.SecurityUtils; import jakarta.validation.Valid; import jakarta.validation.constraints.Email; diff --git a/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/errors/ExceptionStatusMapper.java b/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/errors/ExceptionStatusMapper.java index 4a2a542..b38a2b0 100644 --- a/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/errors/ExceptionStatusMapper.java +++ b/commons/src/main/java/io/flowinquiry/modules/usermanagement/web/rest/errors/ExceptionStatusMapper.java @@ -3,10 +3,14 @@ import io.flowinquiry.exceptions.ResourceConstraintException; import io.flowinquiry.exceptions.ResourceNotFoundException; import io.flowinquiry.exceptions.UserException; +import io.flowinquiry.modules.usermanagement.EmailAlreadyUsedException; +import io.flowinquiry.modules.usermanagement.InvalidLoginException; +import io.flowinquiry.modules.usermanagement.InvalidPasswordException; import java.util.HashMap; import java.util.Map; import org.springframework.http.HttpStatus; import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.core.AuthenticationException; import org.springframework.web.server.ResponseStatusException; @@ -19,8 +23,10 @@ public class ExceptionStatusMapper { // Populate the map with exception-to-status mappings exceptionToStatusMap.put(IllegalArgumentException.class, HttpStatus.BAD_REQUEST); exceptionToStatusMap.put(InvalidLoginException.class, HttpStatus.BAD_REQUEST); + exceptionToStatusMap.put(InvalidPasswordException.class, HttpStatus.BAD_REQUEST); exceptionToStatusMap.put(EmailAlreadyUsedException.class, HttpStatus.BAD_REQUEST); exceptionToStatusMap.put(UserException.class, HttpStatus.BAD_REQUEST); + exceptionToStatusMap.put(BadCredentialsException.class, HttpStatus.UNAUTHORIZED); exceptionToStatusMap.put(AccessDeniedException.class, HttpStatus.FORBIDDEN); exceptionToStatusMap.put(AuthenticationException.class, HttpStatus.UNAUTHORIZED); exceptionToStatusMap.put(ResponseStatusException.class, HttpStatus.NOT_FOUND);