| | |
| | | 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與EServiceResource,主要是用這兩個做登入 |
| | | @Deprecated |
| | | @RestController |
| | | @RequestMapping("/api/testLogin") |
| | | public class TestLoginResource { |
| | |
| | | |
| | | @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") |