use of org.apache.cxf.xkms.exception.XKMSLocateException in project cxf by apache.
the class XKMSInvoker method getCertificate.
public X509Certificate getCertificate(List<X509AppId> ids) {
try {
LocateRequestType locateRequestType = prepareLocateXKMSRequest(ids);
LocateResultType locateResultType = xkmsConsumer.locate(locateRequestType);
return parseLocateXKMSResponse(locateResultType, ids);
} catch (RuntimeException e) {
String msg = String.format("XKMS locate call fails for certificate: %s. Error: %s", ids, e.getMessage());
LOG.warn(msg, e);
throw new XKMSLocateException(msg, e);
}
}
use of org.apache.cxf.xkms.exception.XKMSLocateException in project cxf by apache.
the class XKMSInvoker method parseLocateXKMSResponse.
@SuppressWarnings("unchecked")
protected X509Certificate parseLocateXKMSResponse(LocateResultType locateResultType, List<X509AppId> ids) {
XKMSException exception = ExceptionMapper.fromResponse(locateResultType);
if (exception != null) {
throw exception;
}
if (!locateResultType.getUnverifiedKeyBinding().iterator().hasNext()) {
LOG.warn("X509Certificate is not found in XKMS for id: " + ids);
return null;
}
KeyInfoType keyInfo = locateResultType.getUnverifiedKeyBinding().iterator().next().getKeyInfo();
if (!keyInfo.getContent().iterator().hasNext()) {
LOG.warn("X509Certificate is not found in XKMS for id: " + ids);
return null;
}
JAXBElement<X509DataType> x509Data = (JAXBElement<X509DataType>) keyInfo.getContent().iterator().next();
JAXBElement<byte[]> certificate = (JAXBElement<byte[]>) x509Data.getValue().getX509IssuerSerialOrX509SKIOrX509SubjectName().iterator().next();
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
return (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(certificate.getValue()));
} catch (CertificateException e) {
throw new XKMSLocateException(XKMS_LOCATE_INVALID_CERTIFICATE, e);
}
}
Aggregations