Search in sources :

Example 6 with AbstractSecuredElementSecurityEvent

use of org.apache.xml.security.stax.securityEvent.AbstractSecuredElementSecurityEvent in project cxf by apache.

the class StaxCryptoCoverageChecker method checkSignedAddressing.

private void checkSignedAddressing(List<SecurityEvent> results, AddressingProperties addressingProperties) throws WSSecurityException {
    if (!signAddressingHeaders || addressingProperties == null || (addressingProperties.getReplyTo() == null && addressingProperties.getFaultTo() == null)) {
        return;
    }
    boolean isReplyToSigned = false;
    boolean isFaultToSigned = false;
    for (SecurityEvent signedEvent : results) {
        AbstractSecuredElementSecurityEvent securedEvent = (AbstractSecuredElementSecurityEvent) signedEvent;
        if (!securedEvent.isSigned()) {
            continue;
        }
        List<QName> signedPath = securedEvent.getElementPath();
        if (isReplyTo(signedPath)) {
            isReplyToSigned = true;
        }
        if (isFaultTo(signedPath)) {
            isFaultToSigned = true;
        }
        if (isReplyToSigned && isFaultToSigned) {
            break;
        }
    }
    if (!isReplyToSigned && (addressingProperties.getReplyTo() != null)) {
        throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, new Exception("The Addressing headers are not signed"));
    }
    if (!isFaultToSigned && (addressingProperties.getFaultTo() != null)) {
        throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, new Exception("The Addressing headers are not signed"));
    }
}
Also used : SecurityEvent(org.apache.xml.security.stax.securityEvent.SecurityEvent) AbstractSecuredElementSecurityEvent(org.apache.xml.security.stax.securityEvent.AbstractSecuredElementSecurityEvent) AbstractSecuredElementSecurityEvent(org.apache.xml.security.stax.securityEvent.AbstractSecuredElementSecurityEvent) QName(javax.xml.namespace.QName) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException)

Example 7 with AbstractSecuredElementSecurityEvent

use of org.apache.xml.security.stax.securityEvent.AbstractSecuredElementSecurityEvent in project cxf by apache.

the class TokenProviderUtils method getReqSigCert.

/**
 * Get the X509Certificate associated with the signature that was received. This cert is to be used
 * for encrypting the issued token.
 */
public static X509Certificate getReqSigCert(Map<String, Object> messageContext) {
    @SuppressWarnings("unchecked") List<WSHandlerResult> results = (List<WSHandlerResult>) messageContext.get(WSHandlerConstants.RECV_RESULTS);
    // DOM
    X509Certificate cert = WSS4JUtils.getReqSigCert(results);
    if (cert != null) {
        return cert;
    }
    // Streaming
    @SuppressWarnings("unchecked") final List<SecurityEvent> incomingEventList = (List<SecurityEvent>) messageContext.get(SecurityEvent.class.getName() + ".in");
    if (incomingEventList != null) {
        for (SecurityEvent incomingEvent : incomingEventList) {
            if (WSSecurityEventConstants.SIGNED_PART == incomingEvent.getSecurityEventType() || WSSecurityEventConstants.SignedElement == incomingEvent.getSecurityEventType()) {
                org.apache.xml.security.stax.securityToken.SecurityToken token = ((AbstractSecuredElementSecurityEvent) incomingEvent).getSecurityToken();
                try {
                    if (token != null && token.getX509Certificates() != null && token.getX509Certificates().length > 0) {
                        return token.getX509Certificates()[0];
                    }
                } catch (XMLSecurityException ex) {
                    LOG.log(Level.FINE, ex.getMessage(), ex);
                    return null;
                }
            }
        }
    }
    return null;
}
Also used : SecurityEvent(org.apache.xml.security.stax.securityEvent.SecurityEvent) AbstractSecuredElementSecurityEvent(org.apache.xml.security.stax.securityEvent.AbstractSecuredElementSecurityEvent) WSHandlerResult(org.apache.wss4j.dom.handler.WSHandlerResult) X509Certificate(java.security.cert.X509Certificate) XMLSecurityException(org.apache.xml.security.exceptions.XMLSecurityException) AbstractSecuredElementSecurityEvent(org.apache.xml.security.stax.securityEvent.AbstractSecuredElementSecurityEvent) List(java.util.List)

Aggregations

AbstractSecuredElementSecurityEvent (org.apache.xml.security.stax.securityEvent.AbstractSecuredElementSecurityEvent)7 SecurityEvent (org.apache.xml.security.stax.securityEvent.SecurityEvent)7 QName (javax.xml.namespace.QName)6 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)6 X509Certificate (java.security.cert.X509Certificate)1 List (java.util.List)1 WSHandlerResult (org.apache.wss4j.dom.handler.WSHandlerResult)1 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)1