保誠-保戶業務員媒合平台
Mila
2021-11-30 4e5136bd4ab797bf1ad5f3332de86848e7db0c3d
pamapi/src/main/java/com/pollex/pam/security/provider/EServiceAuthenticationProvider.java
@@ -8,6 +8,7 @@
import com.pollex.pam.security.token.EServiceAuthenticationToken;
import com.pollex.pam.service.LoginRecordService;
import com.pollex.pam.service.dto.EServiceResponse;
import com.pollex.pam.web.rest.errors.EServiceErrorException;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -67,6 +68,7 @@
            ResponseEntity<EServiceResponse> responseEntity = loginByEService(account, credentials);
            if(HttpStatus.OK.equals(responseEntity.getStatusCode())) {
                EServiceResponse eServiceResponse = responseEntity.getBody();
                log.debug("eService response = {}", eServiceResponse);
                if(E_SERVICE_LOGIN_SUCCESS_CODE.equals(eServiceResponse.getCode())){
                    loginRecordService.saveEServiceLoginSuccessRecord(account);
@@ -74,20 +76,20 @@
                }
                else {
                    loginRecordService.saveEServiceLoginFailRecord(account, eServiceResponse.getMsg());
                    throw new RuntimeException("eService login failed, eService response code = " + eServiceResponse.getCode() + ", eService response msg = " + eServiceResponse.getMsg());
                    throw new EServiceErrorException(eServiceResponse.getMsg());
                }
            }
            throw new RuntimeException("eService http error!, response http status code = " + responseEntity.getStatusCode());
        } catch (JsonProcessingException e) {
            throw new AuthenticationServiceException("convert to json processing error!");
            throw new RuntimeException("convert to json processing error!");
        } catch (GeneralSecurityException e) {
            throw new AuthenticationServiceException("General Security SSL error!");
            throw new RuntimeException("General Security SSL error!");
        }
    }
    private UsernamePasswordAuthenticationToken getConsultantToken(String account, String credential) {
        Consultant consultant = consultantRepository.findOneByAgentNo(account).orElseThrow(() -> new UsernameNotFoundException("consultant is not in db, consultant agentNo = " + account));
        Consultant consultant = consultantRepository.findOneByAgentNo(account).orElseThrow(() -> new UsernameNotFoundException("該顧問資料並不存在於媒合平台系統中"));
        List<GrantedAuthority> grantedAuths = Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"));
        UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(account, credential, grantedAuths);