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 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 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 loginByEService(@RequestParam("account") String account, @RequestParam("password") String password) throws Exception { return loginService.loginByEService(account, password); } }