ehsbe CommonsTM
Version 1.1.0rc3

com.ehsbe.commons.gui.util
Class JxHostnameVerifier

java.lang.Object
  extended by com.ehsbe.commons.util.LocalHostnameVerifier
      extended by com.ehsbe.commons.gui.util.JxHostnameVerifier
All Implemented Interfaces:
HostnameVerifier

public class JxHostnameVerifier
extends LocalHostnameVerifier

A Hostname verifier, which lets the user choose, whether to accept a connection, even if the received certificate's common name does not match the hostname of the url connection (i.e. does not belong to the host).

Activated by HttpsURLConnection.setDefaultHostnameVerifier($JxHostnameVerifier)

NOTE: A pre-requisit to get this dialog fired up is, that the certificate of the given host has been accepted by the SSLSocketFactory of the related connection. For unknown certificates one probably wants to initialize the default SSLFactory with its own TrustManagers. E.g.


        TrustManager[] localTM = new TrustManager[] {
                new LocalTrustManager(crtPath, new InvalidCertHandler() {
                        public boolean accept(X509Certificate[] chain, 
                                CertificateException ex)
                        {
                                return true;
                        }
                })
        };
        SSLContext = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        HttpsURLConnection.setDefaultHostnameVerifier(new JxHostnameVerifier());
Of course, your TrustManager(s) should not accept all certificates blindly!

Version:
$Revision: 463 $
Author:
Jens Elkner
See Also:
LocalHostnameVerifier, JxX509CertPanel

Nested Class Summary
 
Nested classes/interfaces inherited from class com.ehsbe.commons.util.LocalHostnameVerifier
LocalHostnameVerifier.VerifyResult
 
Constructor Summary
JxHostnameVerifier()
           
 
Method Summary
 boolean verify(String hostname, SSLSession session)
          If URLConnection.getAllowUserInteraction() is true, a dialog gets displayed, which asks the user, whether to accept the connection.
 
Methods inherited from class com.ehsbe.commons.util.LocalHostnameVerifier
verify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JxHostnameVerifier

public JxHostnameVerifier()
Method Detail

verify

public boolean verify(String hostname,
                      SSLSession session)
If URLConnection.getAllowUserInteraction() is true, a dialog gets displayed, which asks the user, whether to accept the connection.

Specified by:
verify in interface HostnameVerifier
Overrides:
verify in class LocalHostnameVerifier
Parameters:
hostname -
session -
Returns:
false, if the connection should be discarded or URLConnection.getAllowUserInteraction() returned false.

ehsbe CommonsTM
Version 1.1.0rc3

Copyright ©2005-2009 EHSBE, Walther-Rathenau-Str. 58, 39104 Magdeburg, Sachsen-Anhalt, Germany. All Rights Reserved.