diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d55635e..059c9fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,7 +83,7 @@ jobs: - name: Deploy to GKE run: | kubectl set image deployment/security-service \ - security-service=docker.io/dockerforomar/micropay-security:latest + security-service=docker.io/dockerforomar/micropay-security:${{ github.sha }} kubectl rollout status deployment/security-service diff --git a/src/main/java/com/micropay/security/exception/handler/GlobalExceptionHandler.java b/src/main/java/com/micropay/security/exception/handler/GlobalExceptionHandler.java index 00de9ba..326af21 100644 --- a/src/main/java/com/micropay/security/exception/handler/GlobalExceptionHandler.java +++ b/src/main/java/com/micropay/security/exception/handler/GlobalExceptionHandler.java @@ -1,12 +1,10 @@ package com.micropay.security.exception.handler; -import com.micropay.security.exception.DuplicateObjectException; -import com.micropay.security.exception.InvalidTokenException; -import com.micropay.security.exception.NotActiveUserException; -import com.micropay.security.exception.UserNotFoundException; +import com.micropay.security.exception.*; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import com.micropay.security.dto.response.ErrorResponse; +import org.springframework.security.authentication.BadCredentialsException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @@ -78,4 +76,14 @@ public ResponseEntity handleInvalidTokenException(InvalidTokenExc return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(body); } + @ExceptionHandler(BadCredentialsException.class) + public ResponseEntity handleBadCredentialsException(BadCredentialsException exception) { + ErrorResponse body = new ErrorResponse( + HttpStatus.UNAUTHORIZED.value(), + exception.getMessage(), + LocalDateTime.now() + ); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(body); + } + } diff --git a/src/main/java/com/micropay/security/service/security/impl/PinManagementServiceImpl.java b/src/main/java/com/micropay/security/service/security/impl/PinManagementServiceImpl.java index e3ad8f2..48ce117 100644 --- a/src/main/java/com/micropay/security/service/security/impl/PinManagementServiceImpl.java +++ b/src/main/java/com/micropay/security/service/security/impl/PinManagementServiceImpl.java @@ -27,7 +27,7 @@ public String hashPin(String pin) { @Override public void checkPinMatching(String rawPin, String hashedPin) { if (!passwordEncoder.matches(rawPin, hashedPin)) { - throw new BadCredentialsException("Passwords do not match."); + throw new BadCredentialsException("Invalid PIN."); } }