FileDocCategorySizeDatePackage
TimestampTest.javaAPI DocExample8171Tue May 29 16:57:44 BST 2007com.sun.xml.wss.impl

TimestampTest

public class TimestampTest extends TestCase
author
admin

Fields Summary
private static HashMap
client
private static com.sun.xml.wss.impl.AlgorithmSuite
alg
Constructors Summary
public TimestampTest(String testName)
Creates a new instance of TimestampTest

    
           
       
        super(testName);
    
Methods Summary
protected voidsetUp()

    	
    
public static junit.framework.Testsuite()

        TestSuite suite = new TestSuite(TimestampTest.class);                                                                                                 return suite;
    
protected voidtearDown()

    
public static voidtestTimestampOnTop()

            //alg.setType(AlgorithmSuiteValue.Basic128);
            alg = new AlgorithmSuite(AlgorithmSuiteValue.Basic128.getDigAlgorithm(), AlgorithmSuiteValue.Basic128.getEncAlgorithm(), AlgorithmSuiteValue.Basic128.getSymKWAlgorithm(), AlgorithmSuiteValue.Basic128.getAsymKWAlgorithm());
            SignaturePolicy signaturePolicy = new SignaturePolicy();
            SignatureTarget st = new SignatureTarget();
            st.setType("qname");
            st.setDigestAlgorithm(DigestMethod.SHA1);
            ((SignaturePolicy.FeatureBinding)signaturePolicy.getFeatureBinding()).
                    addTargetBinding(st);
            ((SignaturePolicy.FeatureBinding)signaturePolicy.getFeatureBinding()).
                    setCanonicalizationAlgorithm(MessageConstants.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
            
            QName name = new QName("X509Certificate");
            Token tok = new Token(name);
            
            AuthenticationTokenPolicy.X509CertificateBinding x509bind =
                    (AuthenticationTokenPolicy.X509CertificateBinding)signaturePolicy.newX509CertificateKeyBinding();
            x509bind.setReferenceType(MessageConstants.DIRECT_REFERENCE_TYPE);
            x509bind.setIncludeToken(Token.INCLUDE_ALWAYS);
	    //x509bind.setPolicyToken(tok);
    	    x509bind.setUUID(new String("1008"));
            
            TimestampPolicy tsPolicy = new TimestampPolicy();
            
            SOAPMessage msg = MessageFactory.newInstance().createMessage();
    	    SOAPBody body = msg.getSOAPBody();
            SOAPBodyElement sbe = body.addBodyElement(
            	    SOAPFactory.newInstance().createName(
                	"StockSymbol",
                    	"tru",
	                "http://fabrikam123.com/payloads"));
    	    sbe.addTextNode("QQQ");
            
            //Create processing context and set the soap
    	    //message to be processed.
            ProcessingContextImpl context = new ProcessingContextImpl(client);
	    context.setSOAPMessage(msg);
        
            com.sun.xml.ws.security.policy.WSSAssertion wssAssertionws = null;
            WSSAssertion wssAssertion = null;
            AssertionSet as = null;
            Policy wssPolicy = new PolicyResourceLoader().loadPolicy("security/policy-binding2.xml");
            Iterator<AssertionSet> i = wssPolicy.iterator();
            if(i.hasNext())
                as = i.next();
            
            for(PolicyAssertion assertion:as){
                if(assertion instanceof com.sun.xml.ws.security.policy.WSSAssertion){
                    wssAssertionws = (com.sun.xml.ws.security.policy.WSSAssertion)assertion;
                }                      
            }
            wssAssertion = new WSSAssertion(wssAssertionws.getRequiredProperties(), "1.0");
            MessagePolicy pol = new MessagePolicy();
            pol.append(tsPolicy);
	    pol.append(signaturePolicy);
            pol.setWSSAssertion(wssAssertion);
            
            context.setAlgorithmSuite(alg);
            
            context.setSecurityPolicy(pol);
            CallbackHandler handler = new PolicyCallbackHandler1("client");
	    SecurityEnvironment env = new DefaultSecurityEnvironmentImpl(handler);
    	    context.setSecurityEnvironment(env);
            
            SecurityAnnotator.secureMessage(context);

	    SecurableSoapMessage secMsg = context.getSecurableSoapMessage();
            //DumpFilter.process(context);
            
            SecurityHeader securityHeader = secMsg.findSecurityHeader();
            org.w3c.dom.Node timestamp = securityHeader.getFirstChild();
            assertEquals("Timestamp", timestamp.getLocalName());