1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.support.wss;
14
15 import com.eviware.soapui.config.IncomingWssConfig;
16 import com.eviware.soapui.config.KeyMaterialCryptoConfig;
17 import com.eviware.soapui.config.OutgoingWssConfig;
18 import com.eviware.soapui.config.WssContainerConfig;
19 import com.eviware.soapui.impl.wsdl.support.wss.crypto.KeyMaterialWssCrypto;
20 import com.eviware.soapui.model.ModelItem;
21 import com.eviware.soapui.model.propertyexpansion.PropertyExpansion;
22 import com.eviware.soapui.model.propertyexpansion.PropertyExpansionsResult;
23 import com.eviware.soapui.support.resolver.ResolveContext;
24 import com.eviware.soapui.support.types.StringList;
25 import org.bouncycastle.jce.provider.BouncyCastleProvider;
26
27 import java.security.Security;
28 import java.util.ArrayList;
29 import java.util.HashSet;
30 import java.util.List;
31 import java.util.Set;
32
33 public class DefaultWssContainer implements WssContainer
34 {
35 private final ModelItem modelItem;
36 private List<WssCrypto> cryptos = new ArrayList<WssCrypto>();
37 private List<IncomingWss> incomingWssConfigs = new ArrayList<IncomingWss>();
38 private List<OutgoingWss> outgoingWssConfigs = new ArrayList<OutgoingWss>();
39 private final WssContainerConfig config;
40 private Set<WssContainerListener> listeners = new HashSet<WssContainerListener>();
41
42 static
43 {
44 Security.addProvider(new BouncyCastleProvider());
45 }
46
47 public DefaultWssContainer( ModelItem modelItem, WssContainerConfig config )
48 {
49 this.modelItem = modelItem;
50 this.config = config;
51
52 for( KeyMaterialCryptoConfig cryptoConfig : config.getCryptoList() )
53 {
54 cryptos.add( new KeyMaterialWssCrypto( cryptoConfig, this ) );
55 }
56
57 for( IncomingWssConfig wssConfig : config.getIncomingList())
58 {
59 incomingWssConfigs.add( new IncomingWss( wssConfig, this ));
60 }
61
62 for( OutgoingWssConfig wssConfig : config.getOutgoingList())
63 {
64 outgoingWssConfigs.add( new OutgoingWss( wssConfig, this ));
65 }
66 }
67
68 public ModelItem getModelItem()
69 {
70 return modelItem;
71 }
72
73 public PropertyExpansion[] getPropertyExpansions()
74 {
75 PropertyExpansionsResult result = new PropertyExpansionsResult( getModelItem(), this );
76
77 for( OutgoingWss entry : outgoingWssConfigs )
78 {
79 result.addAll( entry.getPropertyExpansions() );
80 }
81
82 return result.toArray();
83 }
84
85 public List<WssCrypto> getCryptoList()
86 {
87 return new ArrayList<WssCrypto>( cryptos );
88 }
89
90 public WssCrypto addCrypto( String source, String password )
91 {
92 KeyMaterialWssCrypto result = new KeyMaterialWssCrypto( getConfig().addNewCrypto(), this, source, password );
93 cryptos.add( result );
94
95 fireCryptoAdded( result );
96
97 return result;
98 }
99
100 protected void fireCryptoAdded( WssCrypto crypto )
101 {
102 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
103 {
104 listener.cryptoAdded( crypto );
105 }
106 }
107
108 protected void fireCryptoRemoved( WssCrypto crypto )
109 {
110 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
111 {
112 listener.cryptoRemoved( crypto );
113 }
114 }
115
116 public WssContainerConfig getConfig()
117 {
118 return config;
119 }
120
121 public int getCryptoCount()
122 {
123 return cryptos.size();
124 }
125
126 public WssCrypto getCryptoAt( int index )
127 {
128 return cryptos.get( index );
129 }
130
131 public void removeCryptoAt( int row )
132 {
133 WssCrypto crypto = cryptos.remove( row );
134 fireCryptoRemoved( crypto );
135 getConfig().removeCrypto( row );
136 }
137
138 public List<IncomingWss> getIncomingWssList()
139 {
140 return new ArrayList<IncomingWss>( incomingWssConfigs );
141 }
142
143 public IncomingWss addIncomingWss( String label )
144 {
145 IncomingWss incomingWss = new IncomingWss( getConfig().addNewIncoming(), this );
146 incomingWss.setName( label );
147 incomingWssConfigs.add( incomingWss );
148
149 fireIncomingWssAdded( incomingWss );
150
151 return incomingWss;
152 }
153
154 public int getIncomingWssCount()
155 {
156 return incomingWssConfigs.size();
157 }
158
159 public IncomingWss getIncomingWssAt( int index )
160 {
161 return incomingWssConfigs.get( index );
162 }
163
164 public void removeIncomingWssAt( int row )
165 {
166 IncomingWss incomingWss = incomingWssConfigs.remove( row );
167 fireIncomingWssRemoved( incomingWss );
168 getConfig().removeIncoming( row );
169 }
170
171 protected void fireIncomingWssAdded( IncomingWss incomingWss )
172 {
173 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
174 {
175 listener.incomingWssAdded( incomingWss );
176 }
177 }
178
179 protected void fireIncomingWssRemoved( IncomingWss incomingWss )
180 {
181 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
182 {
183 listener.incomingWssRemoved( incomingWss );
184 }
185 }
186
187 public List<OutgoingWss> getOutgoingWssList()
188 {
189 return new ArrayList<OutgoingWss>( outgoingWssConfigs );
190 }
191
192 public OutgoingWss addOutgoingWss( String label )
193 {
194 OutgoingWss result = new OutgoingWss( getConfig().addNewOutgoing(), this );
195 result.setName( label );
196
197 outgoingWssConfigs.add( result );
198
199 fireOutgoingWssAdded( result );
200
201 return result;
202 }
203
204 protected void fireOutgoingWssAdded( OutgoingWss result )
205 {
206 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
207 {
208 listener.outgoingWssAdded( result );
209 }
210 }
211
212 protected void fireOutgoingWssRemoved( OutgoingWss result )
213 {
214 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
215 {
216 listener.outgoingWssRemoved( result );
217 }
218 }
219
220 public int getOutgoingWssCount()
221 {
222 return outgoingWssConfigs.size();
223 }
224
225 public OutgoingWss getOutgoingWssAt( int index )
226 {
227 return outgoingWssConfigs.get( index );
228 }
229
230 public void removeOutgoingWssAt( int row )
231 {
232 OutgoingWss outgoingWss = outgoingWssConfigs.remove( row );
233 fireOutgoingWssRemoved( outgoingWss );
234 outgoingWss.release();
235 getConfig().removeOutgoing( row );
236 }
237
238 public WssCrypto getCryptoByName( String cryptoName )
239 {
240 for( WssCrypto crypto : cryptos )
241 if( crypto.getLabel().equals( cryptoName ))
242 return crypto;
243
244 return null;
245 }
246
247 public IncomingWss getIncomingWssByName( String incomingName )
248 {
249 for( IncomingWss incomingWss : incomingWssConfigs )
250 if( incomingWss.getName().equals( incomingName ))
251 return incomingWss;
252
253 return null;
254 }
255
256 public OutgoingWss getOutgoingWssByName( String outgoingName )
257 {
258 for( OutgoingWss crypto : outgoingWssConfigs )
259 if( crypto.getName().equals( outgoingName ))
260 return crypto;
261
262 return null;
263 }
264
265 public void addWssContainerListener( WssContainerListener listener )
266 {
267 listeners.add( listener );
268 }
269
270 public void removeWssContainerListener( WssContainerListener listener )
271 {
272 listeners.remove( listener );
273 }
274
275 public void fireWssEntryAdded( WssEntry newEntry )
276 {
277 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
278 {
279 listener.outgoingWssEntryAdded( newEntry );
280 }
281 }
282
283 public void fireWssEntryRemoved( WssEntry entry )
284 {
285 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
286 {
287 listener.outgoingWssEntryRemoved( entry );
288 }
289 }
290
291 public String[] getCryptoNames()
292 {
293 StringList result = new StringList();
294
295 for( WssCrypto crypto : getCryptoList() )
296 result.add( crypto.getLabel() );
297
298 return result.toStringArray();
299 }
300
301 public String[] getIncomingWssNames()
302 {
303 StringList result = new StringList();
304
305 for( IncomingWss crypto : getIncomingWssList() )
306 result.add( crypto.getName() );
307
308 return result.toStringArray();
309 }
310
311 public String[] getOutgoingWssNames()
312 {
313 StringList result = new StringList();
314
315 for( OutgoingWss crypto : getOutgoingWssList() )
316 result.add( crypto.getName() );
317
318 return result.toStringArray();
319 }
320
321 public void importConfig( WssContainer wssContainer )
322 {
323 }
324
325 public void resetConfig( WssContainerConfig config )
326 {
327 getConfig().set( config );
328
329 for( int c = 0; c < cryptos.size(); c++ )
330 {
331 ((KeyMaterialWssCrypto)cryptos.get( c )).udpateConfig( getConfig().getCryptoArray( c ) );
332 }
333
334 for( int c = 0; c < incomingWssConfigs.size(); c++ )
335 {
336 incomingWssConfigs.get( c ).updateConfig( getConfig().getIncomingArray( c ));
337 }
338
339 for( int c = 0; c < outgoingWssConfigs.size(); c++ )
340 {
341 outgoingWssConfigs.get( c ).updateConfig( getConfig().getOutgoingArray( c ));
342 }
343 }
344
345 public void fireCryptoUpdated( KeyMaterialWssCrypto crypto )
346 {
347 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
348 {
349 listener.cryptoUpdated( crypto );
350 }
351 }
352
353 public void resolve( ResolveContext context)
354 {
355 for( int c = 0; c < cryptos.size(); c++ )
356 {
357 ((KeyMaterialWssCrypto)cryptos.get( c )).resolve( context );
358 }
359
360 for( int c = 0; c < incomingWssConfigs.size(); c++ )
361 {
362 incomingWssConfigs.get( c ).resolve(context);
363 }
364
365 for( int c = 0; c < outgoingWssConfigs.size(); c++ )
366 {
367 outgoingWssConfigs.get( c ).resolve( context);
368 }
369 }
370 }
371