From a8b21cd919b76a548b77ef0ec2d8aee28c8e6b0e Mon Sep 17 00:00:00 2001 From: wayne <wayne8692wayne8692@gmail.com> Date: 星期二, 23 十一月 2021 10:41:56 +0800 Subject: [PATCH] [update] 修正發送OTP api,將兩個發送方式並成同一個 --- pamapi/src/main/java/com/pollex/pam/web/rest/TestLoginResource.java | 32 ++++++++++++++++---------------- 1 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pamapi/src/main/java/com/pollex/pam/web/rest/TestLoginResource.java b/pamapi/src/main/java/com/pollex/pam/web/rest/TestLoginResource.java index 07691a3..ae4d394 100644 --- a/pamapi/src/main/java/com/pollex/pam/web/rest/TestLoginResource.java +++ b/pamapi/src/main/java/com/pollex/pam/web/rest/TestLoginResource.java @@ -19,10 +19,14 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; +import tw.com.softleader.otp.ws.OtpWebServicePortBindingStub; import javax.xml.rpc.ServiceException; import java.rmi.RemoteException; + +// todo嚗����login�靘蹂蝙��get��撘�嚗��歇��OtpResource��ServiceResource嚗蜓閬����� +@Deprecated @RestController @RequestMapping("/api/testLogin") public class TestLoginResource { @@ -46,30 +50,26 @@ @GetMapping("/bySMS") public ResponseEntity<OtpResponseDTO> sendOtpBySMS(@RequestParam("phone") String phone) throws ServiceException, RemoteException { - otpWebService.sendByPhone(phone); - return new ResponseEntity<>(HttpStatus.OK); + final OtpResponseDTO otpResponseDTO = otpWebService.sendByPhone(phone); + return new ResponseEntity<>(otpResponseDTO, HttpStatus.OK); } @GetMapping("/byEmail") public ResponseEntity<OtpResponseDTO> sendOtpByEmail(@RequestParam("email") String email) throws RemoteException, ServiceException { - otpWebService.sendByEmail(email); - return new ResponseEntity<>(HttpStatus.OK); + final OtpResponseDTO otpResponseDTO = otpWebService.sendByEmail(email); + return new ResponseEntity<>(otpResponseDTO, HttpStatus.OK); } @GetMapping("/verifyOtp") - public ResponseEntity<UserJWTController.JWTToken> verifyOtp(@RequestParam("account") String account, @RequestParam("indexKey") String indexKey, @RequestParam("otpCode") String otpCode) throws ServiceException, RemoteException { - OtpAccount otpAccount = new OtpAccount(account, indexKey); - OtpAuthenticationToken authenticationToken = new OtpAuthenticationToken( - otpAccount, - otpCode - ); + public ResponseEntity<OtpResponseDTO> verifyOtp(@RequestParam("account") String account, @RequestParam("indexKey") String indexKey, @RequestParam("otpCode") String otpCode) throws ServiceException, RemoteException { + OtpWebServicePortBindingStub stub = otpWebService.getOtpWebServicePortBindingStub(); + log.info("call OtpService verifyOTP, systemType = {}, service password = {}, indexKey = {}, paxxword = {}", + applicationProperty.getOtpWebServiceSystemType(), applicationProperty.getOtpWebServicePassword(), indexKey, otpCode); - Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken); - SecurityContextHolder.getContext().setAuthentication(authenticationToken); - String jwt = tokenProvider.createToken(authentication, false); - HttpHeaders httpHeaders = new HttpHeaders(); - httpHeaders.add(JWTFilter.AUTHORIZATION_HEADER, "Bearer" + jwt); - return new ResponseEntity<>(new UserJWTController.JWTToken(jwt), httpHeaders, HttpStatus.OK); + String[] result = + stub.verifyOtp(applicationProperty.getOtpWebServicePassword(), applicationProperty.getOtpWebServiceSystemType(), indexKey, otpCode); + + return new ResponseEntity<>(new OtpResponseDTO(result), HttpStatus.OK); } @GetMapping("/byEService") -- Gitblit v1.8.0