com.ehsbe.commons.gui.util
Class JxHostnameVerifier
java.lang.Object
com.ehsbe.commons.util.LocalHostnameVerifier
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 TrustManager
s. 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
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
JxHostnameVerifier
public JxHostnameVerifier()
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
.
Copyright ©2005-2009 EHSBE, Walther-Rathenau-Str. 58, 39104 Magdeburg, Sachsen-Anhalt, Germany. All Rights Reserved.