1 19 20 package org.netbeans.modules.websvc.wsitconf.ui.service.profiles; 21 22 import javax.swing.JCheckBox ; 23 import javax.swing.JComboBox ; 24 import org.netbeans.modules.websvc.wsitconf.ui.ComboConstants; 25 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.AlgoSuiteModelHelper; 26 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.PolicyModelHelper; 27 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProfilesModelHelper; 28 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.RMModelHelper; 29 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.SecurityPolicyModelHelper; 30 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.SecurityTokensModelHelper; 31 import org.netbeans.modules.websvc.wsitmodelext.policy.Policy; 32 import org.netbeans.modules.websvc.wsitmodelext.security.BootstrapPolicy; 33 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.ProtectionToken; 34 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.SecureConversationToken; 35 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 36 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 37 38 42 public class UsernameAuthentication extends javax.swing.JPanel { 43 44 private boolean inSync = false; 45 46 private WSDLComponent comp; 47 private WSDLModel model; 48 49 52 public UsernameAuthentication(WSDLComponent comp) { 53 super(); 54 initComponents(); 55 this.model = comp.getModel(); 56 this.comp = comp; 57 58 inSync = true; 59 supportTokenCombo.removeAllItems(); 60 supportTokenCombo.addItem(ComboConstants.X509); 61 supportTokenCombo.addItem(ComboConstants.USERNAME); 62 63 layoutCombo.removeAllItems(); 64 layoutCombo.addItem(ComboConstants.STRICT); 65 layoutCombo.addItem(ComboConstants.LAX); 66 layoutCombo.addItem(ComboConstants.LAXTSFIRST); 67 layoutCombo.addItem(ComboConstants.LAXTSLAST); 68 69 algoSuiteCombo.removeAllItems(); 70 algoSuiteCombo.addItem(ComboConstants.BASIC256); 71 algoSuiteCombo.addItem(ComboConstants.BASIC192); 72 algoSuiteCombo.addItem(ComboConstants.BASIC128); 73 algoSuiteCombo.addItem(ComboConstants.TRIPLEDES); 74 algoSuiteCombo.addItem(ComboConstants.BASIC256RSA15); 75 algoSuiteCombo.addItem(ComboConstants.BASIC192RSA15); 76 algoSuiteCombo.addItem(ComboConstants.BASIC128RSA15); 77 algoSuiteCombo.addItem(ComboConstants.TRIPLEDESRSA15); 78 87 inSync = false; 88 89 sync(); 90 } 91 92 private void sync() { 93 inSync = true; 94 95 WSDLComponent secBinding = null; 96 WSDLComponent topSecBinding = SecurityPolicyModelHelper.getSecurityBindingTypeElement(comp); 97 WSDLComponent protTokenKind = SecurityTokensModelHelper.getTokenElement(topSecBinding, ProtectionToken.class); 98 WSDLComponent protToken = SecurityTokensModelHelper.getTokenTypeElement(protTokenKind); 99 100 boolean secConv = (protToken instanceof SecureConversationToken); 101 102 if (secConv) { 103 WSDLComponent bootPolicy = SecurityTokensModelHelper.getTokenElement(protToken, BootstrapPolicy.class); 104 secBinding = SecurityPolicyModelHelper.getSecurityBindingTypeElement(bootPolicy); 105 Policy p = (Policy) secBinding.getParent(); 106 setChBox(secConvChBox, true); 107 setChBox(derivedKeysChBox, SecurityPolicyModelHelper.isRequireDerivedKeys(protToken)); 108 setChBox(reqSigConfChBox, SecurityPolicyModelHelper.isRequireSignatureConfirmation(p)); 109 setChBox(encryptSignatureChBox, SecurityPolicyModelHelper.isEncryptSignature(bootPolicy)); 110 setChBox(encryptOrderChBox, SecurityPolicyModelHelper.isEncryptBeforeSigning(bootPolicy)); 111 p = PolicyModelHelper.getTopLevelElement(bootPolicy, Policy.class); 112 WSDLComponent tokenKind = SecurityTokensModelHelper.getSupportingToken(p, SecurityTokensModelHelper.SIGNED_SUPPORTING); 113 String tokenType = SecurityTokensModelHelper.getTokenType(tokenKind); 114 setCombo(supportTokenCombo, tokenType); 115 } else { 116 secBinding = SecurityPolicyModelHelper.getSecurityBindingTypeElement(comp); 117 setChBox(secConvChBox, false); 118 setChBox(reqSigConfChBox, SecurityPolicyModelHelper.isRequireSignatureConfirmation(comp)); 119 setChBox(encryptSignatureChBox, SecurityPolicyModelHelper.isEncryptSignature(comp)); 120 setChBox(encryptOrderChBox, SecurityPolicyModelHelper.isEncryptBeforeSigning(comp)); 121 WSDLComponent tokenKind = SecurityTokensModelHelper.getSupportingToken(comp, SecurityTokensModelHelper.SIGNED_SUPPORTING); 122 String tokenType = SecurityTokensModelHelper.getTokenType(tokenKind); 123 setCombo(supportTokenCombo, tokenType); 124 } 125 126 WSDLComponent tokenKind = SecurityTokensModelHelper.getTokenElement(secBinding, ProtectionToken.class); 127 WSDLComponent token = SecurityTokensModelHelper.getTokenTypeElement(tokenKind); 128 setChBox(reqDerivedKeys, SecurityPolicyModelHelper.isRequireDerivedKeys(token)); 129 130 setCombo(algoSuiteCombo, AlgoSuiteModelHelper.getAlgorithmSuite(secBinding)); 131 setCombo(layoutCombo, SecurityPolicyModelHelper.getMessageLayout(secBinding)); 132 133 enableDisable(); 134 135 inSync = false; 136 } 137 138 public void setValue(javax.swing.JComponent source) { 139 140 if (inSync) return; 141 142 WSDLComponent secBinding = null; 143 WSDLComponent topSecBinding = SecurityPolicyModelHelper.getSecurityBindingTypeElement(comp); 144 WSDLComponent protTokenKind = SecurityTokensModelHelper.getTokenElement(topSecBinding, ProtectionToken.class); 145 WSDLComponent protToken = SecurityTokensModelHelper.getTokenTypeElement(protTokenKind); 146 147 boolean secConv = (protToken instanceof SecureConversationToken); 148 149 if (source.equals(secConvChBox)) { 150 ProfilesModelHelper.enableSecureConversation(comp, secConvChBox.isSelected(), ComboConstants.PROF_MSGAUTHSSL); 151 } 152 153 if (secConv) { 154 WSDLComponent bootPolicy = SecurityTokensModelHelper.getTokenElement(protToken, BootstrapPolicy.class); 155 secBinding = SecurityPolicyModelHelper.getSecurityBindingTypeElement(bootPolicy); 156 Policy p = (Policy) secBinding.getParent(); 157 if (source.equals(reqSigConfChBox)) { 158 SecurityPolicyModelHelper.enableRequireSignatureConfirmation( 159 SecurityPolicyModelHelper.getWss11(p), reqSigConfChBox.isSelected()); 160 } 161 if (source.equals(derivedKeysChBox)) { 162 SecurityPolicyModelHelper.enableRequireDerivedKeys(protToken, derivedKeysChBox.isSelected()); 163 } 164 p = PolicyModelHelper.getTopLevelElement(bootPolicy, Policy.class); 165 if (source.equals(supportTokenCombo)) { 166 SecurityTokensModelHelper.setSupportingTokens(p, 167 (String )supportTokenCombo.getSelectedItem(), 168 SecurityTokensModelHelper.SIGNED_SUPPORTING); 169 } 170 171 } else { 172 secBinding = SecurityPolicyModelHelper.getSecurityBindingTypeElement(comp); 173 if (source.equals(reqSigConfChBox)) { 174 SecurityPolicyModelHelper.enableRequireSignatureConfirmation(SecurityPolicyModelHelper.getWss11(comp), reqSigConfChBox.isSelected()); 175 } 176 if (source.equals(supportTokenCombo)) { 177 SecurityTokensModelHelper.setSupportingTokens(comp, 178 (String )supportTokenCombo.getSelectedItem(), 179 SecurityTokensModelHelper.SIGNED_SUPPORTING); 180 } 181 } 182 183 if (source.equals(encryptSignatureChBox)) { 184 SecurityPolicyModelHelper.enableEncryptSignature(secBinding, encryptSignatureChBox.isSelected()); 185 if (secConv) { 186 SecurityPolicyModelHelper.enableEncryptSignature(topSecBinding, encryptSignatureChBox.isSelected()); 187 } 188 } 189 if (source.equals(encryptOrderChBox)) { 190 SecurityPolicyModelHelper.enableEncryptBeforeSigning(secBinding, encryptOrderChBox.isSelected()); 191 if (secConv) { 192 SecurityPolicyModelHelper.enableEncryptBeforeSigning(topSecBinding, encryptOrderChBox.isSelected()); 193 } 194 } 195 if (source.equals(layoutCombo)) { 196 SecurityPolicyModelHelper.setLayout(secBinding, (String ) layoutCombo.getSelectedItem()); 197 if (secConv) { 198 SecurityPolicyModelHelper.setLayout(topSecBinding, (String ) layoutCombo.getSelectedItem()); 199 } 200 } 201 if (source.equals(algoSuiteCombo)) { 202 AlgoSuiteModelHelper.setAlgorithmSuite(secBinding, (String ) algoSuiteCombo.getSelectedItem()); 203 if (secConv) { 204 AlgoSuiteModelHelper.setAlgorithmSuite(topSecBinding, (String ) algoSuiteCombo.getSelectedItem()); 205 } 206 } 207 if (source.equals(reqDerivedKeys)) { 208 WSDLComponent tokenKind = SecurityTokensModelHelper.getTokenElement(secBinding, ProtectionToken.class); 209 WSDLComponent token = SecurityTokensModelHelper.getTokenTypeElement(tokenKind); 210 SecurityPolicyModelHelper.enableRequireDerivedKeys(token, reqDerivedKeys.isSelected()); 211 return; 212 } 213 214 enableDisable(); 215 } 216 217 private void enableDisable() { 218 boolean secConvEnabled = secConvChBox.isSelected(); 219 derivedKeysChBox.setEnabled(secConvEnabled); 220 boolean rmEnabled = RMModelHelper.isRMEnabled(comp); 221 if (rmEnabled) { 222 secConvChBox.setEnabled(!secConvEnabled); 223 } else { 224 secConvChBox.setEnabled(true); 225 } 226 } 227 228 private void setCombo(JComboBox combo, String item) { 229 if (item == null) { 230 combo.setSelectedIndex(0); 231 } else { 232 combo.setSelectedItem(item); 233 } 234 } 235 236 private void setChBox(JCheckBox chBox, Boolean enable) { 237 if (enable == null) { 238 chBox.setSelected(false); 239 } else { 240 chBox.setSelected(enable); 241 } 242 } 243 244 249 private void initComponents() { 251 252 secConvChBox = new javax.swing.JCheckBox (); 253 reqSigConfChBox = new javax.swing.JCheckBox (); 254 derivedKeysChBox = new javax.swing.JCheckBox (); 255 algoSuiteLabel = new javax.swing.JLabel (); 256 algoSuiteCombo = new javax.swing.JComboBox (); 257 layoutLabel = new javax.swing.JLabel (); 258 layoutCombo = new javax.swing.JComboBox (); 259 encryptSignatureChBox = new javax.swing.JCheckBox (); 260 reqDerivedKeys = new javax.swing.JCheckBox (); 261 encryptOrderChBox = new javax.swing.JCheckBox (); 262 supportTokenLabel = new javax.swing.JLabel (); 263 supportTokenCombo = new javax.swing.JComboBox (); 264 265 org.openide.awt.Mnemonics.setLocalizedText(secConvChBox, org.openide.util.NbBundle.getMessage(UsernameAuthentication.class, "LBL_SecConvLabel")); secConvChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 267 secConvChBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 268 secConvChBox.addActionListener(new java.awt.event.ActionListener () { 269 public void actionPerformed(java.awt.event.ActionEvent evt) { 270 secConvChBoxActionPerformed(evt); 271 } 272 }); 273 274 org.openide.awt.Mnemonics.setLocalizedText(reqSigConfChBox, org.openide.util.NbBundle.getMessage(UsernameAuthentication.class, "LBL_RequireSigConfirmation")); reqSigConfChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 276 reqSigConfChBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 277 reqSigConfChBox.addActionListener(new java.awt.event.ActionListener () { 278 public void actionPerformed(java.awt.event.ActionEvent evt) { 279 reqSigConfChBoxActionPerformed(evt); 280 } 281 }); 282 283 org.openide.awt.Mnemonics.setLocalizedText(derivedKeysChBox, org.openide.util.NbBundle.getMessage(UsernameAuthentication.class, "LBL_RequireDerivedKeysForSecConv")); derivedKeysChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 285 derivedKeysChBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 286 derivedKeysChBox.addActionListener(new java.awt.event.ActionListener () { 287 public void actionPerformed(java.awt.event.ActionEvent evt) { 288 derivedKeysChBoxActionPerformed(evt); 289 } 290 }); 291 292 algoSuiteLabel.setLabelFor(algoSuiteCombo); 293 org.openide.awt.Mnemonics.setLocalizedText(algoSuiteLabel, org.openide.util.NbBundle.getMessage(UsernameAuthentication.class, "LBL_AlgoSuiteLabel")); 295 algoSuiteCombo.addActionListener(new java.awt.event.ActionListener () { 296 public void actionPerformed(java.awt.event.ActionEvent evt) { 297 algoSuiteComboActionPerformed(evt); 298 } 299 }); 300 301 layoutLabel.setLabelFor(layoutCombo); 302 org.openide.awt.Mnemonics.setLocalizedText(layoutLabel, org.openide.util.NbBundle.getMessage(UsernameAuthentication.class, "LBL_LayoutLabel")); 304 layoutCombo.addActionListener(new java.awt.event.ActionListener () { 305 public void actionPerformed(java.awt.event.ActionEvent evt) { 306 layoutComboActionPerformed(evt); 307 } 308 }); 309 310 org.openide.awt.Mnemonics.setLocalizedText(encryptSignatureChBox, org.openide.util.NbBundle.getMessage(UsernameAuthentication.class, "LBL_EncryptSignatureLabel")); encryptSignatureChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 312 encryptSignatureChBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 313 encryptSignatureChBox.addActionListener(new java.awt.event.ActionListener () { 314 public void actionPerformed(java.awt.event.ActionEvent evt) { 315 encryptSignatureChBox(evt); 316 } 317 }); 318 319 org.openide.awt.Mnemonics.setLocalizedText(reqDerivedKeys, org.openide.util.NbBundle.getMessage(UsernameAuthentication.class, "LBL_RequireDerivedKeys")); reqDerivedKeys.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 321 reqDerivedKeys.setMargin(new java.awt.Insets (0, 0, 0, 0)); 322 reqDerivedKeys.addActionListener(new java.awt.event.ActionListener () { 323 public void actionPerformed(java.awt.event.ActionEvent evt) { 324 reqDerivedKeysActionPerformed(evt); 325 } 326 }); 327 328 org.openide.awt.Mnemonics.setLocalizedText(encryptOrderChBox, org.openide.util.NbBundle.getMessage(UsernameAuthentication.class, "LBL_EncryptOrderLabel")); encryptOrderChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 330 encryptOrderChBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 331 encryptOrderChBox.addActionListener(new java.awt.event.ActionListener () { 332 public void actionPerformed(java.awt.event.ActionEvent evt) { 333 encryptOrderChBoxActionPerformed(evt); 334 } 335 }); 336 337 org.openide.awt.Mnemonics.setLocalizedText(supportTokenLabel, org.openide.util.NbBundle.getMessage(UsernameAuthentication.class, "LBL_AuthToken")); 339 supportTokenCombo.addActionListener(new java.awt.event.ActionListener () { 340 public void actionPerformed(java.awt.event.ActionEvent evt) { 341 supportTokenComboActionPerformed(evt); 342 } 343 }); 344 345 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 346 this.setLayout(layout); 347 layout.setHorizontalGroup( 348 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 349 .add(layout.createSequentialGroup() 350 .addContainerGap() 351 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) 352 .add(reqDerivedKeys) 353 .add(reqSigConfChBox) 354 .add(secConvChBox) 355 .add(derivedKeysChBox) 356 .add(encryptSignatureChBox) 357 .add(encryptOrderChBox) 358 .add(layout.createSequentialGroup() 359 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 360 .add(layoutLabel) 361 .add(algoSuiteLabel) 362 .add(supportTokenLabel)) 363 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 364 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) 365 .add(supportTokenCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 145, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 366 .add(algoSuiteCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 145, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 367 .add(layoutCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 145, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))) 368 .addContainerGap()) 369 ); 370 371 layout.linkSize(new java.awt.Component [] {algoSuiteCombo, layoutCombo, supportTokenCombo}, org.jdesktop.layout.GroupLayout.HORIZONTAL); 372 373 layout.setVerticalGroup( 374 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 375 .add(layout.createSequentialGroup() 376 .addContainerGap() 377 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 378 .add(supportTokenLabel) 379 .add(supportTokenCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 380 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 381 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 382 .add(algoSuiteLabel) 383 .add(algoSuiteCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 384 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 385 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 386 .add(layoutLabel) 387 .add(layoutCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 388 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 389 .add(reqDerivedKeys) 390 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 391 .add(secConvChBox) 392 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 393 .add(derivedKeysChBox) 394 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 395 .add(reqSigConfChBox) 396 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 397 .add(encryptSignatureChBox) 398 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 399 .add(encryptOrderChBox) 400 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 401 ); 402 } 404 private void supportTokenComboActionPerformed(java.awt.event.ActionEvent evt) { setValue(supportTokenCombo); 406 } 408 private void encryptOrderChBoxActionPerformed(java.awt.event.ActionEvent evt) { setValue(encryptOrderChBox); 410 } 412 private void reqDerivedKeysActionPerformed(java.awt.event.ActionEvent evt) { setValue(reqDerivedKeys); 414 } 416 private void reqSigConfChBoxActionPerformed(java.awt.event.ActionEvent evt) { setValue(reqSigConfChBox); 418 } 420 private void derivedKeysChBoxActionPerformed(java.awt.event.ActionEvent evt) { setValue(derivedKeysChBox); 422 } 424 private void secConvChBoxActionPerformed(java.awt.event.ActionEvent evt) { setValue(secConvChBox); 426 } 428 private void encryptSignatureChBox(java.awt.event.ActionEvent evt) { setValue(encryptSignatureChBox); 430 } 432 private void layoutComboActionPerformed(java.awt.event.ActionEvent evt) { setValue(layoutCombo); 434 } 436 private void algoSuiteComboActionPerformed(java.awt.event.ActionEvent evt) { setValue(algoSuiteCombo); 438 } 440 private javax.swing.JComboBox algoSuiteCombo; 442 private javax.swing.JLabel algoSuiteLabel; 443 private javax.swing.JCheckBox derivedKeysChBox; 444 private javax.swing.JCheckBox encryptOrderChBox; 445 private javax.swing.JCheckBox encryptSignatureChBox; 446 private javax.swing.JComboBox layoutCombo; 447 private javax.swing.JLabel layoutLabel; 448 private javax.swing.JCheckBox reqDerivedKeys; 449 private javax.swing.JCheckBox reqSigConfChBox; 450 private javax.swing.JCheckBox secConvChBox; 451 private javax.swing.JComboBox supportTokenCombo; 452 private javax.swing.JLabel supportTokenLabel; 453 455 } 456 | Popular Tags |