View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.support.wss.entries;
14  
15  import com.eviware.soapui.config.WSSEntryConfig;
16  import com.eviware.soapui.impl.wsdl.support.wss.OutgoingWss;
17  import com.eviware.soapui.model.propertyexpansion.PropertyExpansionContext;
18  import com.eviware.soapui.support.components.SimpleBindingForm;
19  import com.eviware.soapui.support.xml.XmlObjectConfigurationBuilder;
20  import com.eviware.soapui.support.xml.XmlObjectConfigurationReader;
21  import com.jgoodies.binding.PresentationModel;
22  import org.apache.ws.security.WSSConfig;
23  import org.apache.ws.security.message.WSSecHeader;
24  import org.apache.ws.security.message.WSSecTimestamp;
25  import org.w3c.dom.Document;
26  
27  import javax.swing.*;
28  
29  public class AddTimestampEntry extends WssEntryBase
30  {
31  	public static final String TYPE = "Timestamp";
32  	
33  	private int timeToLive;
34  	private boolean strictTimestamp;
35  
36  	public void init( WSSEntryConfig config, OutgoingWss container )
37  	{
38  		super.init( config, container, TYPE );
39  	}
40  	
41  	@Override
42  	protected JComponent buildUI()
43  	{
44  		SimpleBindingForm form = new SimpleBindingForm( new PresentationModel<AddTimestampEntry>( this ) ); 
45  		form.addSpace(5);
46  		form.appendTextField( "timeToLive", "Time To Live", "Sets the TimeToLive value for the Timestamp Token" );
47  		form.appendCheckBox( "strictTimestamp", "Millisecond Precision", "Sets precision of timestamp to milliseconds" );
48  		
49  		return form.getPanel();
50  	}
51  
52  	@Override
53  	protected void load( XmlObjectConfigurationReader reader )
54  	{
55  		timeToLive = reader.readInt( "timeToLive", 0 );
56  		strictTimestamp = reader.readBoolean( "strictTimestamp", true );
57  	}
58  
59  	@Override
60  	protected void save( XmlObjectConfigurationBuilder builder )
61  	{
62  		builder.add( "timeToLive", timeToLive );
63  		builder.add( "strictTimestamp", strictTimestamp );
64  	}
65  
66  	public void process( WSSecHeader secHeader, Document doc, PropertyExpansionContext context )
67  	{
68  		if( timeToLive <= 0 )
69  			return;
70  		
71  		WSSecTimestamp timestamp = new WSSecTimestamp();
72  		timestamp.setTimeToLive( timeToLive );
73  
74  		if( !strictTimestamp )
75  		{
76  			WSSConfig wsc = WSSConfig.getNewInstance();
77  		   wsc.setPrecisionInMilliSeconds(false);
78  		   wsc.setTimeStampStrict(false);
79  		   timestamp.setWsConfig(wsc);
80  		}
81  		
82  		timestamp.build( doc, secHeader );
83  	}
84  	
85  	public String getTimeToLive()
86  	{
87  		return String.valueOf( timeToLive );
88  	}
89  	
90  	public boolean isStrictTimestamp()
91  	{
92  		return strictTimestamp;
93  	}
94  
95  	public void setStrictTimestamp( boolean strictTimestamp )
96  	{
97  		this.strictTimestamp = strictTimestamp;
98  		saveConfig();
99  	}
100 
101 	public void setTimeToLive( String timeToLive )
102 	{
103 		try
104 		{
105 			this.timeToLive = Integer.valueOf( timeToLive );
106 			saveConfig();
107 		}
108 		catch( Exception e )
109 		{
110 		}		
111 	}
112 }