Package org.apache.rampart.policy

Examples of org.apache.rampart.policy.RampartPolicyData


            } else if (act.intValue() == WSConstants.ENCR) {
                encr = true;
            }
        }

        RampartPolicyData rpd = data.getRampartMessageData().getPolicyData();

        SupportingToken sgndSupTokens = rpd.getSignedSupportingTokens();
        SupportingToken sgndEndorSupTokens = rpd.getSignedEndorsingSupportingTokens();

        if (sig && signatureParts.size() == 0
                && (sgndSupTokens == null || sgndSupTokens.getTokens().size() == 0)
                && (sgndEndorSupTokens == null || sgndEndorSupTokens.getTokens().size() == 0)) {
View Full Code Here


     */
    protected void validateSupportingTokens(ValidatorData data, Vector results)
            throws RampartException {

        // Check for UsernameToken
        RampartPolicyData rpd = data.getRampartMessageData().getPolicyData();
        Vector supportingToks = rpd.getSupportingTokensList();
        for (int i = 0; i < supportingToks.size(); i++) {
            SupportingToken suppTok = (SupportingToken) supportingToks.get(i);
            handleSupportingTokens(results, suppTok);
        }
        SupportingToken signedSuppToken = rpd.getSignedSupportingTokens();
        handleSupportingTokens(results, signedSuppToken);
        SupportingToken signedEndSuppToken = rpd.getSignedEndorsingSupportingTokens();
        handleSupportingTokens(results, signedEndSuppToken);
        SupportingToken endSuppToken = rpd.getEndorsingSupportingTokens();
        handleSupportingTokens(results, endSuppToken);
    }
View Full Code Here

        RampartMessageData rmd = data.getRampartMessageData();

        ArrayList encrRefs = getEncryptedReferences(results);

        RampartPolicyData rpd = rmd.getPolicyData();

        // build the list of encrypted nodes based on the dataRefs xpath expressions
        SOAPEnvelope envelope = rmd.getMsgContext().getEnvelope();
        Set namespaces = RampartUtil.findAllPrefixNamespaces(envelope, rpd.getDeclaredNamespaces());

        Map decryptedElements = new HashMap();
        for (int i = 0; i < encrRefs.size(); i++) {
            WSDataRef dataRef = (WSDataRef) encrRefs.get(i);

            if (dataRef == null || dataRef.getXpath() == null) {
                continue;
            }

            try {
                XPath xp = new AXIOMXPath(dataRef.getXpath());

                Iterator nsIter = namespaces.iterator();

                while (nsIter.hasNext()) {
                    OMNamespace tmpNs = (OMNamespace) nsIter.next();
                    xp.addNamespace(tmpNs.getPrefix(), tmpNs.getNamespaceURI());
                }

                Iterator nodesIterator = xp.selectNodes(envelope).iterator();

                while (nodesIterator.hasNext()) {
                    decryptedElements.put(nodesIterator.next(),
                            Boolean.valueOf(dataRef.isContent()));
                }

            } catch (JaxenException e) {
                // This has to be changed to propagate an instance of a RampartException up
                throw new RampartException(
                        "An error occurred while searching for decrypted elements.", e);
            }

        }

        // Check for encrypted body
        if (rpd.isEncryptBody() && !rpd.isEncryptBodyOptional()) {

            if (!isRefIdPresent(encrRefs, data.getBodyEncrDataId())) {
                throw new RampartException("encryptedPartMissing",
                        new String[] { data.getBodyEncrDataId() });
            }
View Full Code Here

    public void validateRequiredElements(ValidatorData data) throws RampartException {

        RampartMessageData rmd = data.getRampartMessageData();

        RampartPolicyData rpd = rmd.getPolicyData();

        SOAPEnvelope envelope = rmd.getMsgContext().getEnvelope();

        Iterator elementsIter = rpd.getRequiredElements().iterator();

        while (elementsIter.hasNext()) {

            String expression = (String) elementsIter.next();

            if (!RampartUtil.checkRequiredElements(envelope, rpd.getDeclaredNamespaces(),
                    expression)) {
                throw new RampartException("requiredElementsMissing", new String[] { expression });
            }
        }
View Full Code Here

     * @param rmd
     * @throws RampartException
     */
    private void initializeTokens(RampartMessageData rmd) throws RampartException {

        RampartPolicyData rpd = rmd.getPolicyData();

        MessageContext msgContext = rmd.getMsgContext();
        if (rpd.isSymmetricBinding() && !msgContext.isServerSide()) {
            if (log.isDebugEnabled()) {
                log.debug("Processing symmetric binding: "
                        + "Setting up encryption token and signature token");
            }
            // Setting up encryption token and signature token

            Token sigTok = rpd.getSignatureToken();
            Token encrTok = rpd.getEncryptionToken();
            if (sigTok instanceof IssuedToken) {
                log.debug("SignatureToken is an IssuedToken");
                if (rmd.getIssuedSignatureTokenId() == null) {
                    log.debug("No Issuedtoken found, requesting a new token");

View Full Code Here

            }
        }
    }

    protected boolean isSignatureRequired(RampartMessageData rmd) {
        RampartPolicyData rpd = rmd.getPolicyData();
        return (rpd.isSymmetricBinding() && rpd.getSignatureToken() != null)
                || (!rpd.isSymmetricBinding() && !rpd.isTransportBinding() && ((rpd
                        .getInitiatorToken() != null && rmd.isInitiator()) || rpd
                        .getRecipientToken() != null && !rmd.isInitiator()));
    }
View Full Code Here

    protected boolean isUsernameTokenPresent(ValidatorData data) {

        // TODO This can be integrated with supporting token processing
        // which also checks whether Username Tokens present

        RampartPolicyData rpd = data.getRampartMessageData().getPolicyData();

        Vector supportingToks = rpd.getSupportingTokensList();
        for (int i = 0; i < supportingToks.size(); i++) {
            SupportingToken suppTok = (SupportingToken) supportingToks.get(i);
            if (isUsernameTokenPresent(suppTok)) {
                return true;
            }
        }

        SupportingToken signedSuppToken = rpd.getSignedSupportingTokens();
        if (isUsernameTokenPresent(signedSuppToken)) {
            return true;
        }

        SupportingToken signedEndSuppToken = rpd.getSignedEndorsingSupportingTokens();
        if (isUsernameTokenPresent(signedEndSuppToken)) {
            return true;
        }

        SupportingToken endSuppToken = rpd.getEndorsingSupportingTokens();
        if (isUsernameTokenPresent(endSuppToken)) {
            return true;
        }

        return false;
View Full Code Here

    private Element signatureElement;

    public void build(RampartMessageData rmd) throws RampartException {
        log.debug("AsymmetricBindingBuilder build invoked");

        RampartPolicyData rpd = rmd.getPolicyData();
        if (rpd.isIncludeTimestamp()) {
            this.addTimestamp(rmd);
        }

        if (Constants.ENCRYPT_BEFORE_SIGNING.equals(rpd.getProtectionOrder())) {
            this.doEncryptBeforeSig(rmd);
        } else {
            this.doSignBeforeEncrypt(rmd);
        }
View Full Code Here

    }

    private void doEncryptBeforeSig(RampartMessageData rmd)
            throws RampartException {

        RampartPolicyData rpd = rmd.getPolicyData();
        Document doc = rmd.getDocument();
        RampartConfig config = rpd.getRampartConfig();

        /*
         * We need to hold on to these two element to use them as refence in the
         * case of encypting the signature
         */
        Element encrDKTokenElem = null;
        WSSecEncrypt encr = null;
        Element refList = null;
        WSSecDKEncrypt dkEncr = null;

        /*
         * We MUST use keys derived from the same token
         */
        Token encryptionToken = rpd.getRecipientToken();
        Vector encrParts = RampartUtil.getEncryptedParts(rmd);

        if(encryptionToken == null && encrParts.size() > 0) {
            throw new RampartException("encryptionTokenMissing");
        }
       
        if (encryptionToken != null && encrParts.size() > 0) {
            if (encryptionToken.isDerivedKeys()) {
                try {
                    this.setupEncryptedKey(rmd, encryptionToken);
                    // Create the DK encryption builder
                    dkEncr = new WSSecDKEncrypt();
                    dkEncr.setParts(encrParts);
                    dkEncr.setExternalKey(this.encryptedKeyValue,
                            this.encryptedKeyId);
                    dkEncr.prepare(doc);

                    // Get and add the DKT element
                    this.encrDKTElement = dkEncr.getdktElement();
                    encrDKTokenElem = RampartUtil.appendChildToSecHeader(rmd, this.encrDKTElement);

                    refList = dkEncr.encryptForExternalRef(null, encrParts);

                } catch (WSSecurityException e) {
                    throw new RampartException("errorCreatingEncryptedKey", e);
                } catch (ConversationException e) {
                    throw new RampartException("errorInDKEncr", e);
                }
            } else {
                try {
                    encr = new WSSecEncrypt();
                    encr.setParts(encrParts);
                    encr.setWsConfig(rmd.getConfig());
                    encr.setDocument(doc);
                    RampartUtil.setEncryptionUser(rmd, encr);
                    encr.setSymmetricEncAlgorithm(rpd.getAlgorithmSuite().getEncryption());
                    encr.setKeyEncAlgo(rpd.getAlgorithmSuite().getAsymmetricKeyWrap());
                    encr.prepare(doc, RampartUtil.getEncryptionCrypto(config, rmd.getCustomClassLoader()));

                    Element bstElem = encr.getBinarySecurityTokenElement();
                    if (bstElem != null) {
                        RampartUtil.appendChildToSecHeader(rmd, bstElem);
                    }

                    this.encrTokenElement = encr.getEncryptedKeyElement();
                    this.encrTokenElement = RampartUtil.appendChildToSecHeader(rmd,
                            encrTokenElement);

                    refList = encr.encryptForExternalRef(null, encrParts);

                } catch (WSSecurityException e) {
                    throw new RampartException("errorInEncryption", e);
                }
            }

            RampartUtil.appendChildToSecHeader(rmd, refList);

            this.setInsertionLocation(encrTokenElement);

            HashMap sigSuppTokMap = null;
            HashMap endSuppTokMap = null;
            HashMap sgndEndSuppTokMap = null;
            this.sigParts = RampartUtil.getSignedParts(rmd);
           
            if(this.timestampElement != null){
              sigParts.add(new WSEncryptionPart(RampartUtil
                    .addWsuIdToElement((OMElement) this.timestampElement)));
            }
           
            if (rmd.isInitiator()) {

                // Now add the supporting tokens
                SupportingToken sgndSuppTokens = rpd
                        .getSignedSupportingTokens();

                sigSuppTokMap = this
                        .handleSupportingTokens(rmd, sgndSuppTokens);

                SupportingToken endSuppTokens = rpd
                        .getEndorsingSupportingTokens();

                endSuppTokMap = this.handleSupportingTokens(rmd, endSuppTokens);

                SupportingToken sgndEndSuppTokens = rpd
                        .getSignedEndorsingSupportingTokens();

                sgndEndSuppTokMap = this.handleSupportingTokens(rmd,
                        sgndEndSuppTokens);
               
                SupportingToken supportingToks = rpd.getSupportingTokens();
                this.handleSupportingTokens(rmd, supportingToks);
               

                // Setup signature parts
                sigParts = addSignatureParts(sigSuppTokMap, sigParts);
                sigParts = addSignatureParts(sgndEndSuppTokMap, sigParts);
            } else {
                addSignatureConfirmation(rmd, sigParts);
            }
           
            if(rpd.getInitiatorToken() != null) {
                this.doSignature(rmd);
            }

            if (rmd.isInitiator()) {
                // Do endorsed signatures
                Vector endSigVals = this.doEndorsedSignatures(rmd,
                        endSuppTokMap);
                for (Iterator iter = endSigVals.iterator(); iter.hasNext();) {
                    signatureValues.add(iter.next());
                }

                // Do signed endorsing signatures
                Vector sigEndSigVals = this.doEndorsedSignatures(rmd,
                        sgndEndSuppTokMap);
                for (Iterator iter = sigEndSigVals.iterator(); iter.hasNext();) {
                    signatureValues.add(iter.next());
                }
            }

            // Check for signature protection
            if (rpd.isSignatureProtection() && this.mainSigId != null) {

                Vector secondEncrParts = new Vector();

                // Now encrypt the signature using the above token
                secondEncrParts.add(new WSEncryptionPart(this.mainSigId,
View Full Code Here

    }

    private void doSignBeforeEncrypt(RampartMessageData rmd)
            throws RampartException {
        RampartPolicyData rpd = rmd.getPolicyData();
        Document doc = rmd.getDocument();

        HashMap sigSuppTokMap = null;
        HashMap endSuppTokMap = null;
        HashMap sgndEndSuppTokMap = null;
        sigParts = RampartUtil.getSignedParts(rmd);
       
        //Add timestamp
        if(this.timestampElement != null){
          sigParts.add(new WSEncryptionPart(RampartUtil
                .addWsuIdToElement((OMElement) this.timestampElement)));
        }else{
          this.setInsertionLocation(null);
        }
       
        if (rmd.isInitiator()) {
            // Now add the supporting tokens
            SupportingToken sgndSuppTokens = rpd.getSignedSupportingTokens();

            sigSuppTokMap = this.handleSupportingTokens(rmd, sgndSuppTokens);

            SupportingToken endSuppTokens = rpd.getEndorsingSupportingTokens();

            endSuppTokMap = this.handleSupportingTokens(rmd, endSuppTokens);

            SupportingToken sgndEndSuppTokens = rpd
                    .getSignedEndorsingSupportingTokens();

            sgndEndSuppTokMap = this.handleSupportingTokens(rmd,
                    sgndEndSuppTokens);

            // Setup signature parts
            sigParts = addSignatureParts(sigSuppTokMap, sigParts);
            sigParts = addSignatureParts(sgndEndSuppTokMap, sigParts);
        } else {
            addSignatureConfirmation(rmd, sigParts);
        }

        if(rpd.getInitiatorToken() != null) {
            // Do signature
            this.doSignature(rmd);
        }
       
        //Do endorsed signature

        if (rmd.isInitiator()) {
            // Do endorsed signatures
            Vector endSigVals = this.doEndorsedSignatures(rmd,
                    endSuppTokMap);
            for (Iterator iter = endSigVals.iterator(); iter.hasNext();) {
                signatureValues.add(iter.next());
            }

            // Do signed endorsing signatures
            Vector sigEndSigVals = this.doEndorsedSignatures(rmd,
                    sgndEndSuppTokMap);
            for (Iterator iter = sigEndSigVals.iterator(); iter.hasNext();) {
                signatureValues.add(iter.next());
            }
        }
       
       
            
        Vector encrParts = RampartUtil.getEncryptedParts(rmd);
       
        //Check for signature protection
        if(rpd.isSignatureProtection() && this.mainSigId != null) {
            encrParts.add(new WSEncryptionPart(RampartUtil.addWsuIdToElement((OMElement)this.signatureElement), "Element"));
        }
       
        //Do encryption
        Token encrToken = rpd.getRecipientToken();
        if(encrToken != null && encrParts.size() > 0) {
            Element refList = null;
            if(encrToken.isDerivedKeys()) {
               
                try {
                    WSSecDKEncrypt dkEncr = new WSSecDKEncrypt();
                   
                    if(this.encrKey == null) {
                        this.setupEncryptedKey(rmd, encrToken);
                    }
                   
                    dkEncr.setExternalKey(this.encryptedKeyValue, this.encryptedKeyId);
                    dkEncr.setSymmetricEncAlgorithm(rpd.getAlgorithmSuite().getEncryption());
                    dkEncr.prepare(doc);
                   
                   
                    if(this.encrTokenElement != null) {
                        this.encrDKTElement = RampartUtil.insertSiblingAfter(
                                rmd, this.encrTokenElement, dkEncr.getdktElement());
                    } else {
                        this.encrDKTElement = RampartUtil.insertSiblingBefore(
                                rmd, this.sigDKTElement, dkEncr.getdktElement());
                    }
                   
                    refList = dkEncr.encryptForExternalRef(null, encrParts);
                   
                    RampartUtil.insertSiblingAfter(rmd,
                                                    this.encrDKTElement,
                                                    refList);
                                                   
                } catch (WSSecurityException e) {
                    throw new RampartException("errorInDKEncr");
                } catch (ConversationException e) {
                    throw new RampartException("errorInDKEncr");
                }
            } else {
                try {
                   
                    WSSecEncrypt encr = new WSSecEncrypt();
                   
                   
                    if(encrToken.getInclusion().equals(Constants.INCLUDE_NEVER)) {
                        if(rpd.getWss10() != null && rpd.getWss10().isMustSupportRefKeyIdentifier()) {
                            encr.setKeyIdentifierType(WSConstants.SKI_KEY_IDENTIFIER);
                        } else if(rpd.getWss11() != null && rpd.getWss11().isMustSupportRefThumbprint()) {
                            encr.setKeyIdentifierType(WSConstants.THUMBPRINT_IDENTIFIER);
                        }
                    } else {
                        encr.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
                    }
                   
                    encr.setWsConfig(rmd.getConfig());
                   
                    encr.setDocument(doc);
                    RampartUtil.setEncryptionUser(rmd, encr);
                    encr.setSymmetricEncAlgorithm(rpd.getAlgorithmSuite().getEncryption());
                    encr.setKeyEncAlgo(rpd.getAlgorithmSuite().getAsymmetricKeyWrap());
                    encr.prepare(doc, RampartUtil.getEncryptionCrypto(rpd
                            .getRampartConfig(), rmd.getCustomClassLoader()));
                   
                    if(this.timestampElement != null){
                      this.setInsertionLocation(this.timestampElement);
                    }else{
View Full Code Here

TOP

Related Classes of org.apache.rampart.policy.RampartPolicyData

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.