保誠-保戶業務員媒合平台
wayne
2021-11-12 55bfb3e3ac2cea5443320dfea61a0ed153bb4e84
[add] todo#126591: e-service, otp登入流程

尚未開給前端規格,以及處理後續流程,目前只發request給otp server和e-service
修改5個檔案
新增10個檔案
464 ■■■■■ 已變更過的檔案
pamapi/.gitignore 1 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/pom.xml 32 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/config/ApplicationProperties.java 40 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/config/SecurityConfiguration.java 1 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/LoginService.java 85 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/dto/EServiceRequest.java 50 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/dto/EServiceResponse.java 72 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/dto/OtpResponseDTO.java 36 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/web/rest/LoginResource.java 71 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/web/rest/vm/EServiceRequestVM.java 22 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/web/rest/vm/OtpEmailLoginVM.java 13 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/web/rest/vm/OtpSMSLoginVM.java 13 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/web/rest/vm/VerifyOtpVM.java 22 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/resources/config/application-dev.yml 6 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/resources/lib/pcalife-otp.jar 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/.gitignore
@@ -94,6 +94,7 @@
*.war
*.ear
*.db
!pcalife-otp.jar
######################
# Windows
pamapi/pom.xml
@@ -320,6 +320,37 @@
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-messaging</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.rpc</groupId>
            <artifactId>javax.xml.rpc-api</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.5</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>com.pcalife.otp</groupId>
            <artifactId>pollex</artifactId>
            <version>1.1.0</version>
            <scope>system</scope>
            <systemPath>${basedir}/src/main/resources/lib/pcalife-otp.jar</systemPath>
        </dependency>
        <!-- jhipster-needle-maven-add-dependency -->
    </dependencies>
@@ -829,6 +860,7 @@
                        </execution>
                    </executions>
                    <configuration>
                        <includeSystemScope>true</includeSystemScope>
                        <mainClass>${start-class}</mainClass>
                        <fork>true</fork>
                        <!--
pamapi/src/main/java/com/pollex/pam/config/ApplicationProperties.java
@@ -9,4 +9,42 @@
 * See {@link tech.jhipster.config.JHipsterProperties} for a good example.
 */
@ConfigurationProperties(prefix = "application", ignoreUnknownFields = false)
public class ApplicationProperties {}
public class ApplicationProperties {
    private String otpWebServiceUrl;
    private String otpWebServicePassword;
    private String otpWebServiceSystemType;
    private String eServiceLoginUrl;
    public String getOtpWebServiceUrl() {
        return otpWebServiceUrl;
    }
    public void setOtpWebServiceUrl(String otpWebServiceUrl) {
        this.otpWebServiceUrl = otpWebServiceUrl;
    }
    public String getOtpWebServicePassword() {
        return otpWebServicePassword;
    }
    public void setOtpWebServicePassword(String otpWebServicePassword) {
        this.otpWebServicePassword = otpWebServicePassword;
    }
    public String getOtpWebServiceSystemType() {
        return otpWebServiceSystemType;
    }
    public void setOtpWebServiceSystemType(String otpWebServiceSystemType) {
        this.otpWebServiceSystemType = otpWebServiceSystemType;
    }
    public String geteServiceLoginUrl() {
        return eServiceLoginUrl;
    }
    public void seteServiceLoginUrl(String eServiceLoginUrl) {
        this.eServiceLoginUrl = eServiceLoginUrl;
    }
}
pamapi/src/main/java/com/pollex/pam/config/SecurityConfiguration.java
@@ -81,6 +81,7 @@
            .antMatchers("/api/authenticate").permitAll()
            .antMatchers("/api/register").permitAll()
            .antMatchers("/api/activate").permitAll()
            .antMatchers("/api/testLogin/**").permitAll()
            .antMatchers("/api/account/reset-password/init").permitAll()
            .antMatchers("/api/account/reset-password/finish").permitAll()
            .antMatchers("/api/consultant/recommend").permitAll()
pamapi/src/main/java/com/pollex/pam/service/LoginService.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,85 @@
package com.pollex.pam.service;
import com.fasterxml.jackson.databind.ObjectMapper;;
import com.pollex.pam.config.ApplicationProperties;
import com.pollex.pam.service.dto.EServiceRequest;
import com.pollex.pam.web.rest.vm.EServiceRequestVM;
import com.pollex.pam.service.dto.EServiceResponse;
import com.pollex.pam.web.rest.vm.OtpEmailLoginVM;
import com.pollex.pam.web.rest.vm.OtpSMSLoginVM;
import com.pollex.pam.web.rest.vm.VerifyOtpVM;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.springframework.http.*;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import javax.net.ssl.SSLContext;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
@Service
public class LoginService {
    private final ApplicationProperties applicationProperties;
    public LoginService(ApplicationProperties applicationProperties) {
        this.applicationProperties = applicationProperties;
    }
    public void otpLoginByPhone(OtpSMSLoginVM login) {
    }
    public void otpLoginByEmail(OtpEmailLoginVM login) {
    }
    public void verifyOtp(VerifyOtpVM verifyOtpParam) {
        // todo è¦è·Ÿä¿èª otp的認證
        // å‡è¨­æˆåŠŸäº†ï¼ŒDB的確認
    }
    public ResponseEntity<EServiceResponse> loginByEService(EServiceRequestVM param) throws Exception{
        EServiceRequest dto = new EServiceRequest();
        dto.setFunc("ValidateUserLogin");
        dto.setId(param.getUsername());
        dto.setPin(param.getPassword());
        dto.setPwd(param.getPassword());
        dto.setSys("epos");
        String dtoJson = new ObjectMapper().writeValueAsString(dto);
        RestTemplate restTemplate = getTrustAllRestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<String> entity = new HttpEntity<>(dtoJson, headers);
        return restTemplate.exchange(applicationProperties.geteServiceLoginUrl(), HttpMethod.POST, entity, EServiceResponse.class);
    }
    private RestTemplate getTrustAllRestTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
        SSLContext sslContext = SSLContexts.custom()
            .loadTrustMaterial(null, (X509Certificate[] x509Certs, String s) -> true)
            .build();
        SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
        CloseableHttpClient httpClient = HttpClients.custom()
            .setSSLSocketFactory(csf)
            .build();
        HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
        requestFactory.setHttpClient(httpClient);
        requestFactory.setConnectTimeout(300000);
        requestFactory.setReadTimeout(300000);
        return new RestTemplate(requestFactory);
    }
}
pamapi/src/main/java/com/pollex/pam/service/dto/EServiceRequest.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,50 @@
package com.pollex.pam.service.dto;
public class EServiceRequest {
    private String func;
    private String id;
    private String pin;
    private String pwd;
    private String sys;
    public String getFunc() {
        return func;
    }
    public void setFunc(String func) {
        this.func = func;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getPin() {
        return pin;
    }
    public void setPin(String pin) {
        this.pin = pin;
    }
    public String getPwd() {
        return pwd;
    }
    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
    public String getSys() {
        return sys;
    }
    public void setSys(String sys) {
        this.sys = sys;
    }
}
pamapi/src/main/java/com/pollex/pam/service/dto/EServiceResponse.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,72 @@
package com.pollex.pam.service.dto;
import java.util.List;
public class EServiceResponse {
    private String issuccess;
    private String code;
    private String msg;
    List<EServiceData> data;
    public String getIssuccess() {
        return issuccess;
    }
    public void setIssuccess(String issuccess) {
        this.issuccess = issuccess;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getMsg() {
        return msg;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }
    public List<EServiceData> getData() {
        return data;
    }
    public void setData(List<EServiceData> data) {
        this.data = data;
    }
}
class EServiceData {
    private String usr;
    private String isactive;
    private String role;
    public String getUsr() {
        return usr;
    }
    public void setUsr(String usr) {
        this.usr = usr;
    }
    public String getIsactive() {
        return isactive;
    }
    public void setIsactive(String isactive) {
        this.isactive = isactive;
    }
    public String getRole() {
        return role;
    }
    public void setRole(String role) {
        this.role = role;
    }
}
pamapi/src/main/java/com/pollex/pam/service/dto/OtpResponseDTO.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,36 @@
package com.pollex.pam.service.dto;
public class OtpResponseDTO {
    private final String indexKey;
    private final boolean success;
    private final String failCode;
    private final String failReason;
    public OtpResponseDTO(String[] strings) {
        if(strings.length == 4) {
            this.indexKey = strings[0];
            this.success = "0".equals(strings[1]);
            this.failCode = strings[2];
            this.failReason = strings[3];
        }
        else {
            throw new RuntimeException("the otp response can't format");
        }
    }
    public String getIndexKey() {
        return indexKey;
    }
    public boolean isSuccess() {
        return success;
    }
    public String getFailCode() {
        return failCode;
    }
    public String getFailReason() {
        return failReason;
    }
}
pamapi/src/main/java/com/pollex/pam/web/rest/LoginResource.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,71 @@
package com.pollex.pam.web.rest;
import com.pollex.pam.config.ApplicationProperties;
import com.pollex.pam.service.LoginService;
import com.pollex.pam.service.dto.OtpResponseDTO;
import com.pollex.pam.web.rest.vm.EServiceRequestVM;
import com.pollex.pam.service.dto.EServiceResponse;
import com.pollex.pam.web.rest.vm.OtpEmailLoginVM;
import com.pollex.pam.web.rest.vm.OtpSMSLoginVM;
import com.pollex.pam.web.rest.vm.VerifyOtpVM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import tw.com.softleader.otp.ws.OtpWebServiceLocator;
import tw.com.softleader.otp.ws.OtpWebServicePortBindingStub;
import javax.xml.rpc.ServiceException;
import java.rmi.RemoteException;
@RestController
@RequestMapping("/api/testLogin")
public class LoginResource {
    private final static Logger log = LoggerFactory.getLogger(LoginResource.class);
    private final LoginService loginService;
    private final ApplicationProperties applicationProperty;
    public LoginResource(LoginService loginService, ApplicationProperties applicationProperty) {
        this.loginService = loginService;
        this.applicationProperty = applicationProperty;
    }
    @PostMapping("/bySMS")
    public ResponseEntity<OtpResponseDTO> sendOtpBySMS(@RequestBody OtpSMSLoginVM login) throws ServiceException, RemoteException {
        OtpWebServiceLocator locator = new OtpWebServiceLocator();
        locator.setOtpWebServicePortEndpointAddress(applicationProperty.getOtpWebServiceUrl());
        OtpWebServicePortBindingStub otpWebServicePort = (OtpWebServicePortBindingStub) locator.getOtpWebServicePort();
        String[] result =
            otpWebServicePort.sendOtpBySMS(applicationProperty.getOtpWebServicePassword(), applicationProperty.getOtpWebServiceSystemType(), login.getPhone());
        return new ResponseEntity<>(new OtpResponseDTO(result), HttpStatus.OK);
    }
    @PostMapping("/byEmail")
    public ResponseEntity<OtpResponseDTO> sendOtpByEmail(@RequestBody OtpEmailLoginVM login) throws RemoteException, ServiceException {
        OtpWebServiceLocator locator = new OtpWebServiceLocator();
        locator.setOtpWebServicePortEndpointAddress(applicationProperty.getOtpWebServiceUrl());
        OtpWebServicePortBindingStub otpWebServicePort = (OtpWebServicePortBindingStub) locator.getOtpWebServicePort();
        String[] result =
            otpWebServicePort.sendOtpByEmail(applicationProperty.getOtpWebServicePassword(), applicationProperty.getOtpWebServiceSystemType(), login.getEmail());
        return new ResponseEntity<>(new OtpResponseDTO(result), HttpStatus.OK);
    }
    // todo: é€™è£¡æœƒçµ¦äºˆæª¢æ ¸é€šéŽçš„jwt
    @PostMapping("/verifyOtp")
    public void verifyOtp(@RequestBody VerifyOtpVM verifyOtpParam) {
        OtpWebServiceLocator locator = new OtpWebServiceLocator();
    }
    // todo: é€™è£¡æœƒçµ¦äºˆæª¢æ ¸é€šéŽçš„jwt
    @PostMapping("/byEService")
    public ResponseEntity<EServiceResponse> loginByEService(@RequestBody EServiceRequestVM param) throws Exception {
        return loginService.loginByEService(param);
    }
}
pamapi/src/main/java/com/pollex/pam/web/rest/vm/EServiceRequestVM.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,22 @@
package com.pollex.pam.web.rest.vm;
public class EServiceRequestVM {
    private String username;
    private String password;
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
}
pamapi/src/main/java/com/pollex/pam/web/rest/vm/OtpEmailLoginVM.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,13 @@
package com.pollex.pam.web.rest.vm;
public class OtpEmailLoginVM {
    private String email;
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
}
pamapi/src/main/java/com/pollex/pam/web/rest/vm/OtpSMSLoginVM.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,13 @@
package com.pollex.pam.web.rest.vm;
public class OtpSMSLoginVM {
    private String phone;
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
}
pamapi/src/main/java/com/pollex/pam/web/rest/vm/VerifyOtpVM.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,22 @@
package com.pollex.pam.web.rest.vm;
public class VerifyOtpVM {
    private String identityCode;
    private String otpCode;
    public String getIdentityCode() {
        return identityCode;
    }
    public void setIdentityCode(String identityCode) {
        this.identityCode = identityCode;
    }
    public String getOtpCode() {
        return otpCode;
    }
    public void setOtpCode(String otpCode) {
        this.otpCode = otpCode;
    }
}
pamapi/src/main/resources/config/application-dev.yml
@@ -110,4 +110,8 @@
# https://www.jhipster.tech/common-application-properties/
# ===================================================================
# application:
application:
  otp-web-service-url: https://vtwlifeopensyssit.pru.intranet.asia:443/pcalife-otp/ws/otpWebService
  otp-web-service-password: es20!%Pass
  otp-web-service-system-type: epos
  e-service-login-url: https://ssotwsit.eservice.pcalife.com.tw/sso/acctValidate
pamapi/src/main/resources/lib/pcalife-otp.jar
Binary files differ