| | |
| | | |
| | | import com.pollex.pam.config.ApplicationProperties; |
| | | import com.pollex.pam.security.jwt.TokenProvider; |
| | | import com.pollex.pam.service.LoginRecordService; |
| | | import com.pollex.pam.service.OtpWebService; |
| | | import com.pollex.pam.service.dto.EServiceResponse; |
| | | import com.pollex.pam.service.dto.OtpResponseDTO; |
| | | import com.pollex.pam.business.service.dto.EServiceResponse; |
| | | import com.pollex.pam.business.service.dto.OtpResponseDTO; |
| | | import org.apache.http.conn.ssl.NoopHostnameVerifier; |
| | | import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
| | | import org.apache.http.impl.client.CloseableHttpClient; |
| | |
| | | private final static Logger log = LoggerFactory.getLogger(TestLoginResource.class); |
| | | |
| | | @Autowired |
| | | LoginRecordService loginRecordService; |
| | | |
| | | @Autowired |
| | | ApplicationProperties applicationProperty; |
| | | |
| | | @Autowired |
| | |
| | | return new ResponseEntity<>(otpResponseDTO, HttpStatus.OK); |
| | | } |
| | | |
| | | @GetMapping("/byEService") |
| | | public ResponseEntity<EServiceResponse> loginByEService(@RequestParam("account") String account, @RequestParam("password") String password) throws Exception { |
| | | RestTemplate restTemplate = getTrustAllRestTemplate(); |
| | | settingMessageConvertesToSpecifyType(restTemplate, MediaType.ALL); |
| | | // @GetMapping("/byEService") |
| | | // public ResponseEntity<EServiceResponse> loginByEService(@RequestParam("account") String account, @RequestParam("password") String password) throws Exception { |
| | | // RestTemplate restTemplate = getTrustAllRestTemplate(); |
| | | // settingMessageConvertesToSpecifyType(restTemplate, MediaType.ALL); |
| | | // |
| | | // String urlTemplate = UriComponentsBuilder.fromHttpUrl(applicationProperty.geteServiceLoginUrl()) |
| | | // .queryParam("func", applicationProperty.geteServiceLoginFunc()) |
| | | // .queryParam("id", account) |
| | | // .queryParam("pin", password) |
| | | // .queryParam("pwd", password) |
| | | // .queryParam("sys", applicationProperty.geteServiceLoginSys()) |
| | | // .queryParam("transactionId", UUID.randomUUID().toString()) |
| | | // .encode().toUriString(); |
| | | // |
| | | // log.debug("http get loginByEService, url = {}", urlTemplate); |
| | | // |
| | | // HttpHeaders headers = new HttpHeaders(); |
| | | // headers.setContentType(MediaType.APPLICATION_JSON); |
| | | // |
| | | // HttpEntity<String> entity = new HttpEntity<>(headers); |
| | | // return restTemplate.exchange(urlTemplate, HttpMethod.GET, entity, EServiceResponse.class); |
| | | // } |
| | | |
| | | String urlTemplate = UriComponentsBuilder.fromHttpUrl(applicationProperty.geteServiceLoginUrl()) |
| | | .queryParam("func", applicationProperty.geteServiceLoginFunc()) |
| | | .queryParam("id", account) |
| | | .queryParam("pin", password) |
| | | .queryParam("pwd", password) |
| | | .queryParam("sys", applicationProperty.geteServiceLoginSys()) |
| | | .queryParam("transactionId", UUID.randomUUID().toString()) |
| | | .encode().toUriString(); |
| | | // private void settingMessageConvertesToSpecifyType(RestTemplate restTemplate, MediaType mediaType) { |
| | | // List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); |
| | | // MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); |
| | | // converter.setSupportedMediaTypes(Collections.singletonList(mediaType)); |
| | | // messageConverters.add(converter); |
| | | // restTemplate.setMessageConverters(messageConverters); |
| | | // } |
| | | |
| | | log.debug("http get loginByEService, url = {}", urlTemplate); |
| | | |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | |
| | | HttpEntity<String> entity = new HttpEntity<>(headers); |
| | | return restTemplate.exchange(urlTemplate, HttpMethod.GET, entity, EServiceResponse.class); |
| | | } |
| | | |
| | | private void settingMessageConvertesToSpecifyType(RestTemplate restTemplate, MediaType mediaType) { |
| | | List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); |
| | | MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); |
| | | converter.setSupportedMediaTypes(Collections.singletonList(mediaType)); |
| | | messageConverters.add(converter); |
| | | restTemplate.setMessageConverters(messageConverters); |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | // 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); |
| | | // } |
| | | } |