1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.support.wss;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.apache.ws.security.message.WSSecHeader;
19 import org.apache.ws.security.util.WSSecurityUtil;
20 import org.w3c.dom.Document;
21 import org.w3c.dom.Element;
22
23 import com.eviware.soapui.SoapUI;
24 import com.eviware.soapui.config.OutgoingWssConfig;
25 import com.eviware.soapui.config.WSSEntryConfig;
26 import com.eviware.soapui.model.propertyexpansion.PropertyExpansionContext;
27 import com.eviware.soapui.support.UISupport;
28
29 public class OutgoingWss
30 {
31 public static final String WSSENTRY_PROPERTY = OutgoingWss.class.getName() + "@wssEntry";
32
33 private OutgoingWssConfig config;
34 private List<WssEntry> entries = new ArrayList<WssEntry>();
35 private final DefaultWssContainer container;
36
37 public OutgoingWss( OutgoingWssConfig config, DefaultWssContainer container )
38 {
39 this.config = config;
40 this.container = container;
41
42 for( WSSEntryConfig entryConfig : config.getEntryList() )
43 {
44 WssEntry entry = WssEntryRegistry.get().build( entryConfig, this );
45 if( entry != null )
46 entries.add( entry );
47 }
48 }
49
50 public WssContainer getWssContainer()
51 {
52 return container;
53 }
54
55 public String getName()
56 {
57 return config.getName();
58 }
59
60 public String getPassword()
61 {
62 return config.getPassword();
63 }
64
65 public String getUsername()
66 {
67 return config.getUsername();
68 }
69
70 public void setName( String arg0 )
71 {
72 config.setName( arg0 );
73 }
74
75 public void setPassword( String arg0 )
76 {
77 config.setPassword( arg0 );
78 }
79
80 public void setUsername( String arg0 )
81 {
82 config.setUsername( arg0 );
83 }
84
85 public WssEntry addEntry( String type )
86 {
87 WssEntry newEntry = WssEntryRegistry.get().create( type, this );
88 entries.add( newEntry );
89
90 container.fireWssEntryAdded( newEntry );
91
92 return newEntry;
93 }
94
95 public void removeEntry( WssEntry entry )
96 {
97 int index = entries.indexOf( entry );
98
99 container.fireWssEntryRemoved( entries.remove( index ) );
100 config.removeEntry( index );
101 entry.release();
102 }
103
104 public OutgoingWssConfig getConfig()
105 {
106 return config;
107 }
108
109 public void processOutgoing( Document soapDocument, PropertyExpansionContext context )
110 {
111 Element header = WSSecurityUtil.findWsseSecurityHeaderBlock( soapDocument, soapDocument.getDocumentElement(),
112 false );
113
114 while( header != null )
115 {
116 header.getParentNode().removeChild( header );
117 header = WSSecurityUtil.findWsseSecurityHeaderBlock( soapDocument, soapDocument.getDocumentElement(), false );
118 }
119
120 WSSecHeader secHeader = new WSSecHeader();
121 secHeader.insertSecurityHeader( soapDocument );
122
123 for( WssEntry entry : entries )
124 {
125 try
126 {
127 entry.process( secHeader, soapDocument, context );
128 }
129 catch( Throwable e )
130 {
131 SoapUI.logError( e );
132 }
133 }
134 }
135
136 public List<WssEntry> getEntries()
137 {
138 return entries;
139 }
140
141 public void updateConfig( OutgoingWssConfig config )
142 {
143 this.config = config;
144
145 for( int c = 0; c < entries.size(); c++ )
146 {
147 entries.get( c ).udpateConfig( this.config.getEntryArray( c ) );
148 }
149 }
150
151 public void release()
152 {
153 for( WssEntry entry : entries )
154 entry.release();
155 }
156 }