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.types.StringList;
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
78
79
80
81
82
83
84
85 return result.toArray();
86 }
87
88 public List<WssCrypto> getCryptoList()
89 {
90 return new ArrayList<WssCrypto>( cryptos );
91 }
92
93 public WssCrypto addCrypto( String source, String password )
94 {
95 KeyMaterialWssCrypto result = new KeyMaterialWssCrypto( getConfig().addNewCrypto(), this, source, password );
96 cryptos.add( result );
97
98 fireCryptoAdded( result );
99
100 return result;
101 }
102
103 protected void fireCryptoAdded( WssCrypto crypto )
104 {
105 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
106 {
107 listener.cryptoAdded( crypto );
108 }
109 }
110
111 protected void fireCryptoRemoved( WssCrypto crypto )
112 {
113 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
114 {
115 listener.cryptoRemoved( crypto );
116 }
117 }
118
119 public WssContainerConfig getConfig()
120 {
121 return config;
122 }
123
124 public int getCryptoCount()
125 {
126 return cryptos.size();
127 }
128
129 public WssCrypto getCryptoAt( int index )
130 {
131 return cryptos.get( index );
132 }
133
134 public void removeCryptoAt( int row )
135 {
136 WssCrypto crypto = cryptos.remove( row );
137 fireCryptoRemoved( crypto );
138 getConfig().removeCrypto( row );
139 }
140
141 public List<IncomingWss> getIncomingWssList()
142 {
143 return new ArrayList<IncomingWss>( incomingWssConfigs );
144 }
145
146 public IncomingWss addIncomingWss( String label )
147 {
148 IncomingWss incomingWss = new IncomingWss( getConfig().addNewIncoming(), this );
149 incomingWss.setName( label );
150 incomingWssConfigs.add( incomingWss );
151
152 fireIncomingWssAdded( incomingWss );
153
154 return incomingWss;
155 }
156
157 public int getIncomingWssCount()
158 {
159 return incomingWssConfigs.size();
160 }
161
162 public IncomingWss getIncomingWssAt( int index )
163 {
164 return incomingWssConfigs.get( index );
165 }
166
167 public void removeIncomingWssAt( int row )
168 {
169 IncomingWss incomingWss = incomingWssConfigs.remove( row );
170 fireIncomingWssRemoved( incomingWss );
171 getConfig().removeIncoming( row );
172 }
173
174 protected void fireIncomingWssAdded( IncomingWss incomingWss )
175 {
176 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
177 {
178 listener.incomingWssAdded( incomingWss );
179 }
180 }
181
182 protected void fireIncomingWssRemoved( IncomingWss incomingWss )
183 {
184 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
185 {
186 listener.incomingWssRemoved( incomingWss );
187 }
188 }
189
190 public List<OutgoingWss> getOutgoingWssList()
191 {
192 return new ArrayList<OutgoingWss>( outgoingWssConfigs );
193 }
194
195 public OutgoingWss addOutgoingWss( String label )
196 {
197 OutgoingWss result = new OutgoingWss( getConfig().addNewOutgoing(), this );
198 result.setName( label );
199
200 outgoingWssConfigs.add( result );
201
202 fireOutgoingWssAdded( result );
203
204 return result;
205 }
206
207 protected void fireOutgoingWssAdded( OutgoingWss result )
208 {
209 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
210 {
211 listener.outgoingWssAdded( result );
212 }
213 }
214
215 protected void fireOutgoingWssRemoved( OutgoingWss result )
216 {
217 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
218 {
219 listener.outgoingWssRemoved( result );
220 }
221 }
222
223 public int getOutgoingWssCount()
224 {
225 return outgoingWssConfigs.size();
226 }
227
228 public OutgoingWss getOutgoingWssAt( int index )
229 {
230 return outgoingWssConfigs.get( index );
231 }
232
233 public void removeOutgoingWssAt( int row )
234 {
235 OutgoingWss outgoingWss = outgoingWssConfigs.remove( row );
236 fireOutgoingWssRemoved( outgoingWss );
237 outgoingWss.release();
238 getConfig().removeOutgoing( row );
239 }
240
241 public WssCrypto getCryptoByName( String cryptoName )
242 {
243 for( WssCrypto crypto : cryptos )
244 if( crypto.getLabel().equals( cryptoName ))
245 return crypto;
246
247 return null;
248 }
249
250 public IncomingWss getIncomingByName( String incomingName )
251 {
252 for( IncomingWss incomingWss : incomingWssConfigs )
253 if( incomingWss.getName().equals( incomingName ))
254 return incomingWss;
255
256 return null;
257 }
258
259 public OutgoingWss getOutgoingByName( String outgoingName )
260 {
261 for( OutgoingWss crypto : outgoingWssConfigs )
262 if( crypto.getName().equals( outgoingName ))
263 return crypto;
264
265 return null;
266 }
267
268 public void addWssContainerListener( WssContainerListener listener )
269 {
270 listeners.add( listener );
271 }
272
273 public void removeWssContainerListener( WssContainerListener listener )
274 {
275 listeners.remove( listener );
276 }
277
278 public void fireWssEntryAdded( WssEntry newEntry )
279 {
280 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
281 {
282 listener.outgoingWssEntryAdded( newEntry );
283 }
284 }
285
286 public void fireWssEntryRemoved( WssEntry entry )
287 {
288 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
289 {
290 listener.outgoingWssEntryRemoved( entry );
291 }
292 }
293
294 public String[] getCryptoNames()
295 {
296 StringList result = new StringList();
297
298 for( WssCrypto crypto : getCryptoList() )
299 result.add( crypto.getLabel() );
300
301 return result.toStringArray();
302 }
303
304 public String[] getIncomingNames()
305 {
306 StringList result = new StringList();
307
308 for( IncomingWss crypto : getIncomingWssList() )
309 result.add( crypto.getName() );
310
311 return result.toStringArray();
312 }
313
314 public String[] getOutgoingNames()
315 {
316 StringList result = new StringList();
317
318 for( OutgoingWss crypto : getOutgoingWssList() )
319 result.add( crypto.getName() );
320
321 return result.toStringArray();
322 }
323
324 public void importConfig( WssContainer wssContainer )
325 {
326 }
327
328 public void resetConfig( WssContainerConfig config )
329 {
330 getConfig().set( config );
331
332 for( int c = 0; c < cryptos.size(); c++ )
333 {
334 ((KeyMaterialWssCrypto)cryptos.get( c )).udpateConfig( getConfig().getCryptoArray( c ) );
335 }
336
337 for( int c = 0; c < incomingWssConfigs.size(); c++ )
338 {
339 incomingWssConfigs.get( c ).updateConfig( getConfig().getIncomingArray( c ));
340 }
341
342 for( int c = 0; c < outgoingWssConfigs.size(); c++ )
343 {
344 outgoingWssConfigs.get( c ).updateConfig( getConfig().getOutgoingArray( c ));
345 }
346 }
347
348 public void fireCryptoUpdated( KeyMaterialWssCrypto crypto )
349 {
350 for( WssContainerListener listener : listeners.toArray( new WssContainerListener[listeners.size()] ))
351 {
352 listener.cryptoUpdated( crypto );
353 }
354 }
355 }
356