Package org.apache.rampart.policy

Examples of org.apache.rampart.policy.RampartPolicyData


       
    }

    private void doSignature(RampartMessageData rmd) throws RampartException {

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

        sigToken = rpd.getInitiatorToken();

        if (sigToken.isDerivedKeys()) {
            // Set up the encrypted key to use
            if(this.encrKey == null) {
                setupEncryptedKey(rmd, sigToken);
            }
           
            WSSecDKSign dkSign = new WSSecDKSign();
            dkSign.setExternalKey(this.encryptedKeyValue, this.encryptedKeyId);

            // Set the algo info
            dkSign.setSignatureAlgorithm(rpd.getAlgorithmSuite()
                    .getSymmetricSignature());
            dkSign.setDerivedKeyLength(rpd.getAlgorithmSuite()
                    .getMinimumSymmetricKeyLength() / 8);
           
            try {
                dkSign.prepare(doc, rmd.getSecHeader());

                if (rpd.isTokenProtection()) {
                    sigParts.add(new WSEncryptionPart(encrKey.getId()));
                }

                dkSign.setParts(sigParts);
View Full Code Here


   

    public static CallbackHandler getPasswordCB(RampartMessageData rmd) throws RampartException {

        MessageContext msgContext = rmd.getMsgContext();
        RampartPolicyData rpd = rmd.getPolicyData();
       
        return getPasswordCB(msgContext, rpd);
    }
View Full Code Here

        }
       
    }
   
    public static Vector getEncryptedParts(RampartMessageData rmd) {
        RampartPolicyData rpd =  rmd.getPolicyData();
        SOAPEnvelope envelope = rmd.getMsgContext().getEnvelope();
        return getPartsAndElements(false, envelope, rpd.isEncryptBody(), rpd.getEncryptedParts(), rpd.getEncryptedElements() );
    }
View Full Code Here

        SOAPEnvelope envelope = rmd.getMsgContext().getEnvelope();
        return getPartsAndElements(false, envelope, rpd.isEncryptBody(), rpd.getEncryptedParts(), rpd.getEncryptedElements() );
    }

    public static Vector getSignedParts(RampartMessageData rmd) {
        RampartPolicyData rpd =  rmd.getPolicyData();
        SOAPEnvelope envelope = rmd.getMsgContext().getEnvelope();
        return getPartsAndElements(true, envelope, rpd.isSignBody(), rpd.getSignedParts(), rpd.getSignedElements() );
    }
View Full Code Here

            throw new RampartException("errorExtractingToken");
        }
    }
   
    public static void setEncryptionUser(RampartMessageData rmd, WSSecEncryptedKey encrKeyBuilder) throws RampartException {
        RampartPolicyData rpd = rmd.getPolicyData();
        String encrUser = rpd.getRampartConfig().getEncryptionUser();
        if(encrUser == null || "".equals(encrUser)) {
            throw new RampartException("missingEncryptionUser");
        }
        if(encrUser.equals(WSHandlerConstants.USE_REQ_SIG_CERT)) {
            Object resultsObj = rmd.getMsgContext().getProperty(WSHandlerConstants.RECV_RESULTS);
View Full Code Here

   
    public void build(RampartMessageData rmd) throws RampartException {
       
        log.debug("SymmetricBindingBuilder build invoked");
       
        RampartPolicyData rpd = rmd.getPolicyData();
        if(rpd.isIncludeTimestamp()) {
            this.addTimestamp(rmd);
        }
       
        if(rmd.isInitiator()) {
            //Setup required tokens
            initializeTokens(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();
       
        Vector signatureValues = new Vector();
       
        Token encryptionToken = rpd.getEncryptionToken();
        Vector encrParts = RampartUtil.getEncryptedParts(rmd);

        if(encryptionToken == null && encrParts.size() > 0) {
            throw new RampartException("encryptionTokenMissing");
        }
       
        if(encryptionToken != null && encrParts.size() > 0) {
            //The encryption token can be an IssuedToken or a
             //SecureConversationToken
            String tokenId = null;
            org.apache.rahas.Token tok = null;
           
            if(encryptionToken instanceof IssuedToken) {
                tokenId = rmd.getIssuedEncryptionTokenId();
                log.debug("Issued EncryptionToken Id : " + tokenId);
            } else if(encryptionToken instanceof SecureConversationToken) {
                tokenId = rmd.getSecConvTokenId();
                log.debug("SCT Id : " + tokenId);
            } else if (encryptionToken instanceof X509Token) {
                tokenId = setupEncryptedKey(rmd, encryptionToken);
            } //TODO SAMLToken
           
            if(tokenId == null || tokenId.length() == 0) {
                throw new RampartException("noSecurityToken");
            }
           
            /*
             * Get hold of the token from the token storage
             */
            tok = this.getToken(rmd, tokenId);

            /*
             * Attach the token into the message based on token inclusion
             * values
             */
            boolean attached = false;
            Element encrTokenElement = null;
            Element refList = null;
            WSSecDKEncrypt dkEncr = null;
            WSSecEncrypt encr = null;
            Element encrDKTokenElem = null;
           
            if(Constants.INCLUDE_ALWAYS.equals(encryptionToken.getInclusion()) ||
                    Constants.INCLUDE_ONCE.equals(encryptionToken.getInclusion()) ||
                    (rmd.isInitiator() && Constants.INCLUDE_ALWAYS_TO_RECIPIENT.equals(encryptionToken.getInclusion()))) {
                encrTokenElement = RampartUtil.appendChildToSecHeader(rmd, tok.getToken());
                attached = true;
            }
           
            //In the X509 case we MUST add the EncryptedKey
            if(encryptionToken instanceof X509Token) {
                RampartUtil.appendChildToSecHeader(rmd, tok.getToken());
            }
            Document doc = rmd.getDocument();

            if(encryptionToken.isDerivedKeys()) {
                log.debug("Use drived keys");
               
                dkEncr = new WSSecDKEncrypt();
               
                if(attached && tok.getAttachedReference() != null) {
                   
                    dkEncr.setExternalKey(tok.getSecret(), (Element) doc
                            .importNode((Element) tok.getAttachedReference(),
                                    true));
                   
                } else if(tok.getUnattachedReference() != null) {
                    dkEncr.setExternalKey(tok.getSecret(), (Element) doc
                            .importNode((Element) tok.getUnattachedReference(),
                                    true));
                } else {
                    dkEncr.setExternalKey(tok.getSecret(), tok.getId());
                }
                try {
                    dkEncr.prepare(doc);
                    encrDKTokenElem = dkEncr.getdktElement();
                    RampartUtil.appendChildToSecHeader(rmd, encrDKTokenElem);
                   
                    refList = dkEncr.encryptForExternalRef(null, encrParts);
                   
                } catch (WSSecurityException e) {
                    throw new RampartException("errorInDKEncr");
                } catch (ConversationException e) {
                    throw new RampartException("errorInDKEncr");
                }
            } else {
                log.debug("NO derived keys, use the shared secret");
                encr = new WSSecEncrypt();
               
                encr.setWsConfig(rmd.getConfig());
               
                encr.setEphemeralKey(tok.getSecret());
                encr.setDocument(doc);
               
                try {
                    //Encrypt, get hold of the ref list and add it
                    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;
            Vector 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);
            }
           
            //Sign the message
            //We should use the same key in the case of EncryptBeforeSig
            signatureValues.add(this.doSymmSignature(rmd, encryptionToken, tok, sigParts));

            this.mainSigId = RampartUtil.addWsuIdToElement((OMElement)this.getInsertionLocation());
           
           
            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, "Element"));
View Full Code Here

    }


    private void doSignBeforeEncrypt(RampartMessageData rmd) throws RampartException {

        RampartPolicyData rpd = rmd.getPolicyData();
        Document doc = rmd.getDocument();
       
        Token sigToken = rpd.getSignatureToken();
       
        String encrTokId = null;
        String sigTokId = null;
       
        org.apache.rahas.Token encrTok = null;
        org.apache.rahas.Token sigTok = null;
       
        Element sigTokElem = null;
       
        Vector signatureValues = new Vector();
       
        if(sigToken != null) {
            if(sigToken instanceof SecureConversationToken) {
                sigTokId = rmd.getSecConvTokenId();
            } else if(sigToken instanceof IssuedToken) {
                sigTokId = rmd.getIssuedSignatureTokenId();
            } else if(sigToken instanceof X509Token) {
                sigTokId = setupEncryptedKey(rmd, sigToken);
            }
        } else {
            throw new RampartException("signatureTokenMissing");
        }
       
        if(sigTokId == null || sigTokId.length() == 0) {
            throw new RampartException("noSecurityToken");
        }
       
        sigTok = this.getToken(rmd, sigTokId);

        if(Constants.INCLUDE_ALWAYS.equals(sigToken.getInclusion()) ||
                Constants.INCLUDE_ONCE.equals(sigToken.getInclusion()) ||
                (rmd.isInitiator() &&
                        Constants.INCLUDE_ALWAYS_TO_RECIPIENT.equals(
                                sigToken.getInclusion()))) {
            sigTokElem = RampartUtil.appendChildToSecHeader(rmd,
                                                            sigTok.getToken());
            this.setInsertionLocation(sigTokElem);
        }
       

       
        //In the X509 case we MUST add the EncryptedKey
        if(sigToken instanceof X509Token) {
            sigTokElem = RampartUtil.appendChildToSecHeader(rmd, sigTok.getToken());
           
            //Set the insertion location
            this.setInsertionLocation(sigTokElem);
        }
       

        HashMap sigSuppTokMap = null;
        HashMap endSuppTokMap = null;
        HashMap sgndEndSuppTokMap = null;
        Vector 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);
   
            //Setup signature parts
            sigParts = addSignatureParts(sigSuppTokMap, sigParts);
            sigParts = addSignatureParts(sgndEndSuppTokMap, sigParts);
        } else {
            addSignatureConfirmation(rmd, sigParts);
        }
        //Sign the message
        signatureValues.add(this.doSymmSignature(rmd, sigToken, sigTok, sigParts));

        this.mainSigId = RampartUtil.addWsuIdToElement((OMElement)this.getInsertionLocation());

        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());
            }
        }

        //Encryption
        Token encrToken = rpd.getEncryptionToken();
        Element encrTokElem = null;
        if(sigToken.equals(encrToken)) {
            //Use the same token
            encrTokId = sigTokId;
            encrTok = sigTok;
            encrTokElem = sigTokElem;
        } else {
            encrTokId = rmd.getIssuedEncryptionTokenId();
            encrTok = this.getToken(rmd, encrTokId);
           
            if(Constants.INCLUDE_ALWAYS.equals(encrToken.getInclusion()) ||
                    Constants.INCLUDE_ONCE.equals(encrToken.getInclusion()) ||
                    (rmd.isInitiator() && Constants.INCLUDE_ALWAYS_TO_RECIPIENT.equals(encrToken.getInclusion()))) {
                encrTokElem = (Element)encrTok.getToken();
               
                //Add the encrToken element before the sigToken element
                RampartUtil.insertSiblingBefore(rmd, sigTokElem, encrTokElem);
            }
           
        }
       
        Vector encrParts = RampartUtil.getEncryptedParts(rmd);
       
        //Check for signature protection
        if(rpd.isSignatureProtection() && this.mainSigId != null) {
            //Now encrypt the signature using the above token
            encrParts.add(new WSEncryptionPart(this.mainSigId, "Element"));
        }
        Element refList = null;
       
        if(encrToken.isDerivedKeys() || encrToken instanceof SecureConversationToken) {
           
            try {
                WSSecDKEncrypt dkEncr = new WSSecDKEncrypt();
               
                if(encrTokElem != null && encrTok.getAttachedReference() != null) {
                   
                    dkEncr.setExternalKey(encrTok.getSecret(), (Element) doc
                            .importNode((Element) encrTok.getAttachedReference(),
                                    true));
                   
                } else if(encrTok.getUnattachedReference() != null) {
                    dkEncr.setExternalKey(encrTok.getSecret(), (Element) doc
                            .importNode((Element) encrTok.getUnattachedReference(),
                                    true));
                } else {
                    dkEncr.setExternalKey(encrTok.getSecret(), encrTok.getId());
                }
               
                dkEncr.prepare(doc);
                Element encrDKTokenElem = null;
                encrDKTokenElem = dkEncr.getdktElement();
                if(encrTokElem != null) {
                    RampartUtil.insertSiblingAfter(rmd, encrTokElem, encrDKTokenElem);
                } else {
                    RampartUtil.insertSiblingAfter(rmd, this.timestampElement, encrDKTokenElem);
                }
               
                refList = dkEncr.encryptForExternalRef(null, encrParts);
               
                RampartUtil.insertSiblingAfter(rmd,
                                                encrDKTokenElem,
                                                refList);

            } catch (WSSecurityException e) {
                throw new RampartException("errorInDKEncr");
            } catch (ConversationException e) {
                throw new RampartException("errorInDKEncr");
            }
        } else {
            try {
               
                WSSecEncrypt encr = new WSSecEncrypt();
               
                encr.setWsConfig(rmd.getConfig());
               
                encr.setEphemeralKey(encrTok.getSecret());
                RampartUtil.setEncryptionUser(rmd, encr);
                encr.setDocument(doc);
                encr.prepare(doc, RampartUtil.getEncryptionCrypto(rpd
                        .getRampartConfig(), rmd.getCustomClassLoader()));
               
                //Encrypt, get hold of the ref list and add it
                refList = encr.encryptForExternalRef(null, encrParts);
View Full Code Here

     * @param rpd
     * @throws RampartException
     */
    private void initializeTokens(RampartMessageData rmd) throws RampartException {
       
        RampartPolicyData rpd = rmd.getPolicyData();
       
        MessageContext msgContext = rmd.getMsgContext();
        if(rpd.isSymmetricBinding() && !msgContext.isServerSide()) {
            log.debug("Procesing symmentric 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) {
View Full Code Here

     */
    protected WSSecUsernameToken addUsernameToken(RampartMessageData rmd) throws RampartException {
      
        log.debug("Adding a UsernameToken");
       
        RampartPolicyData rpd = rmd.getPolicyData();
       
        //Get the user
        String user = rpd.getRampartConfig().getUser();
        if(user != null && !"".equals(user)) {
            log.debug("User : " + user);
           
            //Get the password
            CallbackHandler handler = RampartUtil.getPasswordCB(rmd);
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.