Package org.apache.ws.security

Examples of org.apache.ws.security.WSEncryptionPart


       
            Vector<WSEncryptionPart> sigs = getSignedParts();
            //Add timestamp
            if (timestampEl != null) {
                Element el = timestampEl.getElement();
                sigs.add(new WSEncryptionPart(addWsuIdToElement(el)));
            }

            if (isRequestor()) {
                addSupportingTokens(sigs);
                if (!sigs.isEmpty()) {
                    signatures.add(doSignature(sigs, sigTokenWrapper, sigToken, sigTok, tokIncluded));
                }
                doEndorse();
            } else {
                //confirm sig
                assertSupportingTokens(sigs);
                addSignatureConfirmation(sigs);
                if (!sigs.isEmpty()) {
                    doSignature(sigs, sigTokenWrapper, sigToken, sigTok, tokIncluded);
                }
            }

           
           
            //Encryption
            TokenWrapper encrTokenWrapper = getEncryptionToken();
            Token encrToken = encrTokenWrapper.getToken();
            SecurityToken encrTok = null;
            if (sigToken.equals(encrToken)) {
                //Use the same token
                encrTok = sigTok;
            } else {
                String encrTokId = null;
                //REVISIT - issued token from trust?
                encrTok = tokenStore.getToken(encrTokId);
               
                if (SPConstants.IncludeTokenType.INCLUDE_TOKEN_ALWAYS == encrToken.getInclusion()
                    || SPConstants.IncludeTokenType.INCLUDE_TOKEN_ONCE == encrToken.getInclusion()
                    || (isRequestor()
                            && SPConstants.IncludeTokenType.INCLUDE_TOKEN_ALWAYS_TO_RECIPIENT
                            == encrToken.getInclusion())) {
                    Element encrTokElem = (Element)encrTok.getToken();
                   
                    //Add the encrToken element before the sigToken element
                    secHeader.getSecurityHeader().insertBefore(encrTokElem, sigTokElem);
                }
            }
           
            Vector<WSEncryptionPart> enc = getEncryptedParts();
           
            //Check for signature protection
            if (sbinding.isSignatureProtection() && mainSigId != null) {
                enc.add(new WSEncryptionPart(mainSigId, "Element"));
            }
           
            if (isRequestor()) {
                for (String id : encryptedTokensIdList) {
                    enc.add(new WSEncryptionPart(id, "Element"));
                }
            }
            doEncryption(encrTokenWrapper,
                         encrTok,
                         tokIncluded,
View Full Code Here


                }
                if (sigTokId.startsWith("#")) {
                    sigTokId = sigTokId.substring(1);
                }
            }
            sigs.add(new WSEncryptionPart(sigTokId));
        }
       
        dkSign.setParts(sigs);
        dkSign.addReferencesToSign(sigs, secHeader);
       
View Full Code Here

                                       List<WSEncryptionPart> sigParts) {
       
        for (Map.Entry<Token, WSSecBase> entry : tokenMap.entrySet()) {
           
            Object tempTok =  entry.getValue();
            WSEncryptionPart part = null;
           
            if (tempTok instanceof WSSecSignatureHelper) {
                WSSecSignatureHelper tempSig = (WSSecSignatureHelper) tempTok;
                if ((WSConstants.WSS_SAML_NS + WSConstants.SAML_ASSERTION_ID).
                    equals(tempSig.getSecRef().getKeyIdentifierValueType())) {
                   
                    addSupportingElement(cloneElement(tempSig.getSecRef().getElement()));
                              
                    // NOTE: This usage of WSEncryptionPart is a workaroud that is
                    // coupled with WSSecSignatureHelper. This approach is used so that
                    // we can force WSS4J to sign the assertion through a STR that
                    // WSS4J did not create during message signature creation.
                    part = new WSEncryptionPart(tempSig.getStrUri(), "ExternalSTRTransform", "Element",
                          WSConstants.PART_TYPE_ELEMENT);
           
                } else {
                    if (tempSig.getBSTTokenId() != null) {
                        part = new WSEncryptionPart(tempSig.getBSTTokenId());
                    }
                }
            } else if (tempTok instanceof WSSecUsernameToken) {
                WSSecUsernameToken unt = (WSSecUsernameToken)tempTok;
                part = new WSEncryptionPart(unt.getId());
            } else {
                policyNotAsserted(entry.getKey(), "UnsupportedTokenInSupportingToken: " + tempTok)
            }
            if (part != null) {
                sigParts.add(part);
View Full Code Here

       
        List<WSEncryptionPart> signedParts = new ArrayList<WSEncryptionPart>();
        if (parts != null) {
            isBody = parts.isBody();
            for (Header head : parts.getHeaders()) {
                WSEncryptionPart wep = new WSEncryptionPart(head.getName(),
                                                            head.getNamespace(),
                                                            "Element");
                signedParts.add(wep);
            }
        }
View Full Code Here

       
        List<WSEncryptionPart> signedParts = new ArrayList<WSEncryptionPart>();
        if (parts != null) {
            isSignBody = parts.isBody();
            for (Header head : parts.getHeaders()) {
                WSEncryptionPart wep = new WSEncryptionPart(head.getName(),
                                                            head.getNamespace(),
                                                            "Element");
                signedParts.add(wep);
            }
        }
View Full Code Here

       
        if (includeBody && !found.contains(this.saaj.getSOAPBody())) {
            found.add(saaj.getSOAPBody());
            final String id = this.addWsuIdToElement(this.saaj.getSOAPBody());
            if (sign) {
                result.add(new WSEncryptionPart(
                        id,
                        "Element",
                        WSConstants.PART_TYPE_BODY));
            } else {
                result.add(new WSEncryptionPart(
                        id,
                        "Content",
                        WSConstants.PART_TYPE_BODY));
            }
        }
       
        final SOAPHeader header = saaj.getSOAPHeader();
       
        // Handle sign/enc parts
        for (WSEncryptionPart part : parts) {
            final List<Element> elements;
           
            if (StringUtils.isEmpty(part.getName())) {
                // An entire namespace
                elements =
                    DOMUtils.getChildrenWithNamespace(header, part.getNamespace());   
            } else {
                // All elements with a given name and namespace
                elements =
                    DOMUtils.getChildrenWithName(header, part.getNamespace(), part.getName());
            }
           
            for (Element el : elements) {
                if (!found.contains(el)) {
                    found.add(el);
                    // Generate an ID for the element and use this ID or else
                    // WSS4J will only ever sign/encrypt the first matching
                    // elemenet with the same name and namespace as that in the
                    // WSEncryptionPart
                    final String id = this.addWsuIdToElement(el);
                    result.add(new WSEncryptionPart(
                            id,
                            part.getEncModifier(),
                            WSConstants.PART_TYPE_HEADER));
                }
            }
View Full Code Here

                        // element with the same name and namespace as that in the
                        // WSEncryptionPart
                        final String id = this.addWsuIdToElement(el);
                       
                       
                        WSEncryptionPart part = new WSEncryptionPart(
                                id,
                                encryptionModifier,
                                WSConstants.PART_TYPE_ELEMENT);
                        part.setXpath(expression);
                       
                        /**
                        String wsuId = el.getAttributeNS(WSConstants.WSU_NS, "Id");
                       
                        if (!StringUtils.isEmpty(wsuId)) {
View Full Code Here

       
        for (Map.Entry<Token, WSSecBase> ent : tokenMap.entrySet()) {
            WSSecBase tempTok = ent.getValue();
           
            Vector<WSEncryptionPart> sigParts = new Vector<WSEncryptionPart>();
            sigParts.add(new WSEncryptionPart(mainSigId));
           
            if (tempTok instanceof WSSecSignature) {
                WSSecSignature sig = (WSSecSignature)tempTok;
                if (isTokenProtection && sig.getBSTTokenId() != null) {
                    sigParts.add(new WSEncryptionPart(sig.getBSTTokenId()));
                }
                try {
                    sig.addReferencesToSign(sigParts, secHeader);
                    sig.computeSignature();
                    sig.appendToHeader(secHeader);
                   
                    signatures.add(sig.getSignatureValue());
                    if (isSigProtect) {
                        encryptedTokensIdList.add(sig.getId());
                    }
                } catch (WSSecurityException e) {
                    policyNotAsserted(ent.getKey(), e);
                }
               
            } else if (tempTok instanceof WSSecurityTokenHolder) {
                SecurityToken token = ((WSSecurityTokenHolder)tempTok).getToken();
                if (isTokenProtection) {
                    sigParts.add(new WSEncryptionPart(token.getId()));
                }
               
                try {
                    if (ent.getKey().isDerivedKeys()) {
                        doSymmSignatureDerived(ent.getKey(), token, sigParts, isTokenProtection);
View Full Code Here

            //TODO Need a better fix
            String sigTokId = tok.getId();
            if (sigTokId.startsWith("#")) {
                sigTokId = sigTokId.substring(1);
            }
            sigParts.add(new WSEncryptionPart(sigTokId));
        }
       
        dkSign.setParts(sigParts);
       
        dkSign.addReferencesToSign(sigParts, secHeader);
View Full Code Here

                byte[] sigVal = (byte[]) wsr.get(WSSecurityEngineResult.TAG_SIGNATURE_VALUE);
                wsc.setSignatureValue(sigVal);
                wsc.prepare(saaj.getSOAPPart());
                addSupportingElement(wsc.getSignatureConfirmationElement());
                if (sigParts != null) {
                    sigParts.add(new WSEncryptionPart(wsc.getId()));
                }
            }
        } else {
            //No Sig value
            wsc.prepare(saaj.getSOAPPart());
            addSupportingElement(wsc.getSignatureConfirmationElement());
            if (sigParts != null) {
                sigParts.add(new WSEncryptionPart(wsc.getId()));
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.ws.security.WSEncryptionPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.