use of org.apache.cxf.transport.http.UntrustedURLConnectionIOException in project cxf by apache.
the class CertConstraintsInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
final CertConstraints certConstraints = (CertConstraints) message.getContextualProperty(CertConstraints.class.getName());
if (certConstraints == null) {
return;
}
if (isRequestor(message)) {
try {
String scheme = (String) message.get("http.scheme");
if ("https".equals(scheme)) {
final MessageTrustDecider orig = message.get(MessageTrustDecider.class);
MessageTrustDecider trust = new HttpsMessageTrustDecider(certConstraints, orig);
message.put(MessageTrustDecider.class, trust);
} else {
throw new UntrustedURLConnectionIOException("TLS is not in use");
}
} catch (UntrustedURLConnectionIOException ex) {
throw new Fault(ex);
}
} else {
try {
TLSSessionInfo tlsInfo = message.get(TLSSessionInfo.class);
final Certificate[] certs = tlsInfo.getPeerCertificates();
if (certs == null || certs.length == 0) {
throw new UntrustedURLConnectionIOException("No client certificates were found");
}
X509Certificate[] x509Certs = (X509Certificate[]) certs;
if (!certConstraints.matches(x509Certs[0])) {
throw new UntrustedURLConnectionIOException("The client certificate does not match the defined cert constraints");
}
} catch (UntrustedURLConnectionIOException ex) {
throw new Fault(ex);
}
}
}
Aggregations