保誠-保戶業務員媒合平台
[UPDATE] 透過e service 登入時調整判斷錯誤的邏輯, 如果登入失敗的時候也需要從DB提取錯誤訊息顯示
修改1個檔案
新增1個檔案
修改1個檔案名稱
45 ■■■■ 已變更過的檔案
pamapi/src/doc/sql/20241227_j.sql 7 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/doc/sql/executed/20230803_j.sql 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java 38 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/doc/sql/20241227_j.sql
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,7 @@
-- ç‚ºäº†EService å›žå‚³çš„錯誤訊息可以在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)
);
pamapi/src/doc/sql/executed/20230803_j.sql
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());