Search in sources :

Example 1 with XKMSLocateException

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);
    }
}
Also used : XKMSLocateException(org.apache.cxf.xkms.exception.XKMSLocateException) LocateResultType(org.apache.cxf.xkms.model.xkms.LocateResultType) LocateRequestType(org.apache.cxf.xkms.model.xkms.LocateRequestType)

Example 2 with XKMSLocateException

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);
    }
}
Also used : X509DataType(org.apache.cxf.xkms.model.xmldsig.X509DataType) XKMSLocateException(org.apache.cxf.xkms.exception.XKMSLocateException) ByteArrayInputStream(java.io.ByteArrayInputStream) XKMSException(org.apache.cxf.xkms.exception.XKMSException) CertificateException(java.security.cert.CertificateException) JAXBElement(javax.xml.bind.JAXBElement) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) KeyInfoType(org.apache.cxf.xkms.model.xmldsig.KeyInfoType)

Aggregations

XKMSLocateException (org.apache.cxf.xkms.exception.XKMSLocateException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 CertificateException (java.security.cert.CertificateException)1 CertificateFactory (java.security.cert.CertificateFactory)1 X509Certificate (java.security.cert.X509Certificate)1 JAXBElement (javax.xml.bind.JAXBElement)1 XKMSException (org.apache.cxf.xkms.exception.XKMSException)1 LocateRequestType (org.apache.cxf.xkms.model.xkms.LocateRequestType)1 LocateResultType (org.apache.cxf.xkms.model.xkms.LocateResultType)1 KeyInfoType (org.apache.cxf.xkms.model.xmldsig.KeyInfoType)1 X509DataType (org.apache.cxf.xkms.model.xmldsig.X509DataType)1