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