保誠-保戶業務員媒合平台
wayne
2021-11-19 4e54ae39c612c2995e3592121327fa79ded539a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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;
    }
 
    @GetMapping("/bySMS")
    public ResponseEntity<OtpResponseDTO> sendOtpBySMS(@RequestParam("phone") String phone) throws ServiceException, RemoteException {
        OtpWebServiceLocator locator = new OtpWebServiceLocator();
        locator.setOtpWebServicePortEndpointAddress(applicationProperty.getOtpWebServiceUrl());
 
        OtpWebServicePortBindingStub otpWebServicePort = (OtpWebServicePortBindingStub) locator.getOtpWebServicePort();
        String[] result =
            otpWebServicePort.sendOtpBySMS(applicationProperty.getOtpWebServicePassword(), applicationProperty.getOtpWebServiceSystemType(), phone);
 
        return new ResponseEntity<>(new OtpResponseDTO(result), HttpStatus.OK);
    }
 
    @GetMapping("/byEmail")
    public ResponseEntity<OtpResponseDTO> sendOtpByEmail(@RequestParam("email") String email) throws RemoteException, ServiceException {
        OtpWebServiceLocator locator = new OtpWebServiceLocator();
        locator.setOtpWebServicePortEndpointAddress(applicationProperty.getOtpWebServiceUrl());
 
        OtpWebServicePortBindingStub otpWebServicePort = (OtpWebServicePortBindingStub) locator.getOtpWebServicePort();
        String[] result =
            otpWebServicePort.sendOtpByEmail(applicationProperty.getOtpWebServicePassword(), applicationProperty.getOtpWebServiceSystemType(), email);
 
        return new ResponseEntity<>(new OtpResponseDTO(result), HttpStatus.OK);
    }
 
    // todo: 這裡移動到認證授權的provider
    @PostMapping("/verifyOtp")
    public void verifyOtp(@RequestBody VerifyOtpVM verifyOtpParam) {
        OtpWebServiceLocator locator = new OtpWebServiceLocator();
    }
 
    // todo: 這裡移動到認證授權的provider
    @GetMapping("/byEService")
    public ResponseEntity<EServiceResponse> loginByEService(@RequestParam("account") String account, @RequestParam("password") String password) throws Exception {
        return loginService.loginByEService(account, password);
    }
}