Search in sources :

Example 1 with WSSecSignatureConfirmation

use of org.apache.wss4j.dom.message.WSSecSignatureConfirmation in project cxf by apache.

the class AbstractBindingBuilder method addSignatureConfirmation.

protected void addSignatureConfirmation(List<WSEncryptionPart> sigParts) {
    Wss10 wss10 = getWss10();
    if (!(wss10 instanceof Wss11) || !((Wss11) wss10).isRequireSignatureConfirmation()) {
        // If we don't require sig confirmation simply go back :-)
        return;
    }
    List<WSHandlerResult> results = CastUtils.cast((List<?>) message.getExchange().getInMessage().get(WSHandlerConstants.RECV_RESULTS));
    /*
         * loop over all results gathered by all handlers in the chain. For each
         * handler result get the various actions. After that loop we have all
         * signature results in the signatureActions list
         */
    List<WSSecurityEngineResult> signatureActions = new ArrayList<>();
    for (WSHandlerResult wshResult : results) {
        if (wshResult.getActionResults().containsKey(WSConstants.SIGN)) {
            signatureActions.addAll(wshResult.getActionResults().get(WSConstants.SIGN));
        }
        if (wshResult.getActionResults().containsKey(WSConstants.UT_SIGN)) {
            signatureActions.addAll(wshResult.getActionResults().get(WSConstants.UT_SIGN));
        }
    }
    sigConfList = new ArrayList<>();
    // prepare a SignatureConfirmation token
    WSSecSignatureConfirmation wsc = new WSSecSignatureConfirmation(secHeader);
    wsc.setIdAllocator(wssConfig.getIdAllocator());
    if (!signatureActions.isEmpty()) {
        for (WSSecurityEngineResult wsr : signatureActions) {
            byte[] sigVal = (byte[]) wsr.get(WSSecurityEngineResult.TAG_SIGNATURE_VALUE);
            wsc.setSignatureValue(sigVal);
            wsc.prepare();
            addSupportingElement(wsc.getSignatureConfirmationElement());
            if (sigParts != null) {
                WSEncryptionPart part = new WSEncryptionPart(wsc.getId(), "Element");
                part.setElement(wsc.getSignatureConfirmationElement());
                sigParts.add(part);
                sigConfList.add(part);
            }
        }
    } else {
        // No Sig value
        wsc.prepare();
        addSupportingElement(wsc.getSignatureConfirmationElement());
        if (sigParts != null) {
            WSEncryptionPart part = new WSEncryptionPart(wsc.getId(), "Element");
            part.setElement(wsc.getSignatureConfirmationElement());
            sigParts.add(part);
            sigConfList.add(part);
        }
    }
    assertPolicy(new QName(wss10.getName().getNamespaceURI(), SPConstants.REQUIRE_SIGNATURE_CONFIRMATION));
}
Also used : WSEncryptionPart(org.apache.wss4j.common.WSEncryptionPart) QName(javax.xml.namespace.QName) WSSecSignatureConfirmation(org.apache.wss4j.dom.message.WSSecSignatureConfirmation) Wss11(org.apache.wss4j.policy.model.Wss11) ArrayList(java.util.ArrayList) Wss10(org.apache.wss4j.policy.model.Wss10) WSHandlerResult(org.apache.wss4j.dom.handler.WSHandlerResult) WSSecurityEngineResult(org.apache.wss4j.dom.engine.WSSecurityEngineResult)

Aggregations

ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 WSEncryptionPart (org.apache.wss4j.common.WSEncryptionPart)1 WSSecurityEngineResult (org.apache.wss4j.dom.engine.WSSecurityEngineResult)1 WSHandlerResult (org.apache.wss4j.dom.handler.WSHandlerResult)1 WSSecSignatureConfirmation (org.apache.wss4j.dom.message.WSSecSignatureConfirmation)1 Wss10 (org.apache.wss4j.policy.model.Wss10)1 Wss11 (org.apache.wss4j.policy.model.Wss11)1