1 19 20 package org.netbeans.modules.websvc.wsitconf.ui.service; 21 22 import java.awt.Dialog ; 23 import javax.swing.undo.UndoManager ; 24 import org.netbeans.modules.websvc.wsitconf.ui.ComboConstants; 25 import org.netbeans.modules.websvc.wsitconf.ui.service.subpanels.TargetsPanel; 26 import org.netbeans.modules.websvc.wsitconf.util.UndoCounter; 27 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProfilesModelHelper; 28 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.SecurityPolicyModelHelper; 29 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.SecurityTokensModelHelper; 30 import org.netbeans.modules.xml.multiview.ui.SectionInnerPanel; 31 import org.netbeans.modules.xml.multiview.ui.SectionView; 32 import org.netbeans.modules.xml.multiview.ui.SectionVisualTheme; 33 import org.netbeans.modules.xml.wsdl.model.Binding; 34 import org.netbeans.modules.xml.wsdl.model.BindingInput; 35 import org.netbeans.modules.xml.wsdl.model.BindingOperation; 36 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 37 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 38 import org.netbeans.modules.xml.xam.ComponentEvent; 39 import org.netbeans.modules.xml.xam.ComponentListener; 40 import org.openide.DialogDescriptor; 41 import org.openide.DialogDisplayer; 42 import org.openide.nodes.Node; 43 44 import javax.swing.*; 45 import org.openide.util.NbBundle; 46 47 51 public class InputPanel extends SectionInnerPanel { 52 53 private WSDLModel model; 54 private Node node; 55 private BindingInput input; 56 private BindingOperation operation; 57 private Binding binding; 58 private UndoManager undoManager; 59 private boolean inSync = false; 60 61 private boolean signed = false; 62 private boolean endorsing = false; 63 64 public InputPanel(SectionView view, Node node, BindingInput input, UndoManager undoManager) { 65 super(view); 66 this.model = input.getModel(); 67 this.node = node; 68 this.input = input; 69 this.operation = (BindingOperation)input.getParent(); 70 this.binding = (Binding)input.getParent().getParent(); 71 this.undoManager = undoManager; 72 initComponents(); 73 74 tokenComboLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 75 tokenCombo.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 76 signedChBox.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 77 endorsingChBox.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 78 79 addImmediateModifier(tokenCombo); 80 addImmediateModifier(signedChBox); 81 addImmediateModifier(endorsingChBox); 82 83 inSync = true; 84 tokenCombo.removeAllItems(); 85 tokenCombo.addItem(ComboConstants.NONE); 86 tokenCombo.addItem(ComboConstants.USERNAME); 87 tokenCombo.addItem(ComboConstants.X509); 88 tokenCombo.addItem(ComboConstants.SAML); 89 tokenCombo.addItem(ComboConstants.ISSUED); 90 inSync = false; 92 93 sync(); 94 95 model.addComponentListener(new ComponentListener() { 96 public void valueChanged(ComponentEvent evt) { 97 sync(); 98 } 99 public void childrenAdded(ComponentEvent evt) { 100 sync(); 101 } 102 public void childrenDeleted(ComponentEvent evt) { 103 sync(); 104 } 105 }); 106 107 } 108 109 private void sync() { 110 inSync = true; 111 112 WSDLComponent token = null; 113 114 WSDLComponent t = SecurityTokensModelHelper.getSupportingToken(input, SecurityTokensModelHelper.SUPPORTING); 115 if (t != null) { 116 token = t; 117 signed = false; 118 endorsing = false; 119 } 120 t = SecurityTokensModelHelper.getSupportingToken(input, SecurityTokensModelHelper.SIGNED_SUPPORTING); 121 if (t != null) { 122 token = t; 123 signed = true; 124 endorsing = false; 125 } 126 t = SecurityTokensModelHelper.getSupportingToken(input, SecurityTokensModelHelper.ENDORSING); 127 if (t != null) { 128 token = t; 129 signed = false; 130 endorsing = true; 131 } 132 t = SecurityTokensModelHelper.getSupportingToken(input, SecurityTokensModelHelper.SIGNED_ENDORSING); 133 if (t != null) { 134 token = t; 135 signed = true; 136 endorsing = true; 137 } 138 139 signedChBox.setSelected(signed); 140 endorsingChBox.setSelected(endorsing); 141 tokenCombo.setSelectedItem(SecurityTokensModelHelper.getTokenType(token)); 142 143 enableDisable(); 144 145 inSync = false; 146 } 147 148 @Override 149 public void setValue(javax.swing.JComponent source, Object value) { 150 if (!inSync) { 151 if (source.equals(tokenCombo)) { 152 String token = (String ) tokenCombo.getSelectedItem(); 153 if (token != null) { 154 SecurityTokensModelHelper.setSupportingTokens(input, token, getSuppType(signed, endorsing)); 155 } 156 enableDisable(); 157 } 158 if (source.equals(signedChBox)) { 159 String token = (String ) tokenCombo.getSelectedItem(); 160 signed = signedChBox.isSelected(); 161 SecurityTokensModelHelper.setSupportingTokens(input, token, getSuppType(signed, endorsing)); 162 enableDisable(); 163 } 164 if (source.equals(endorsingChBox)) { 165 String token = (String ) tokenCombo.getSelectedItem(); 166 endorsing = endorsingChBox.isSelected(); 167 SecurityTokensModelHelper.setSupportingTokens(input, token, getSuppType(signed, endorsing)); 168 enableDisable(); 169 } 170 } 171 } 172 173 private int getSuppType(boolean signed, boolean endorsing) { 174 if (signed && endorsing) return SecurityTokensModelHelper.SIGNED_ENDORSING; 175 if (signed) return SecurityTokensModelHelper.SIGNED_SUPPORTING; 176 if (endorsing) return SecurityTokensModelHelper.ENDORSING; 177 return SecurityTokensModelHelper.SUPPORTING; 178 } 179 180 @Override 181 public void documentChanged(javax.swing.text.JTextComponent comp, String value) { 182 SectionView view = getSectionView(); 183 enableDisable(); 184 if (view != null) { 185 view.getErrorPanel().clearError(); 186 } 187 } 188 189 @Override 190 public void rollbackValue(javax.swing.text.JTextComponent source) { 191 } 192 193 @Override 194 protected void endUIChange() { } 195 196 public void linkButtonPressed(Object ddBean, String ddProperty) { } 197 198 public javax.swing.JComponent getErrorComponent(String errorId) { 199 return new JButton(); 200 } 201 202 private void enableDisable() { 203 boolean bSecurityEnabled = SecurityPolicyModelHelper.isSecurityEnabled(binding); 205 boolean oSecurityEnabled = SecurityPolicyModelHelper.isSecurityEnabled(operation); 206 207 String profile = null; 208 if (bSecurityEnabled) { 209 profile = ProfilesModelHelper.getSecurityProfile(binding); 210 } 211 if (oSecurityEnabled) { 212 profile = ProfilesModelHelper.getSecurityProfile(operation); 213 } 214 215 boolean secConversation = ProfilesModelHelper.isSCEnabled(binding); 216 boolean bindingScopeTokenPresent = SecurityTokensModelHelper.getSupportingToken(binding, 217 SecurityTokensModelHelper.SIGNED_SUPPORTING) != null; 218 boolean securityEnabled = bSecurityEnabled || oSecurityEnabled; 219 boolean genericProfile = true; 220 224 tokenCombo.setEnabled(securityEnabled && genericProfile && !secConversation && !bindingScopeTokenPresent); 225 tokenComboLabel.setEnabled(securityEnabled && genericProfile && !secConversation && !bindingScopeTokenPresent); 226 targetsButton.setEnabled(securityEnabled); 228 boolean tokenSelected = !ComboConstants.NONE.equals((String )tokenCombo.getSelectedItem()); 229 signedChBox.setEnabled(securityEnabled && tokenSelected && genericProfile && !secConversation && !bindingScopeTokenPresent); 230 endorsingChBox.setEnabled(securityEnabled && tokenSelected && genericProfile && !secConversation && !bindingScopeTokenPresent); 231 } 232 233 238 private void initComponents() { 240 241 tokenComboLabel = new javax.swing.JLabel (); 242 tokenCombo = new javax.swing.JComboBox (); 243 targetsButton = new javax.swing.JButton (); 244 signedChBox = new javax.swing.JCheckBox (); 245 endorsingChBox = new javax.swing.JCheckBox (); 246 247 tokenComboLabel.setLabelFor(tokenCombo); 248 org.openide.awt.Mnemonics.setLocalizedText(tokenComboLabel, org.openide.util.NbBundle.getMessage(InputPanel.class, "LBL_tokenComboLabel")); 250 tokenCombo.setModel(new javax.swing.DefaultComboBoxModel (new String [] { "X509", "Username" })); 251 252 org.openide.awt.Mnemonics.setLocalizedText(targetsButton, org.openide.util.NbBundle.getMessage(InputPanel.class, "LBL_SignEncrypt")); targetsButton.addActionListener(new java.awt.event.ActionListener () { 254 public void actionPerformed(java.awt.event.ActionEvent evt) { 255 targetsButtonActionPerformed(evt); 256 } 257 }); 258 259 org.openide.awt.Mnemonics.setLocalizedText(signedChBox, org.openide.util.NbBundle.getMessage(InputPanel.class, "LBL_Token_Signed")); signedChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 261 signedChBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 262 263 org.openide.awt.Mnemonics.setLocalizedText(endorsingChBox, org.openide.util.NbBundle.getMessage(InputPanel.class, "LBL_Token_Endorsing")); endorsingChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 265 endorsingChBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 266 267 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 268 this.setLayout(layout); 269 layout.setHorizontalGroup( 270 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 271 .add(layout.createSequentialGroup() 272 .addContainerGap() 273 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 274 .add(layout.createSequentialGroup() 275 .add(10, 10, 10) 276 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 277 .add(signedChBox) 278 .add(endorsingChBox))) 279 .add(layout.createSequentialGroup() 280 .add(tokenComboLabel) 281 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 282 .add(tokenCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 138, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 283 .add(targetsButton)) 284 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 285 ); 286 layout.setVerticalGroup( 287 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 288 .add(layout.createSequentialGroup() 289 .addContainerGap() 290 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 291 .add(tokenComboLabel) 292 .add(tokenCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 293 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 294 .add(signedChBox) 295 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 296 .add(endorsingChBox) 297 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 298 .add(targetsButton) 299 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 300 ); 301 } 303 private void targetsButtonActionPerformed(java.awt.event.ActionEvent evt) { UndoCounter undoCounter = new UndoCounter(); 305 model.addUndoableEditListener(undoCounter); 306 307 TargetsPanel targetsPanel = new TargetsPanel(input); DialogDescriptor dlgDesc = new DialogDescriptor(targetsPanel, 309 NbBundle.getMessage(InputPanel.class, "LBL_Targets_Panel_Title")); Dialog dlg = DialogDisplayer.getDefault().createDialog(dlgDesc); 311 312 dlg.setVisible(true); 313 if (dlgDesc.getValue() == dlgDesc.CANCEL_OPTION) { 314 for (int i=0; i<undoCounter.getCounter();i++) { 315 if (undoManager.canUndo()) { 316 undoManager.undo(); 317 } 318 } 319 } else { 320 SecurityPolicyModelHelper.setTargets(input, targetsPanel.getTargetsModel()); 321 } 322 323 model.removeUndoableEditListener(undoCounter); 324 } 326 private javax.swing.JCheckBox endorsingChBox; 328 private javax.swing.JCheckBox signedChBox; 329 private javax.swing.JButton targetsButton; 330 private javax.swing.JComboBox tokenCombo; 331 private javax.swing.JLabel tokenComboLabel; 332 334 } 335 | Popular Tags |