Search in sources :

Example 1 with XKMSException

use of org.apache.cxf.xkms.exception.XKMSException in project cxf by apache.

the class XKMSInvoker method parseValidateXKMSResponse.

protected CertificateValidationResult parseValidateXKMSResponse(ValidateResultType validateResultType, String id) {
    XKMSException exception = ExceptionMapper.fromResponse(validateResultType);
    if (exception != null) {
        throw exception;
    }
    StatusType status = validateResultType.getKeyBinding().iterator().next().getStatus();
    if (KeyBindingEnum.HTTP_WWW_W_3_ORG_2002_03_XKMS_VALID != status.getStatusValue()) {
        return new CertificateValidationResult(false, XKMS_VALIDATE_ERROR);
    }
    return new CertificateValidationResult(true, null);
}
Also used : StatusType(org.apache.cxf.xkms.model.xkms.StatusType) XKMSException(org.apache.cxf.xkms.exception.XKMSException)

Example 2 with XKMSException

use of org.apache.cxf.xkms.exception.XKMSException 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)

Example 3 with XKMSException

use of org.apache.cxf.xkms.exception.XKMSException in project cxf by apache.

the class X509Locator method parse.

private List<UseKeyWithType> parse(LocateRequestType request) {
    List<UseKeyWithType> keyIDs = new ArrayList<>();
    if (request == null) {
        return keyIDs;
    }
    QueryKeyBindingType query = request.getQueryKeyBinding();
    if (query == null) {
        return keyIDs;
    }
    // http://www.w3.org/TR/xkms2/ [213]
    if (query.getTimeInstant() != null) {
        throw new XKMSException(ResultMajorEnum.HTTP_WWW_W_3_ORG_2002_03_XKMS_RECEIVER, ResultMinorEnum.HTTP_WWW_W_3_ORG_2002_03_XKMS_TIME_INSTANT_NOT_SUPPORTED);
    }
    keyIDs.addAll(parse(query.getKeyInfo()));
    List<UseKeyWithType> useKeyList = query.getUseKeyWith();
    keyIDs.addAll(useKeyList);
    return keyIDs;
}
Also used : XKMSException(org.apache.cxf.xkms.exception.XKMSException) UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) ArrayList(java.util.ArrayList) QueryKeyBindingType(org.apache.cxf.xkms.model.xkms.QueryKeyBindingType)

Example 4 with XKMSException

use of org.apache.cxf.xkms.exception.XKMSException in project cxf by apache.

the class LdapSearch method searchSubTree.

// CHECKSTYLE:ON
public NamingEnumeration<SearchResult> searchSubTree(String rootEntry, String filter) throws NamingException {
    int retry = 0;
    while (true) {
        try {
            if (this.dirContext == null) {
                this.dirContext = createInitialContext();
            }
            SearchControls ctls = new SearchControls();
            ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
            return dirContext.search(rootEntry, filter, ctls);
        } catch (CommunicationException e) {
            LOG.log(Level.WARNING, "Error in ldap search: " + e.getMessage(), e);
            this.dirContext = null;
            retry++;
            if (retry >= numRetries) {
                throw new XKMSException(ResultMajorEnum.HTTP_WWW_W_3_ORG_2002_03_XKMS_RECEIVER, ResultMinorEnum.HTTP_WWW_W_3_ORG_2002_03_XKMS_FAILURE, "Backend failure");
            }
        }
    }
}
Also used : CommunicationException(javax.naming.CommunicationException) XKMSException(org.apache.cxf.xkms.exception.XKMSException) SearchControls(javax.naming.directory.SearchControls)

Aggregations

XKMSException (org.apache.cxf.xkms.exception.XKMSException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)1 CertificateException (java.security.cert.CertificateException)1 CertificateFactory (java.security.cert.CertificateFactory)1 X509Certificate (java.security.cert.X509Certificate)1 ArrayList (java.util.ArrayList)1 CommunicationException (javax.naming.CommunicationException)1 SearchControls (javax.naming.directory.SearchControls)1 JAXBElement (javax.xml.bind.JAXBElement)1 XKMSLocateException (org.apache.cxf.xkms.exception.XKMSLocateException)1 QueryKeyBindingType (org.apache.cxf.xkms.model.xkms.QueryKeyBindingType)1 StatusType (org.apache.cxf.xkms.model.xkms.StatusType)1 UseKeyWithType (org.apache.cxf.xkms.model.xkms.UseKeyWithType)1 KeyInfoType (org.apache.cxf.xkms.model.xmldsig.KeyInfoType)1 X509DataType (org.apache.cxf.xkms.model.xmldsig.X509DataType)1