Skip to content

Commit 04eb3e0

Browse files
author
Stephane Landelle
committed
DefaultHostnameVerifier should be using slf4j, not jul, close AsyncHttpClient#779
1 parent c835519 commit 04eb3e0

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/main/java/com/ning/http/util/DefaultHostnameVerifier.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66
*/
77
package com.ning.http.util;
88

9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
912
import javax.net.ssl.HostnameVerifier;
1013
import javax.net.ssl.SSLPeerUnverifiedException;
1114
import javax.net.ssl.SSLSession;
1215
import javax.security.auth.kerberos.KerberosPrincipal;
16+
1317
import java.security.Principal;
1418
import java.security.cert.Certificate;
1519
import java.security.cert.CertificateException;
1620
import java.security.cert.X509Certificate;
17-
import java.util.logging.Level;
18-
import java.util.logging.Logger;
1921

2022
/**
2123
* Uses the internal HostnameChecker to verify the server's hostname matches with the
@@ -36,7 +38,7 @@ public class DefaultHostnameVerifier implements HostnameVerifier {
3638
private HostnameVerifier extraHostnameVerifier;
3739

3840
// Logger to log exceptions.
39-
private static final Logger log = Logger.getLogger(DefaultHostnameVerifier.class.getName());
41+
private static final Logger log = LoggerFactory.getLogger(DefaultHostnameVerifier.class.getName());
4042

4143
/**
4244
* A hostname verifier that uses the {{sun.security.util.HostnameChecker}} under the hood.
@@ -83,42 +85,42 @@ public DefaultHostnameVerifier(HostnameChecker checker, HostnameVerifier extraHo
8385
* @return true if the hostname matches, false otherwise.
8486
*/
8587
private boolean hostnameMatches(String hostname, SSLSession session) {
86-
log.log(Level.FINE, "hostname = {0}, session = {1}", new Object[] { hostname, Base64.encode(session.getId()) });
88+
log.debug("hostname = {}, session = {}",hostname, Base64.encode(session.getId()));
8789

8890
try {
8991
final Certificate[] peerCertificates = session.getPeerCertificates();
9092
if (peerCertificates.length == 0) {
91-
log.log(Level.FINE, "No peer certificates");
93+
log.debug("No peer certificates");
9294
return false;
9395
}
9496

9597
if (peerCertificates[0] instanceof X509Certificate) {
9698
X509Certificate peerCertificate = (X509Certificate) peerCertificates[0];
97-
log.log(Level.FINE, "peerCertificate = {0}", peerCertificate);
99+
log.debug("peerCertificate = {0}", peerCertificate);
98100
try {
99101
checker.match(hostname, peerCertificate);
100102
// Certificate matches hostname if no exception is thrown.
101103
return true;
102104
} catch (CertificateException ex) {
103-
log.log(Level.FINE, "Certificate does not match hostname", ex);
105+
log.debug("Certificate does not match hostname", ex);
104106
}
105107
} else {
106-
log.log(Level.FINE, "Peer does not have any certificates or they aren't X.509");
108+
log.debug("Peer does not have any certificates or they aren't X.509");
107109
}
108110
return false;
109111
} catch (SSLPeerUnverifiedException ex) {
110-
log.log(Level.FINE, "Not using certificates for peers, try verifying the principal");
112+
log.debug("Not using certificates for peers, try verifying the principal");
111113
try {
112114
Principal peerPrincipal = session.getPeerPrincipal();
113-
log.log(Level.FINE, "peerPrincipal = {0}", peerPrincipal);
115+
log.debug("peerPrincipal = {0}", peerPrincipal);
114116
if (peerPrincipal instanceof KerberosPrincipal) {
115117
return checker.match(hostname, (KerberosPrincipal) peerPrincipal);
116118
} else {
117-
log.log(Level.FINE, "Can't verify principal, not Kerberos");
119+
log.debug("Can't verify principal, not Kerberos");
118120
}
119121
} catch (SSLPeerUnverifiedException ex2) {
120122
// Can't verify principal, no principal
121-
log.log(Level.FINE, "Can't verify principal, no principal", ex2);
123+
log.debug("Can't verify principal, no principal", ex2);
122124
}
123125
return false;
124126
}

0 commit comments

Comments
 (0)