From 5e8b57aacdbf94cd57c4d3533ded5ee73ff71340 Mon Sep 17 00:00:00 2001 From: jack <jack.su@pollex.com.tw> Date: 星期五, 27 十二月 2024 14:43:28 +0800 Subject: [PATCH] [UPDATE] 透過e service 登入時調整判斷錯誤的邏輯, 如果登入失敗的時候也需要從DB提取錯誤訊息顯示 --- pamapi/src/doc/sql/20241227_j.sql | 7 +++++++ pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java | 38 +++++++++++++++++++++++++++++++++----- pamapi/src/doc/sql/executed/20230803_j.sql | 0 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/pamapi/src/doc/sql/20241227_j.sql b/pamapi/src/doc/sql/20241227_j.sql new file mode 100644 index 0000000..60c33a0 --- /dev/null +++ b/pamapi/src/doc/sql/20241227_j.sql @@ -0,0 +1,7 @@ +-- �鈭Service ����隤方��隞亙DB閮剖��銝*蝷箇��, ��迨�憓迨table-- +CREATE TABLE eservice_error_code ( + id bigserial NOT NULL, + error_code varchar(255) NOT null, + error_message varchar(255) NOT null, + PRIMARY KEY (id) +); diff --git a/pamapi/src/doc/sql/20230803_j.sql b/pamapi/src/doc/sql/executed/20230803_j.sql similarity index 100% rename from pamapi/src/doc/sql/20230803_j.sql rename to pamapi/src/doc/sql/executed/20230803_j.sql diff --git a/pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java b/pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java index d260f8e..1860b1b 100644 --- a/pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java +++ b/pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java @@ -3,6 +3,7 @@ import com.pollex.pam.business.domain.Consultant; import com.pollex.pam.business.enums.ConsultantDetailEnum; import com.pollex.pam.business.repository.ConsultantRepository; +import com.pollex.pam.business.repository.EServiceErrorCodeRepository; import com.pollex.pam.business.service.EServiceConnectService; import com.pollex.pam.business.service.dto.EServiceResponse; import com.pollex.pam.business.web.errors.ConsultantDisableException; @@ -25,6 +26,8 @@ import java.security.GeneralSecurityException; import java.util.*; +import static java.util.Arrays.asList; + @Component public class EServiceAuthenticationProvider { @@ -40,13 +43,19 @@ @Autowired EServiceConnectService eServiceConnectService; + @Autowired + EServiceErrorCodeRepository eServiceErrorCodeRepository; + public Authentication authenticate(EServiceAuthenticationToken authenticationToken) throws AuthenticationException { String account = authenticationToken.getPrincipal(); String credentials = authenticationToken.getCredentials(); + if(applicationProperties.isMockLogin()){ return getConsultantTokenAndRecordLoginTime(account, credentials); } + + try { ResponseEntity<EServiceResponse> responseEntity = eServiceConnectService.loginByEService(account, credentials); @@ -54,13 +63,32 @@ EServiceResponse eServiceResponse = responseEntity.getBody(); log.debug("eService response = {}", eServiceResponse); - if(E_SERVICE_LOGIN_SUCCESS_CODE.equals(eServiceResponse.getIssuccess())){ + if(eServiceResponse == null) { + throw new RuntimeException("eService error!, response body is null"); + } + + List<String> successCode = new ArrayList<>(asList("0","3","4","6")); + + if(successCode.contains(eServiceResponse.getCode())) { return getConsultantTokenAndRecordLoginTime(account, credentials); + } else { + log.debug("account:{},error:{}",account,eServiceResponse.getMsg()); + eServiceErrorCodeRepository.findByErrorCode(eServiceResponse.getCode()). + ifPresent(eServiceErrorCode -> { + throw new EServiceErrorException(eServiceErrorCode.getErrorMessage()); + }); + + throw new EServiceErrorException("�頛詨�����炊嚗��頛詨"); } - else { - log.debug("account:{},error:{}",account,eServiceResponse.getMsg()); - throw new EServiceErrorException("撣唾��Ⅳ�隤�"); - } + +// if(E_SERVICE_LOGIN_SUCCESS_CODE.equals(eServiceResponse.getIssuccess())){ +// +// return getConsultantTokenAndRecordLoginTime(account, credentials); +// } +// else { +// log.debug("account:{},error:{}",account,eServiceResponse.getMsg()); +// throw new EServiceErrorException("�頛詨�����炊嚗��頛詨"); +// } } throw new RuntimeException("eService http error!, response http status code = " + responseEntity.getStatusCode()); -- Gitblit v1.8.0