Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. String jwtUrl = "https://ABC.XYZ.COM:3333/api/auth";
  2. String username = "ABC";
  3. String password = "ABC";
  4.  
  5.  
  6. String userCredentials = username + ":" + password;
  7. String basicAuth = "Basic "
  8. + new String(org.apache.commons.codec.binary.Base64.encodeBase64(userCredentials.getBytes()));
  9.  
  10. HttpHeaders headers1 = new HttpHeaders();
  11. headers1.set("Authorization", basicAuth);
  12. HttpEntity httpEntity = new HttpEntity(headers1);
  13. ResponseEntity<String> responseEntity = restTemplate1.exchange(jwtUrl, HttpMethod.GET, httpEntity,
  14. String.class);
  15.  
  16. System.out.println("Response Body = " + responseEntity.getBody());
  17.  
  18. Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateEx
  19. ception: No name matching ABC.XYZ.COM found
  20. at sun.security.ssl.Alerts.getSSLException(Unknown Source)
  21. at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
  22. at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
  23. at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
  24. at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
  25. at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
  26. at sun.security.ssl.Handshaker.processLoop(Unknown Source)
  27. at sun.security.ssl.Handshaker.process_record(Unknown Source)
  28. at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
  29. at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source
  30. )
  31.  
  32. static {
  33. disableSslVerification();
  34. }
  35.  
  36. private static void disableSslVerification() {
  37. try {
  38. // Create a trust manager that does not validate certificate chains
  39. TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
  40. @Override
  41. public java.security.cert.X509Certificate[] getAcceptedIssuers() {
  42. return null;
  43. }
  44.  
  45. @Override
  46. public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
  47. // TODO Auto-generated method stub
  48.  
  49. }
  50.  
  51. @Override
  52. public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
  53. // TODO Auto-generated method stub
  54.  
  55. }
  56. } };
  57.  
  58. // Install the all-trusting trust manager
  59. SSLContext sc = SSLContext.getInstance("SSL");
  60. sc.init(null, trustAllCerts, new java.security.SecureRandom());
  61. HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
  62.  
  63. // Create all-trusting host name verifier
  64. HostnameVerifier allHostsValid = new HostnameVerifier() {
  65.  
  66. @Override
  67. public boolean verify(String hostname, SSLSession session) {
  68. // TODO Auto-generated method stub
  69. return false;
  70. }
  71. };
  72.  
  73. // Install the all-trusting host verifier
  74. HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
  75. } catch (NoSuchAlgorithmException e) {
  76. e.printStackTrace();
  77. } catch (KeyManagementException e) {
  78. e.printStackTrace();
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement