FileDocCategorySizeDatePackage
SupportingTokensProcessor.javaAPI DocExample11797Thu Jul 19 02:00:08 BST 2007com.sun.xml.ws.security.impl.policyconv

SupportingTokensProcessor

public class SupportingTokensProcessor extends Object
author
K.Venugopal@sun.com

Fields Summary
protected TokenProcessor
tokenProcessor
protected SignatureTargetCreator
stc
protected EncryptionTargetCreator
etc
protected com.sun.xml.ws.security.policy.Binding
binding
protected XWSSPolicyContainer
policyContainer
protected com.sun.xml.wss.impl.policy.mls.SignaturePolicy
signaturePolicy
protected com.sun.xml.wss.impl.policy.mls.EncryptionPolicy
encryptionPolicy
protected com.sun.xml.ws.security.policy.SupportingTokens
st
protected IntegrityAssertionProcessor
iAP
protected EncryptionAssertionProcessor
eAP
protected ArrayList
spList
protected ArrayList
epList
protected com.sun.xml.ws.security.policy.SignedParts
emptySP
protected boolean
buildSP
protected boolean
buildEP
protected PolicyID
pid
Constructors Summary
protected SupportingTokensProcessor()

    
     
        
    
public SupportingTokensProcessor(com.sun.xml.ws.security.policy.SupportingTokens st, TokenProcessor tokenProcessor, com.sun.xml.ws.security.policy.Binding binding, XWSSPolicyContainer container, com.sun.xml.wss.impl.policy.mls.SignaturePolicy sp, com.sun.xml.wss.impl.policy.mls.EncryptionPolicy ep, PolicyID pid)
Creates a new instance of SupportingTokensProcessor

        this.st = st;
        this.tokenProcessor = tokenProcessor;
        this.binding = binding;
        this.pid =pid;
        this.policyContainer = container;
        this.encryptionPolicy  = ep;
        this.signaturePolicy = sp;
        AlgorithmSuite as = null;
        as = st.getAlgorithmSuite();
        if( as == null){
            as = binding.getAlgorithmSuite();
        }
        this.iAP = new IntegrityAssertionProcessor(as,binding.isSignContent());
        this.eAP = new EncryptionAssertionProcessor(as,false);
        this.stc = iAP.getTargetCreator();
        this.etc = eAP.getTargetCreator();
        this.emptySP = getEmptySignedParts(st.getSignedParts());
    
Methods Summary
protected voidaddTargets()

        if(binding.getProtectionOrder() == Binding.SIGN_ENCRYPT){
            if(spList != null){
                populateSignaturePolicy();
            }
            if(epList != null){
                populateEncryptionPolicy();
            }
        }else{
            if(epList != null){
                populateEncryptionPolicy();
            }
            if(spList != null){
                populateSignaturePolicy();
            }
        }
    
protected voidaddToPrimarySignature(com.sun.xml.wss.impl.policy.mls.WSSPolicy policy, com.sun.xml.ws.security.policy.Token token)

        //no-op
    
protected voidcollectSignaturePolicies(com.sun.xml.ws.security.policy.Token token)

        if(buildSP){
            createSupportingSignature(token);
        }
    
protected voidcorrectSAMLBinding(com.sun.xml.wss.impl.policy.mls.WSSPolicy policy)

        //no-op
    
protected voidcreateSupportingSignature(com.sun.xml.ws.security.policy.Token token)

        SignaturePolicy sp = new SignaturePolicy();
        sp.setUUID(pid.generateID());
        tokenProcessor.addKeyBinding(sp, token,true);
        if(binding.getTokenProtection()){
            protectToken((WSSPolicy) sp.getKeyBinding(), sp);
        }
        SignaturePolicy.FeatureBinding spFB = (com.sun.xml.wss.impl.policy.mls.SignaturePolicy.FeatureBinding)sp.getFeatureBinding();
        //spFB.setCanonicalizationAlgorithm(CanonicalizationMethod.EXCLUSIVE);
        AlgorithmSuite as = null;
        as = st.getAlgorithmSuite();
        if( as == null){
            as = binding.getAlgorithmSuite();
        }
        SecurityPolicyUtil.setCanonicalizationMethod(spFB, as);
        //   sp.setKeyBinding(policy);
        getSPList().add(sp);
        endorseSignature(sp);
    
protected voidencryptToken(com.sun.xml.ws.security.policy.Token token)

        if ( token.getTokenId()!= null ) {
            EncryptionPolicy.FeatureBinding fb =(EncryptionPolicy.FeatureBinding) encryptionPolicy.getFeatureBinding();
            EncryptionTarget et = etc.newURIEncryptionTarget(token.getTokenId());
            fb.addTargetBinding(et);
        }
    
protected voidendorseSignature(com.sun.xml.wss.impl.policy.mls.SignaturePolicy sp)

        //no-op
    
protected java.util.ArrayListgetEPList()

        if(epList == null){
            epList = new ArrayList<EncryptionPolicy>();
        }
        return epList;
    
protected com.sun.xml.ws.security.policy.SignedPartsgetEmptySignedParts(java.util.Iterator itr)

        while(itr.hasNext()){
            Target target = (Target)itr.next();
            if(PolicyUtil.isSignedParts((PolicyAssertion)target)){
                if(SecurityPolicyUtil.isSignedPartsEmpty((SignedParts) target)){
                    return (SignedParts) target;
                }
            }
        }
        return null;
    
protected java.util.ArrayListgetSPList()

        if(spList == null){
            spList = new ArrayList<SignaturePolicy>();
        }
        return spList;
    
protected voidpopulateEncryptionPolicy()

        for(EncryptionPolicy ep :epList){
            EncryptionPolicy.FeatureBinding epFB = (EncryptionPolicy.FeatureBinding)ep.getFeatureBinding();
            Iterator<EncryptedElements> itr = st.getEncryptedElements();
            while(itr.hasNext()){
                EncryptedElements target = itr.next();
                eAP.process(target,epFB);
            }
            Iterator<EncryptedParts> epr = st.getEncryptedParts();
            while(epr.hasNext()){
                EncryptedParts target = epr.next();
                eAP.process(target,epFB);
            }
            policyContainer.insert(ep);
        }
    
protected voidpopulateSignaturePolicy()

        for(SignaturePolicy sp : spList){
            SignaturePolicy.FeatureBinding spFB = (SignaturePolicy.FeatureBinding)sp.getFeatureBinding();
            if(emptySP != null){
                iAP.process(emptySP,spFB);
            }else{
                Iterator<SignedParts>itr = st.getSignedParts();
                while(itr.hasNext()){
                    SignedParts target = itr.next();
                    iAP.process(target,spFB);
                }
            }
            Iterator<SignedElements> itr = st.getSignedElements();
            while(itr.hasNext()){
                SignedElements target = itr.next();
                iAP.process(target,spFB);
            }
            policyContainer.insert(sp);
        }
    
public voidprocess()

        Iterator tokens = st.getTokens();
        
        if(st.getEncryptedParts().hasNext() || st.getEncryptedElements().hasNext()){
            buildEP = true;
        }
        if(st.getSignedElements().hasNext() || st.getSignedParts().hasNext()){
            buildSP = true;
        }
        
        while(tokens.hasNext()){
            Token token = (Token) tokens.next();
            WSSPolicy policy = tokenProcessor.getWSSToken(token);
            if ( policy.getUUID() != null ) {
                
                addToPrimarySignature(policy,token);
                if(PolicyUtil.isUsernameToken((PolicyAssertion) token) && ((UserNameToken)token).hasPassword()){
                    encryptToken(token);
                }
                if(PolicyUtil.isSamlToken((PolicyAssertion)token)){
                    correctSAMLBinding(policy);
                }
                
                collectSignaturePolicies(token);
                if(buildEP){
                    EncryptionPolicy ep = new EncryptionPolicy();
                    ep.setKeyBinding(policy);
                    getEPList().add(ep);
                }
            }
            
            //TODO:: Add token to MessagePolicy;
            AuthenticationTokenPolicy atp = new AuthenticationTokenPolicy();
            atp.setFeatureBinding(policy);
            policyContainer.insert(atp);
            //TODO: Take care of targets.
            addTargets();
        }
    
protected voidprotectToken(com.sun.xml.wss.impl.policy.mls.WSSPolicy token, com.sun.xml.wss.impl.policy.mls.SignaturePolicy sp)

        String uid = token.getUUID();
        if ( uid != null ) {
            SignatureTargetCreator stc = iAP.getTargetCreator();
            SignatureTarget st = stc.newURISignatureTarget(uid);
            SecurityPolicyUtil.setName(st, token);
            stc.addSTRTransform(st);
            SignaturePolicy.FeatureBinding fb = (com.sun.xml.wss.impl.policy.mls.SignaturePolicy.FeatureBinding) sp.getFeatureBinding();
            fb.addTargetBinding(st);
        }