1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.panels.project;
14
15 import java.awt.BorderLayout;
16 import java.awt.Component;
17 import java.awt.Dimension;
18 import java.awt.event.ActionEvent;
19 import java.io.File;
20 import java.util.List;
21
22 import javax.swing.AbstractAction;
23 import javax.swing.DefaultCellEditor;
24 import javax.swing.JButton;
25 import javax.swing.JComboBox;
26 import javax.swing.JComponent;
27 import javax.swing.JPanel;
28 import javax.swing.JPasswordField;
29 import javax.swing.JScrollPane;
30 import javax.swing.JSplitPane;
31 import javax.swing.JTabbedPane;
32 import javax.swing.JTable;
33 import javax.swing.event.ChangeEvent;
34 import javax.swing.event.ChangeListener;
35 import javax.swing.event.ListSelectionEvent;
36 import javax.swing.event.ListSelectionListener;
37 import javax.swing.table.AbstractTableModel;
38 import javax.swing.table.TableCellRenderer;
39
40 import org.jdesktop.swingx.JXTable;
41
42 import com.eviware.soapui.SoapUI;
43 import com.eviware.soapui.impl.WorkspaceImpl;
44 import com.eviware.soapui.impl.support.actions.ShowOnlineHelpAction;
45 import com.eviware.soapui.impl.wsdl.WsdlProject;
46 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
47 import com.eviware.soapui.impl.wsdl.support.wss.IncomingWss;
48 import com.eviware.soapui.impl.wsdl.support.wss.OutgoingWss;
49 import com.eviware.soapui.impl.wsdl.support.wss.WssContainer;
50 import com.eviware.soapui.impl.wsdl.support.wss.WssContainerListener;
51 import com.eviware.soapui.impl.wsdl.support.wss.WssCrypto;
52 import com.eviware.soapui.impl.wsdl.support.wss.WssEntry;
53 import com.eviware.soapui.impl.wsdl.support.wss.WssEntryRegistry;
54 import com.eviware.soapui.impl.wsdl.support.wss.crypto.KeyMaterialWssCrypto;
55 import com.eviware.soapui.impl.wsdl.support.wss.support.KeystoresComboBoxModel;
56 import com.eviware.soapui.model.support.ModelSupport;
57 import com.eviware.soapui.support.StringUtils;
58 import com.eviware.soapui.support.UISupport;
59 import com.eviware.soapui.support.components.JXToolBar;
60
61 public class WSSTabPanel extends JPanel
62 {
63 private JXTable cryptosTable;
64 private RemoveCryptoAction removeCryptoAction;
65 private RemoveIncomingWssAction removeIncomingWssAction;
66 private JXTable incomingWssTable;
67 private JComboBox incomingWssDecryptionCryptoComboBox;
68 private JComboBox incomingWssSignatureCryptoComboBox;
69 private JXTable outgoingWssTable;
70 private RemoveOutgoingWssAction removeOutgoingWssAction;
71
72 private JButton removeOutgoingEntryButton;
73
74
75 private WssEntry selectedEntry;
76 private OutgoingWss selectedOutgoing;
77 private JButton addOutgoingEntryButton;
78 private final WssContainer wssContainer;
79 private InternalWssContainerListener wssContainerListener;
80 private JTabbedPane entriesTabs;
81
82 public WSSTabPanel( WssContainer wssContainer )
83 {
84 super( new BorderLayout() );
85 this.wssContainer = wssContainer;
86
87 wssContainerListener = new InternalWssContainerListener();
88 wssContainer.addWssContainerListener( wssContainerListener );
89
90 buildUI();
91 }
92
93 private void buildUI()
94 {
95 add( buildMainToolbar(), BorderLayout.NORTH );
96 add( buildContent(), BorderLayout.CENTER );
97 }
98
99 private JComponent buildContent()
100 {
101 JTabbedPane tabs = new JTabbedPane();
102 tabs.addTab( "Outgoing WS-Security Configurations", buildOutgoingConfigurationsTab() );
103 tabs.addTab( "Incoming WS-Security Configurations", buildIncomingConfigurationsTab() );
104 tabs.addTab( "Keystores / Certificates", buildCryptosTable() );
105
106 tabs.setMinimumSize( new Dimension( 10, 10 ) );
107
108 return UISupport.createTabPanel( tabs, true );
109 }
110
111 private JPanel buildIncomingConfigurationsTab()
112 {
113 JPanel panel = new JPanel( new BorderLayout() );
114
115 JPanel p = new JPanel( new BorderLayout() );
116 p.add( buildIncomingWssToolbar(), BorderLayout.NORTH );
117
118 incomingWssTable = new JXTable( new IncomingWssTableModel() );
119 incomingWssTable.setSortable( false );
120 incomingWssTable.getSelectionModel().addListSelectionListener( new ListSelectionListener() {
121
122 public void valueChanged( ListSelectionEvent e )
123 {
124 removeIncomingWssAction.setEnabled( incomingWssTable.getSelectedRow() != -1 );
125 }} );
126
127 incomingWssDecryptionCryptoComboBox = new JComboBox( new KeystoresComboBoxModel( wssContainer, null ));
128 incomingWssTable.getColumn( 1 ).setCellEditor( new DefaultCellEditor( incomingWssDecryptionCryptoComboBox ) );
129
130 incomingWssSignatureCryptoComboBox = new JComboBox( new KeystoresComboBoxModel( wssContainer, null ) );
131 incomingWssTable.getColumn( 2 ).setCellEditor( new DefaultCellEditor( incomingWssSignatureCryptoComboBox ) );
132
133 incomingWssTable.getColumn( 3 ).setCellEditor( new DefaultCellEditor( new JPasswordField() ));
134 incomingWssTable.getColumn( 3 ).setCellRenderer( new PasswordTableCellRenderer());
135
136 p.add( new JScrollPane( incomingWssTable ), BorderLayout.CENTER );
137 panel.add( p, BorderLayout.CENTER );
138 return panel;
139 }
140
141 private JPanel buildOutgoingConfigurationsTab()
142 {
143 JPanel panel = new JPanel( new BorderLayout() );
144
145 JPanel p = new JPanel( new BorderLayout() );
146 p.add( buildOutgoingWssToolbar(), BorderLayout.NORTH );
147
148 outgoingWssTable = new JXTable( new OutgoingWssTableModel() );
149 outgoingWssTable.setSortable( false );
150 outgoingWssTable.getSelectionModel().addListSelectionListener( new ListSelectionListener() {
151
152 public void valueChanged( ListSelectionEvent e )
153 {
154 int selectedRow = outgoingWssTable.getSelectedRow();
155 selectedOutgoing = selectedRow == -1 ? null : wssContainer.getOutgoingWssAt( selectedRow );
156 removeOutgoingWssAction.setEnabled( selectedRow != -1 );
157 addOutgoingEntryButton.setEnabled( selectedRow != -1 );
158
159
160 entriesTabs.removeAll();
161 if( selectedOutgoing != null )
162 {
163 for( WssEntry entry : selectedOutgoing.getEntries())
164 {
165 entriesTabs.addTab( entry.getLabel(), entry.getConfigurationPanel() );
166 }
167 }
168
169 entriesTabs.getParent().setVisible( entriesTabs.getTabCount() > 0 );
170 }} );
171
172 outgoingWssTable.getColumn( 2 ).setCellEditor( new DefaultCellEditor( new JPasswordField() ));
173 outgoingWssTable.getColumn( 2 ).setCellRenderer( new PasswordTableCellRenderer());
174
175 JSplitPane split = UISupport.createVerticalSplit( new JScrollPane( outgoingWssTable ), buildOutgoingWssDetails() );
176 split.setDividerLocation( 140 );
177 p.add( split, BorderLayout.CENTER );
178 panel.add( p, BorderLayout.CENTER );
179 return panel;
180 }
181
182 private Component buildOutgoingWssDetails()
183 {
184 JPanel panel = new JPanel( new BorderLayout() );
185 panel.add( buildOutgoingEntriesToolbar(), BorderLayout.NORTH );
186 panel.add( buildOutgoingEntryList(), BorderLayout.CENTER );
187
188 entriesTabs.getParent().setVisible( false );
189
190
191
192
193
194
195 return panel;
196 }
197
198
199
200
201
202
203
204
205
206
207 private Component buildOutgoingEntryList()
208 {
209
210
211
212
213
214
215
216
217
218
219
220
221 entriesTabs = new JTabbedPane();
222 entriesTabs.addChangeListener( new ChangeListener() {
223
224 public void stateChanged( ChangeEvent e )
225 {
226 selectedEntry = entriesTabs.getSelectedIndex() == -1 ? null :
227 selectedOutgoing.getEntries().get( entriesTabs.getSelectedIndex() );
228 removeOutgoingEntryButton.setEnabled( selectedEntry != null );
229 }} );
230
231
232 return UISupport.createTabPanel( entriesTabs, true );
233 }
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251 private Component buildOutgoingEntriesToolbar()
252 {
253 JXToolBar toolbar = UISupport.createSmallToolbar();
254
255 toolbar.addFixed( addOutgoingEntryButton = UISupport.createToolbarButton( new AddOutgoingEntryAction() ) );
256 toolbar.addFixed( removeOutgoingEntryButton = UISupport.createToolbarButton( new RemoveOutgoingEntryAction(), false ) );
257
258 return toolbar;
259 }
260
261 private Component buildOutgoingWssToolbar()
262 {
263 JXToolBar toolbar = UISupport.createSmallToolbar();
264
265 toolbar.addFixed( UISupport.createToolbarButton( new AddOutgoingWssAction() ));
266 removeOutgoingWssAction = new RemoveOutgoingWssAction();
267 toolbar.addFixed( UISupport.createToolbarButton( removeOutgoingWssAction ));
268 toolbar.addGlue();
269 toolbar.addFixed( UISupport.createToolbarButton( new ShowOnlineHelpAction(HelpUrls.OUTGOINGWSS_HELP_URL)));
270
271 return toolbar;
272 }
273
274 private JPanel buildCryptosTable()
275 {
276 JPanel panel = new JPanel( new BorderLayout() );
277 JPanel p = new JPanel( new BorderLayout() );
278
279 p.add( buildCryptosToolbar(), BorderLayout.NORTH );
280
281 cryptosTable = new JXTable( new CryptosTableModel() );
282 cryptosTable.setSortable( false );
283 cryptosTable.getSelectionModel().addListSelectionListener( new ListSelectionListener() {
284
285 public void valueChanged( ListSelectionEvent e )
286 {
287 removeCryptoAction.setEnabled( cryptosTable.getSelectedRow() != -1 );
288 }} );
289
290
291
292
293
294
295
296
297
298
299
300 cryptosTable.getColumn( 2 ).setCellEditor( new DefaultCellEditor( new JPasswordField() ));
301 cryptosTable.getColumn( 2 ).setCellRenderer( new PasswordTableCellRenderer());
302 cryptosTable.getColumn( 4 ).setCellEditor( new DefaultCellEditor( new JPasswordField() ));
303 cryptosTable.getColumn( 4 ).setCellRenderer( new PasswordTableCellRenderer());
304
305 p.add( new JScrollPane( cryptosTable ), BorderLayout.CENTER );
306
307 panel.add( p, BorderLayout.CENTER );
308 return panel;
309 }
310
311 private Component buildCryptosToolbar()
312 {
313 JXToolBar toolbar = UISupport.createSmallToolbar();
314
315 toolbar.addFixed( UISupport.createToolbarButton( new AddCryptoAction() ));
316 removeCryptoAction = new RemoveCryptoAction();
317 toolbar.addFixed( UISupport.createToolbarButton( removeCryptoAction ));
318 toolbar.addGlue();
319 toolbar.addFixed( UISupport.createToolbarButton( new ShowOnlineHelpAction(HelpUrls.CRYPTOSWSS_HELP_URL)));
320 return toolbar;
321 }
322
323 private Component buildIncomingWssToolbar()
324 {
325 JXToolBar toolbar = UISupport.createSmallToolbar();
326
327 toolbar.addFixed( UISupport.createToolbarButton( new AddIncomingWssAction() ));
328 removeIncomingWssAction = new RemoveIncomingWssAction();
329 toolbar.addFixed( UISupport.createToolbarButton( removeIncomingWssAction ));
330
331 toolbar.addGlue();
332 toolbar.addFixed( UISupport.createToolbarButton( new ShowOnlineHelpAction(HelpUrls.INCOMINGWSS_HELP_URL)));
333
334 return toolbar;
335 }
336
337 private Component buildMainToolbar()
338 {
339 JXToolBar toolbar = UISupport.createSmallToolbar();
340
341 toolbar.addGlue();
342 toolbar.addFixed( UISupport.createToolbarButton( new ShowOnlineHelpAction(HelpUrls.WSS_HELP_URL)));
343 return toolbar;
344 }
345
346 public void release()
347 {
348 wssContainer.removeWssContainerListener( wssContainerListener );
349
350 ((IncomingWssTableModel)incomingWssTable.getModel()).release();
351 ((OutgoingWssTableModel)outgoingWssTable.getModel()).release();
352 ((CryptosTableModel)cryptosTable.getModel()).release();
353
354 ((KeystoresComboBoxModel)incomingWssDecryptionCryptoComboBox.getModel()).release();
355 ((KeystoresComboBoxModel)incomingWssSignatureCryptoComboBox.getModel()).release();
356
357 entriesTabs.removeAll();
358 }
359
360 public class CryptosTableModel extends AbstractTableModel
361 {
362 private static final String DEFAULT_OPTION = "<Default>";
363 private List<WssCrypto> cryptos;
364
365 public CryptosTableModel()
366 {
367 cryptos = wssContainer.getCryptoList();
368 }
369
370 public void release()
371 {
372 cryptos = null;
373 }
374
375 public int getColumnCount()
376 {
377
378 return 5;
379 }
380
381 @Override
382 public String getColumnName( int column )
383 {
384 switch( column )
385 {
386 case 0:
387 return "Source";
388 case 1:
389 return "Status";
390 case 2:
391 return "Password";
392 case 3:
393 return "Default Alias";
394 case 4:
395 return "Alias Password";
396 case 5:
397 return "Security Provider";
398 }
399
400 return null;
401 }
402
403 public int getRowCount()
404 {
405 return cryptos == null ? 0 : cryptos.size();
406 }
407
408 @Override
409 public boolean isCellEditable( int rowIndex, int columnIndex )
410 {
411 return columnIndex > 1;
412 }
413
414 public Object getValueAt( int rowIndex, int columnIndex )
415 {
416 KeyMaterialWssCrypto crypto = ( KeyMaterialWssCrypto ) cryptos.get( rowIndex );
417
418 switch( columnIndex )
419 {
420 case 0:
421 return crypto.getSource();
422 case 1:
423 return crypto.getStatus();
424 case 2:
425 return crypto.getPassword();
426 case 3:
427 return crypto.getDefaultAlias();
428 case 4:
429 return crypto.getAliasPassword();
430 case 5:
431 return StringUtils.hasContent( crypto.getCryptoProvider() ) ? crypto.getCryptoProvider() : DEFAULT_OPTION;
432 }
433
434 return null;
435 }
436
437 @Override
438 public void setValueAt( Object aValue, int rowIndex, int columnIndex )
439 {
440 KeyMaterialWssCrypto crypto = ( KeyMaterialWssCrypto ) cryptos.get( rowIndex );
441 if( aValue == null || aValue.equals( DEFAULT_OPTION ) )
442 aValue = "";
443
444 switch( columnIndex )
445 {
446 case 2:
447 crypto.setPassword( aValue.toString() ); break;
448 case 3:
449 crypto.setDefaultAlias( aValue.toString() ); break;
450 case 4:
451 crypto.setAliasPassword( aValue.toString() ); break;
452 case 5:
453 crypto.setCryptoProvider( aValue.toString() ); break;
454 }
455 }
456
457 public void cryptoAdded( WssCrypto crypto )
458 {
459 cryptos.add( crypto );
460 fireTableRowsInserted( cryptos.size()-1, cryptos.size()-1 );
461 }
462
463 public void cryptoRemoved( WssCrypto crypto )
464 {
465 int ix = cryptos.indexOf( crypto );
466 if( ix != -1 )
467 {
468 cryptos.remove( ix );
469 fireTableRowsDeleted( ix, ix );
470 }
471 }
472 }
473
474 private class AddCryptoAction extends AbstractAction
475 {
476 public AddCryptoAction()
477 {
478 putValue( SMALL_ICON, UISupport.createImageIcon( "/add_property.gif" ));
479 putValue( SHORT_DESCRIPTION, "Adds a new crypto to this configuration" );
480 }
481
482 public void actionPerformed( ActionEvent e )
483 {
484 File file = UISupport.getFileDialogs().open( this, "Select Key Material", null, null, null );
485 if( file != null )
486 {
487 String password = UISupport.prompt( "Specify password for [" + file.getName() + "]", "Add Key Material", "" );
488 wssContainer.addCrypto( file.getAbsolutePath(), password );
489 cryptosTable.setRowSelectionInterval( cryptosTable.getRowCount()-1, cryptosTable.getRowCount()-1 );
490 }
491 }
492 }
493
494 private class RemoveCryptoAction extends AbstractAction
495 {
496 public RemoveCryptoAction()
497 {
498 putValue( SMALL_ICON, UISupport.createImageIcon( "/remove_property.gif" ));
499 putValue( SHORT_DESCRIPTION, "Removes the selected crypto from this configuration" );
500
501 setEnabled( false );
502 }
503
504 public void actionPerformed( ActionEvent e )
505 {
506 int row = cryptosTable.getSelectedRow();
507 if( row == -1 )
508 return;
509
510 if( UISupport.confirm( "Removes selected crypto?", "Remove Crypto" ))
511 {
512 wssContainer.removeCryptoAt( row );
513 }
514 }
515 }
516
517 public class IncomingWssTableModel extends AbstractTableModel
518 {
519 private List<IncomingWss> incomingWss;
520
521 public IncomingWssTableModel()
522 {
523 incomingWss = wssContainer.getIncomingWssList();
524 }
525
526 public void release()
527 {
528 incomingWss = null;
529 }
530
531 public int getColumnCount()
532 {
533 return 4;
534 }
535
536 @Override
537 public String getColumnName( int column )
538 {
539 switch( column )
540 {
541 case 0:
542 return "Name";
543 case 1:
544 return "Decrypt Keystore";
545 case 2:
546 return "Signature Keystore";
547 case 3:
548 return "Password";
549 }
550
551 return null;
552 }
553
554 public int getRowCount()
555 {
556 return incomingWss == null ? 0 : incomingWss.size();
557 }
558
559 @Override
560 public boolean isCellEditable( int rowIndex, int columnIndex )
561 {
562 return columnIndex > 0;
563 }
564
565 public Object getValueAt( int rowIndex, int columnIndex )
566 {
567 IncomingWss incoming = incomingWss.get( rowIndex );
568
569 switch( columnIndex )
570 {
571 case 0:
572 return incoming.getName();
573 case 1:
574 return wssContainer.getCryptoByName( incoming.getDecryptCrypto() );
575 case 2:
576 return wssContainer.getCryptoByName( incoming.getSignatureCrypto() );
577 case 3:
578 return incoming.getDecryptPassword();
579 }
580
581 return null;
582 }
583
584 @Override
585 public void setValueAt( Object aValue, int rowIndex, int columnIndex )
586 {
587 IncomingWss incoming = incomingWss.get( rowIndex );
588
589 switch( columnIndex )
590 {
591 case 1:
592 incoming.setDecryptCrypto( aValue == null ? null : aValue.toString() ); break;
593 case 2:
594 incoming.setSignatureCrypto( aValue == null ? null : aValue.toString() ); break;
595 case 3:
596 incoming.setDecryptPassword( aValue == null ? null : aValue.toString() ); break;
597 }
598 }
599
600 public void incomingWssAdded( IncomingWss incoming )
601 {
602 incomingWss.add( incoming );
603 fireTableRowsInserted( incomingWss.size()-1, incomingWss.size()-1 );
604
605 }
606
607 public void incomingWssRemoved( IncomingWss incoming )
608 {
609 int ix = incomingWss.indexOf( incoming );
610 if( ix != -1 )
611 {
612 incomingWss.remove( ix );
613 fireTableRowsDeleted( ix, ix );
614 }
615 }
616 }
617
618 private class AddIncomingWssAction extends AbstractAction
619 {
620 public AddIncomingWssAction()
621 {
622 putValue( SMALL_ICON, UISupport.createImageIcon( "/add_property.gif" ));
623 putValue( SHORT_DESCRIPTION, "Adds a new Incoming WSS Configuration" );
624 }
625
626 public void actionPerformed( ActionEvent e )
627 {
628 String name = UISupport.prompt( "Specify unique name for configuration", "New Incoming WSS Configuration", "" );
629 if( StringUtils.hasContent( name ) && wssContainer.getIncomingWssByName( name ) == null )
630 {
631 wssContainer.addIncomingWss( name );
632 incomingWssTable.setRowSelectionInterval( incomingWssTable.getRowCount()-1, incomingWssTable.getRowCount()-1 );
633 }
634 }
635 }
636
637 private class RemoveIncomingWssAction extends AbstractAction
638 {
639 public RemoveIncomingWssAction()
640 {
641 putValue( SMALL_ICON, UISupport.createImageIcon( "/remove_property.gif" ));
642 putValue( SHORT_DESCRIPTION, "Removes the selected Incoming WSS Configuration" );
643
644 setEnabled( false );
645 }
646
647 public void actionPerformed( ActionEvent e )
648 {
649 int row = incomingWssTable.getSelectedRow();
650 if( row == -1 )
651 return;
652
653 if( UISupport.confirm( "Removes selected configuration?", "Remove Configuration" ))
654 {
655 wssContainer.removeIncomingWssAt( row );
656 }
657 }
658 }
659
660 public class OutgoingWssTableModel extends AbstractTableModel
661 {
662 private List<OutgoingWss> outgoingWss;
663
664 public OutgoingWssTableModel()
665 {
666 outgoingWss = wssContainer.getOutgoingWssList();
667 }
668
669 public void release()
670 {
671 outgoingWss = null;
672 }
673
674 public int getColumnCount()
675 {
676 return 5;
677 }
678
679 @Override
680 public String getColumnName( int column )
681 {
682 switch( column )
683 {
684 case 0:
685 return "Name";
686 case 1:
687 return "Default Username/Alias";
688 case 2:
689 return "Default Password";
690 case 3:
691 return "Actor";
692 case 4:
693 return "Must Understand";
694 }
695
696 return null;
697 }
698
699 @Override
700 public Class<?> getColumnClass(int columnIndex)
701 {
702 return columnIndex == 4 ? Boolean.class : String.class;
703 }
704
705 public int getRowCount()
706 {
707 return outgoingWss == null ? 0 : outgoingWss.size();
708 }
709
710 @Override
711 public boolean isCellEditable( int rowIndex, int columnIndex )
712 {
713 return columnIndex > 0;
714 }
715
716 public Object getValueAt( int rowIndex, int columnIndex )
717 {
718 OutgoingWss outgoing = outgoingWss.get( rowIndex );
719
720 switch( columnIndex )
721 {
722 case 0:
723 return outgoing.getName();
724 case 1:
725 return outgoing.getUsername();
726 case 2:
727 return outgoing.getPassword();
728 case 3:
729 return outgoing.getActor();
730 case 4:
731 return outgoing.getMustUnderstand();
732 }
733
734 return null;
735 }
736
737 @Override
738 public void setValueAt( Object aValue, int rowIndex, int columnIndex )
739 {
740 OutgoingWss outgoing = outgoingWss.get( rowIndex );
741
742 switch( columnIndex )
743 {
744 case 1:
745 outgoing.setUsername( aValue == null ? null : aValue.toString() ); break;
746 case 2:
747 outgoing.setPassword( aValue == null ? null : aValue.toString() ); break;
748 case 3:
749 outgoing.setActor(aValue == null ? null : aValue.toString() ); break;
750 case 4:
751 outgoing.setMustUnderstand(aValue == null ? false : (Boolean)aValue ); break;
752 }
753 }
754
755 public void outgoingWssAdded( OutgoingWss outgoing )
756 {
757 outgoingWss.add( outgoing );
758 fireTableRowsInserted( outgoingWss.size()-1, outgoingWss.size()-1 );
759 }
760
761 public void outgoingWssRemoved( OutgoingWss outgoing )
762 {
763 int ix = outgoingWss.indexOf( outgoing );
764 if( ix != -1 )
765 {
766 outgoingWss.remove( ix );
767 fireTableRowsDeleted( ix, ix );
768 }
769 }
770 }
771
772 private class AddOutgoingWssAction extends AbstractAction
773 {
774 public AddOutgoingWssAction()
775 {
776 putValue( SMALL_ICON, UISupport.createImageIcon( "/add_property.gif" ));
777 putValue( SHORT_DESCRIPTION, "Adds a new Outgoing WSS Configuration" );
778 }
779
780 public void actionPerformed( ActionEvent e )
781 {
782 String name = UISupport.prompt( "Specify unique name for configuration", "New Outgoing WSS Configuration", "" );
783 if( StringUtils.hasContent( name ) && wssContainer.getOutgoingWssByName( name ) == null )
784 {
785 wssContainer.addOutgoingWss( name );
786 outgoingWssTable.setRowSelectionInterval( outgoingWssTable.getRowCount()-1, outgoingWssTable.getRowCount()-1 );
787 }
788 }
789 }
790
791 private class RemoveOutgoingWssAction extends AbstractAction
792 {
793 public RemoveOutgoingWssAction()
794 {
795 putValue( SMALL_ICON, UISupport.createImageIcon( "/remove_property.gif" ));
796 putValue( SHORT_DESCRIPTION, "Removes the selected Outgoing WSS Configuration" );
797
798 setEnabled( false );
799 }
800
801 public void actionPerformed( ActionEvent e )
802 {
803 int row = outgoingWssTable.getSelectedRow();
804 if( row == -1 )
805 return;
806
807 if( UISupport.confirm( "Removes selected configuration?", "Remove Configuration" ))
808 {
809 wssContainer.removeOutgoingWssAt( row );
810 }
811 }
812 }
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872 public class AddOutgoingEntryAction extends AbstractAction
873 {
874 public AddOutgoingEntryAction()
875 {
876 putValue( SHORT_DESCRIPTION, "Adds a new WSS Entry" );
877 putValue( SMALL_ICON, UISupport.createImageIcon( "/add_property.gif" ) );
878 setEnabled( false );
879 }
880
881 public void actionPerformed( ActionEvent e )
882 {
883 if( selectedOutgoing == null )
884 return;
885
886 String type = UISupport.prompt( "Select type of entry to add", "Add WSS Entry", WssEntryRegistry.get()
887 .getTypes() );
888 if( type != null )
889 {
890 WssEntry entry = selectedOutgoing.addEntry( type );
891 entriesTabs.setSelectedComponent( entry.getConfigurationPanel() );
892
893
894
895 }
896 }
897 }
898
899 public class RemoveOutgoingEntryAction extends AbstractAction
900 {
901 public RemoveOutgoingEntryAction()
902 {
903 putValue( SHORT_DESCRIPTION, "Removes the selected WSS-Entry" );
904 putValue( SMALL_ICON, UISupport.createImageIcon( "/remove_property.gif" ) );
905 }
906
907 public void actionPerformed( ActionEvent e )
908 {
909 if( selectedEntry == null )
910 return;
911
912 if( UISupport.confirm( "Remove entry [" + selectedEntry.getLabel() + "]", "Remove WSS Entry" ) )
913 {
914 selectedOutgoing.removeEntry( selectedEntry );
915 }
916 }
917 }
918
919 private class InternalWssContainerListener implements WssContainerListener
920 {
921 public void cryptoAdded( WssCrypto crypto )
922 {
923 ((CryptosTableModel)cryptosTable.getModel()).cryptoAdded( crypto );
924 }
925
926 public void cryptoRemoved( WssCrypto crypto )
927 {
928 ((CryptosTableModel)cryptosTable.getModel()).cryptoRemoved( crypto );
929 }
930
931 public void incomingWssAdded( IncomingWss incomingWss )
932 {
933 ((IncomingWssTableModel)incomingWssTable.getModel()).incomingWssAdded( incomingWss );
934
935 }
936
937 public void incomingWssRemoved( IncomingWss incomingWss )
938 {
939 ((IncomingWssTableModel)incomingWssTable.getModel()).incomingWssRemoved( incomingWss );
940
941 }
942
943 public void outgoingWssAdded( OutgoingWss outgoingWss )
944 {
945 ((OutgoingWssTableModel)outgoingWssTable.getModel()).outgoingWssAdded( outgoingWss );
946 }
947
948 public void outgoingWssEntryAdded( WssEntry entry )
949 {
950 if( entry.getOutgoingWss() == selectedOutgoing )
951 {
952 entriesTabs.addTab( entry.getLabel(), entry.getConfigurationPanel() );
953 entriesTabs.getParent().setVisible( true);
954 }
955
956 }
957
958 public void outgoingWssEntryRemoved( WssEntry entry )
959 {
960 if( entry.getOutgoingWss() == selectedOutgoing )
961 {
962 int ix = entriesTabs.indexOfComponent( entry.getConfigurationPanel() );
963 if( ix != -1 )
964 entriesTabs.remove( ix );
965
966 entriesTabs.getParent().setVisible( entriesTabs.getTabCount() > 0 );
967 }
968
969 }
970
971 public void outgoingWssRemoved( OutgoingWss outgoingWss )
972 {
973 ((OutgoingWssTableModel)outgoingWssTable.getModel()).outgoingWssRemoved( outgoingWss );
974 }
975
976 public void cryptoUpdated( WssCrypto crypto )
977 {
978 }
979 }
980
981 public class ImportWssSettingsAction extends AbstractAction
982 {
983 public ImportWssSettingsAction()
984 {
985 putValue( SHORT_DESCRIPTION, "Imports an existing WS-Security configuration from another project" );
986 putValue( SMALL_ICON, UISupport.createImageIcon( "/load_properties.gif" ) );
987 }
988
989 public void actionPerformed( ActionEvent e )
990 {
991 String[] names = ModelSupport.getNames( ((WorkspaceImpl)SoapUI.getWorkspace()).getOpenProjectList() );
992 String projectName = UISupport.prompt( "Select project to import from", "Import WSS Settings", names );
993 if( projectName != null )
994 {
995 WsdlProject prj = ( WsdlProject ) SoapUI.getWorkspace().getProjectByName( projectName );
996 wssContainer.importConfig( prj.getWssContainer() );
997 }
998 }
999 }
1000
1001 public static class PasswordTableCellRenderer extends JPasswordField implements TableCellRenderer
1002 {
1003 public PasswordTableCellRenderer()
1004 {
1005 setEditable( false );
1006 setBorder( null );
1007 }
1008
1009 public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column )
1010 {
1011 setBackground( table.getBackground() );
1012 setText( value == null ? "" : value.toString() );
1013 return this;
1014 }
1015
1016 }
1017 }