1 19 20 package org.netbeans.modules.websvc.wsitconf.ui.client; 21 22 import java.io.IOException ; 23 import java.util.Enumeration ; 24 import org.netbeans.api.project.FileOwnerQuery; 25 import org.netbeans.api.project.Project; 26 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 27 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 28 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 29 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport; 30 import org.netbeans.modules.websvc.wsitconf.ui.StoreFileFilter; 31 import org.netbeans.modules.websvc.wsitconf.util.Util; 32 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.KeyStore; 33 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProprietarySecurityPolicyModelHelper; 34 import org.netbeans.modules.xml.multiview.ui.SectionInnerPanel; 35 import org.netbeans.modules.xml.multiview.ui.SectionView; 36 import org.netbeans.modules.xml.multiview.ui.SectionVisualTheme; 37 import org.netbeans.modules.xml.wsdl.model.Binding; 38 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 39 import org.openide.filesystems.FileObject; 40 import org.openide.filesystems.FileUtil; 41 import org.openide.nodes.Node; 42 import org.openide.util.NbBundle; 43 import javax.swing.*; 44 import java.io.File ; 45 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel; 46 import org.netbeans.modules.websvc.wsitconf.spi.SecurityCheckerRegistry; 47 import org.openide.DialogDisplayer; 48 import org.openide.NotifyDescriptor; 49 50 54 public class KeystorePanel extends SectionInnerPanel { 55 56 private static final String PKCS12 = "PKCS12"; private static final String JKS = "JKS"; 59 private static final String DEFAULT_PASSWORD="changeit"; 61 private WSDLModel model; 62 private Node node; 63 private Binding binding; 64 65 private String keystoreType = JKS; 66 private String truststoreType = JKS; 67 68 private boolean inSync = false; 69 70 private Project project; 71 72 private JaxWsModel jaxwsmodel; 73 74 public KeystorePanel(SectionView view, WSDLModel model, Node node, Binding binding, JaxWsModel jaxwsmodel) { 75 super(view); 76 this.model = model; 77 this.node = node; 78 this.binding = binding; 79 this.jaxwsmodel = jaxwsmodel; 80 81 FileObject fo = (FileObject) node.getLookup().lookup(FileObject.class); 82 if (fo != null) project = FileOwnerQuery.getOwner(fo); 83 84 initComponents(); 85 86 keyAliasCombo.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 87 keyAliasLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 88 keyPasswordLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 89 keyPasswordField.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 90 keystoreLocationLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 91 keystoreLocationTextField.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 92 keystorePasswordLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 93 keystorePasswordField.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 94 trustAliasCombo.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 95 trustAliasLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 96 trustPasswordField.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 97 truststoreLocationLbl.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 98 truststoreLocationTextField.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 99 truststorePasswordLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 100 101 addModifier(keystoreLocationTextField); 102 addModifier(keyAliasCombo); 103 addModifier(keystorePasswordField); 104 addModifier(keyPasswordField); 105 addModifier(truststoreLocationTextField); 106 addModifier(trustPasswordField); 107 addModifier(trustAliasCombo); 108 109 sync(); 110 } 111 112 private String getKeystoreAlias() { 113 return (String ) this.keyAliasCombo.getSelectedItem(); 114 } 115 116 private void setKeystoreAlias(String alias) { 117 this.keyAliasCombo.setSelectedItem(alias); 118 } 119 120 private String getTruststoreAlias() { 121 return (String ) this.trustAliasCombo.getSelectedItem(); 122 } 123 124 private void setTruststoreAlias(String alias) { 125 this.trustAliasCombo.setSelectedItem(alias); 126 } 127 128 private char[] getCharPassword(boolean trust) { 129 return trust ? trustPasswordField.getPassword() : keystorePasswordField.getPassword(); 130 } 131 132 private String getKeyPassword() { 133 return String.valueOf(this.keyPasswordField.getPassword()); 134 } 135 136 private String getKeystorePassword() { 137 return String.valueOf(this.keystorePasswordField.getPassword()); 138 } 139 140 private void setKeyPassword(String password) { 141 this.keyPasswordField.setText(password); 142 } 143 144 private void setKeystorePassword(String password) { 145 this.keystorePasswordField.setText(password); 146 } 147 148 private String getTruststorePassword() { 149 return String.valueOf(this.trustPasswordField.getPassword()); 150 } 151 152 private void setTruststorePassword(String password) { 153 this.trustPasswordField.setText(password); 154 } 155 156 private void setKeystorePath(String path) { 157 this.keystoreLocationTextField.setText(path); 158 } 159 160 private String getKeystorePath() { 161 String path = this.keystoreLocationTextField.getText(); 162 if ("".equals(path) || (path == null)) { return null; 164 } 165 return path; 166 } 167 168 private void setTruststorePath(String path) { 169 this.truststoreLocationTextField.setText(path); 170 } 171 172 private String getTruststorePath() { 173 String path = this.truststoreLocationTextField.getText(); 174 if ("".equals(path) || (path == null)) { return null; 176 } 177 return path; 178 } 179 180 public void sync() { 181 inSync = true; 182 183 J2eePlatform p = null; 184 JAXWSSupport ws = null; 185 FileObject fo = null; 186 if ((ws != null) && (fo != null)) { 187 Project project = FileOwnerQuery.getOwner(fo); 188 if (project != null) { 189 J2eeModuleProvider mp = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class); 190 if (mp != null) { 191 String instance = mp.getServerInstanceID(); 192 p = Deployment.getDefault().getJ2eePlatform(instance); 193 } 194 } 195 } 196 197 String keystoreLocation = ProprietarySecurityPolicyModelHelper.getStoreLocation(binding, false); 198 if (keystoreLocation != null) { 199 setKeystorePath(keystoreLocation); 200 } else { 201 setKeystorePath(getServerStoreLocation(false)); 202 } 203 204 String truststoreLocation = ProprietarySecurityPolicyModelHelper.getStoreLocation(binding, true); 205 if (truststoreLocation != null) { 206 setTruststorePath(truststoreLocation); 207 } else { 208 setTruststorePath(getServerStoreLocation(true)); 209 } 210 211 String keyStorePassword = ProprietarySecurityPolicyModelHelper.getStorePassword(binding, false); 212 if (keyStorePassword != null) { 213 setKeystorePassword(keyStorePassword); 214 reloadAliases(false); 215 } else { 216 setKeystorePassword(DEFAULT_PASSWORD); 217 } 218 219 String trustStorePassword = ProprietarySecurityPolicyModelHelper.getStorePassword(binding,true); 220 if (trustStorePassword != null) { 221 setTruststorePassword(trustStorePassword); 222 reloadAliases(true); 223 } else { 224 setTruststorePassword(DEFAULT_PASSWORD); 225 } 226 227 String keyPassword = ProprietarySecurityPolicyModelHelper.getKeyPassword(binding); 228 if (keyPassword != null) { 229 setKeyPassword(keyPassword); 230 } 231 232 String keyStoreAlias = ProprietarySecurityPolicyModelHelper.getStoreAlias(binding, false); 233 setKeystoreAlias(keyStoreAlias); 234 235 String truststoreAlias = ProprietarySecurityPolicyModelHelper.getStoreAlias(binding,true); 236 setTruststoreAlias(truststoreAlias); 237 238 enableDisable(); 239 240 inSync = false; 241 } 242 243 private String getServerStoreLocation(boolean trust) { 244 String storeLocation = null; 245 J2eeModuleProvider mp = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class); 246 if (mp != null) { 247 String sID = mp.getServerInstanceID(); 248 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(sID); 249 File [] keyLocs = null; 250 keyLocs = trust ? j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_TRUSTSTORE_CLIENT) : 251 j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_KEYSTORE_CLIENT); 252 if ((keyLocs != null) && (keyLocs.length > 0)) { 253 storeLocation = keyLocs[0].getAbsolutePath(); 254 } 255 } 256 return storeLocation; 257 } 258 259 @Override 260 public void setValue(javax.swing.JComponent source, Object value) { 261 262 if (inSync) return; 263 264 if (source.equals(keystoreLocationTextField) || 265 source.equals(keyAliasCombo) || 266 source.equals(keystorePasswordField) || 267 source.equals(keyPasswordField)) { 268 269 String alias = getKeystoreAlias(); 270 if ((alias == null) || (alias.length() == 0)) { 271 ProprietarySecurityPolicyModelHelper.setKeyStoreAlias(binding, null, true); 272 } else { 273 ProprietarySecurityPolicyModelHelper.setKeyStoreAlias(binding, alias, true); 274 } 275 276 String passwd = getKeystorePassword(); 277 if ((passwd == null) || (passwd.length() == 0)) { 278 ProprietarySecurityPolicyModelHelper.setStorePassword(binding, null, false, true); 279 } else { 280 ProprietarySecurityPolicyModelHelper.setStorePassword(binding, passwd, false, true); 281 } 282 283 String kpasswd = getKeyPassword(); 284 if ((kpasswd == null) || (kpasswd.length() == 0)) { 285 ProprietarySecurityPolicyModelHelper.setKeyPassword(binding, null, true); 286 } else { 287 ProprietarySecurityPolicyModelHelper.setKeyPassword(binding, kpasswd, true); 288 } 289 290 String loc = getKeystorePath(); 291 if ((loc == null) || (loc.length() == 0)) { 292 ProprietarySecurityPolicyModelHelper.setStoreType(binding, null, false, true); 293 ProprietarySecurityPolicyModelHelper.setStoreLocation(binding, null, false, true); 294 } else { 295 ProprietarySecurityPolicyModelHelper.setStoreType(binding, KeyStore.KEYSTORE_TYPE, false, true); 296 ProprietarySecurityPolicyModelHelper.setStoreLocation(binding, loc, false, true); 297 } 298 299 return; 300 } 301 302 if (source.equals(truststoreLocationTextField) || source.equals(trustAliasCombo) || 303 source.equals(trustPasswordField) ) { 304 305 String alias = getTruststoreAlias(); 306 if ((alias == null) || (alias.length() == 0)) { 307 ProprietarySecurityPolicyModelHelper.setTrustPeerAlias(binding, null, true); 308 } else { 309 ProprietarySecurityPolicyModelHelper.setTrustPeerAlias(binding, alias, true); 310 } 311 312 String passwd = getTruststorePassword(); 313 if ((passwd == null) || (passwd.length() == 0)) { 314 ProprietarySecurityPolicyModelHelper.setStorePassword(binding, null, true, true); 315 } else { 316 ProprietarySecurityPolicyModelHelper.setStorePassword(binding, passwd, true, true); 317 } 318 319 String loc = getTruststorePath(); 320 if ((loc == null) || (loc.length() == 0)) { 321 ProprietarySecurityPolicyModelHelper.setStoreType(binding, null, true, true); 322 ProprietarySecurityPolicyModelHelper.setStoreLocation(binding, null, true, true); 323 } else { 324 ProprietarySecurityPolicyModelHelper.setStoreType(binding, KeyStore.KEYSTORE_TYPE, true, true); 325 ProprietarySecurityPolicyModelHelper.setStoreLocation(binding, loc, true, true); 326 } 327 328 return; 329 } 330 331 enableDisable(); 332 } 333 334 private void enableDisable() { 335 336 boolean amSec = SecurityCheckerRegistry.getDefault().isNonWsitSecurityEnabled(node, jaxwsmodel); 337 338 keyAliasLabel.setEnabled(!amSec); 339 keyPasswordField.setEnabled(!amSec); 340 keyPasswordLabel.setEnabled(!amSec); 341 keystoreLocationButton.setEnabled(!amSec); 342 keystoreLocationLabel.setEnabled(!amSec); 343 keystoreLocationTextField.setEnabled(!amSec); 344 keystorePasswordField.setEnabled(!amSec); 345 keystorePasswordLabel.setEnabled(!amSec); 346 loadKeyAliases.setEnabled(!amSec); 347 loadTrustAliases.setEnabled(!amSec); 348 trustAliasCombo.setEnabled(!amSec); 349 trustAliasLabel.setEnabled(!amSec); 350 trustPasswordField.setEnabled(!amSec); 351 truststoreLocationButton.setEnabled(!amSec); 352 truststoreLocationLbl.setEnabled(!amSec); 353 truststoreLocationTextField.setEnabled(!amSec); 354 truststorePasswordLabel.setEnabled(!amSec); 355 } 356 357 @Override 358 public void documentChanged(javax.swing.text.JTextComponent comp, String value) { 359 enableDisable(); 360 } 361 362 @Override 363 public void rollbackValue(javax.swing.text.JTextComponent source) { 364 } 365 366 @Override 367 protected void endUIChange() { 368 } 369 370 public void linkButtonPressed(Object ddBean, String ddProperty) { 371 } 372 373 public javax.swing.JComponent getErrorComponent(String errorId) { 374 return null; 375 } 376 377 382 private void initComponents() { 384 385 keystoreLocationLabel = new javax.swing.JLabel (); 386 truststorePasswordLabel = new javax.swing.JLabel (); 387 truststoreLocationLbl = new javax.swing.JLabel (); 388 keystorePasswordLabel = new javax.swing.JLabel (); 389 keystoreLocationTextField = new javax.swing.JTextField (); 390 keystoreLocationButton = new javax.swing.JButton (); 391 truststoreLocationTextField = new javax.swing.JTextField (); 392 truststoreLocationButton = new javax.swing.JButton (); 393 keyAliasLabel = new javax.swing.JLabel (); 394 keyPasswordLabel = new javax.swing.JLabel (); 395 keyAliasCombo = new javax.swing.JComboBox (); 396 trustAliasLabel = new javax.swing.JLabel (); 397 trustAliasCombo = new javax.swing.JComboBox (); 398 keystorePasswordField = new javax.swing.JPasswordField (); 399 keyPasswordField = new javax.swing.JPasswordField (); 400 trustPasswordField = new javax.swing.JPasswordField (); 401 loadKeyAliases = new javax.swing.JButton (); 402 loadTrustAliases = new javax.swing.JButton (); 403 404 addFocusListener(new java.awt.event.FocusAdapter () { 405 public void focusGained(java.awt.event.FocusEvent evt) { 406 formFocusGained(evt); 407 } 408 }); 409 addAncestorListener(new javax.swing.event.AncestorListener () { 410 public void ancestorMoved(javax.swing.event.AncestorEvent evt) { 411 } 412 public void ancestorAdded(javax.swing.event.AncestorEvent evt) { 413 formAncestorAdded(evt); 414 } 415 public void ancestorRemoved(javax.swing.event.AncestorEvent evt) { 416 } 417 }); 418 419 keystoreLocationLabel.setLabelFor(keystoreLocationTextField); 420 org.openide.awt.Mnemonics.setLocalizedText(keystoreLocationLabel, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_KeyStoreLocationLabel")); 422 truststorePasswordLabel.setLabelFor(trustPasswordField); 423 org.openide.awt.Mnemonics.setLocalizedText(truststorePasswordLabel, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_TrustPasswordLabel")); 425 truststoreLocationLbl.setLabelFor(truststoreLocationTextField); 426 org.openide.awt.Mnemonics.setLocalizedText(truststoreLocationLbl, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_TrustStoreLocationLabel")); 428 keystorePasswordLabel.setLabelFor(keystorePasswordField); 429 org.openide.awt.Mnemonics.setLocalizedText(keystorePasswordLabel, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_KeystorePasswordLabel")); 431 org.openide.awt.Mnemonics.setLocalizedText(keystoreLocationButton, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_KBrowseButton")); keystoreLocationButton.addActionListener(new java.awt.event.ActionListener () { 433 public void actionPerformed(java.awt.event.ActionEvent evt) { 434 keystoreLocationButtonActionPerformed(evt); 435 } 436 }); 437 438 org.openide.awt.Mnemonics.setLocalizedText(truststoreLocationButton, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_TBrowseButton")); truststoreLocationButton.addActionListener(new java.awt.event.ActionListener () { 440 public void actionPerformed(java.awt.event.ActionEvent evt) { 441 truststoreLocationButtonActionPerformed(evt); 442 } 443 }); 444 445 keyAliasLabel.setLabelFor(keyAliasCombo); 446 org.openide.awt.Mnemonics.setLocalizedText(keyAliasLabel, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_KeyAliasLabel")); 448 keyPasswordLabel.setLabelFor(keyPasswordField); 449 org.openide.awt.Mnemonics.setLocalizedText(keyPasswordLabel, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_KeyPasswordLabel")); 451 keyAliasCombo.setEditable(true); 452 keyAliasCombo.addActionListener(new java.awt.event.ActionListener () { 453 public void actionPerformed(java.awt.event.ActionEvent evt) { 454 keyAliasComboActionPerformed(evt); 455 } 456 }); 457 keyAliasCombo.addKeyListener(new java.awt.event.KeyAdapter () { 458 public void keyReleased(java.awt.event.KeyEvent evt) { 459 keyAliasComboKeyReleased(evt); 460 } 461 }); 462 463 trustAliasLabel.setLabelFor(trustAliasCombo); 464 org.openide.awt.Mnemonics.setLocalizedText(trustAliasLabel, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_TrustAliasLabel")); 466 trustAliasCombo.setEditable(true); 467 trustAliasCombo.addActionListener(new java.awt.event.ActionListener () { 468 public void actionPerformed(java.awt.event.ActionEvent evt) { 469 trustAliasComboActionPerformed(evt); 470 } 471 }); 472 trustAliasCombo.addKeyListener(new java.awt.event.KeyAdapter () { 473 public void keyReleased(java.awt.event.KeyEvent evt) { 474 trustAliasComboKeyReleased(evt); 475 } 476 }); 477 478 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/wsitconf/ui/client/Bundle"); org.openide.awt.Mnemonics.setLocalizedText(loadKeyAliases, bundle.getString("LBL_KLoadKeys")); loadKeyAliases.addActionListener(new java.awt.event.ActionListener () { 481 public void actionPerformed(java.awt.event.ActionEvent evt) { 482 loadKeyAliasesActionPerformed(evt); 483 } 484 }); 485 486 org.openide.awt.Mnemonics.setLocalizedText(loadTrustAliases, bundle.getString("LBL_TLoadKeys")); loadTrustAliases.addActionListener(new java.awt.event.ActionListener () { 488 public void actionPerformed(java.awt.event.ActionEvent evt) { 489 loadTrustAliasesActionPerformed(evt); 490 } 491 }); 492 493 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 494 this.setLayout(layout); 495 layout.setHorizontalGroup( 496 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 497 .add(layout.createSequentialGroup() 498 .addContainerGap() 499 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 500 .add(layout.createSequentialGroup() 501 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 502 .add(truststorePasswordLabel) 503 .add(truststoreLocationLbl) 504 .add(trustAliasLabel)) 505 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 506 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 507 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 508 .add(truststoreLocationTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE) 509 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 510 .add(truststoreLocationButton)) 511 .add(layout.createSequentialGroup() 512 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) 513 .add(org.jdesktop.layout.GroupLayout.LEADING, trustAliasCombo, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 514 .add(org.jdesktop.layout.GroupLayout.LEADING, trustPasswordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)) 515 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 516 .add(loadTrustAliases) 517 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 74, Short.MAX_VALUE)))) 518 .add(layout.createSequentialGroup() 519 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 520 .add(keystoreLocationLabel) 521 .add(keystorePasswordLabel) 522 .add(keyAliasLabel) 523 .add(keyPasswordLabel)) 524 .add(22, 22, 22) 525 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 526 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 527 .add(keystoreLocationTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE) 528 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 529 .add(keystoreLocationButton)) 530 .add(layout.createSequentialGroup() 531 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 532 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) 533 .add(org.jdesktop.layout.GroupLayout.LEADING, keyPasswordField) 534 .add(org.jdesktop.layout.GroupLayout.LEADING, keyAliasCombo, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 535 .add(org.jdesktop.layout.GroupLayout.LEADING, keystorePasswordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)) 536 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 537 .add(loadKeyAliases) 538 .add(71, 71, 71))))) 539 .addContainerGap()) 540 ); 541 542 layout.linkSize(new java.awt.Component [] {keystoreLocationButton, truststoreLocationButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL); 543 544 layout.setVerticalGroup( 545 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 546 .add(layout.createSequentialGroup() 547 .addContainerGap() 548 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 549 .add(keystoreLocationLabel) 550 .add(keystoreLocationButton) 551 .add(keystoreLocationTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 552 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 553 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 554 .add(keystorePasswordLabel) 555 .add(keystorePasswordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 556 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 557 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 558 .add(keyAliasLabel) 559 .add(keyAliasCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 560 .add(loadKeyAliases)) 561 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 562 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 563 .add(keyPasswordLabel) 564 .add(keyPasswordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 565 .add(49, 49, 49) 566 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 567 .add(truststoreLocationLbl) 568 .add(truststoreLocationButton) 569 .add(truststoreLocationTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 570 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 571 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 572 .add(truststorePasswordLabel) 573 .add(trustPasswordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 574 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 575 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 576 .add(trustAliasLabel) 577 .add(trustAliasCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 578 .add(loadTrustAliases)) 579 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 580 ); 581 } 583 private void formAncestorAdded(javax.swing.event.AncestorEvent evt) { enableDisable(); 585 } 587 private void formFocusGained(java.awt.event.FocusEvent evt) { enableDisable(); 589 } 591 private void trustAliasComboKeyReleased(java.awt.event.KeyEvent evt) { setValue(trustAliasCombo, null); 593 } 595 private void trustAliasComboActionPerformed(java.awt.event.ActionEvent evt) { setValue(trustAliasCombo, null); 597 } 599 private void keyAliasComboKeyReleased(java.awt.event.KeyEvent evt) { setValue(keyAliasCombo, null); 601 } 603 private void keyAliasComboActionPerformed(java.awt.event.ActionEvent evt) { setValue(keyAliasCombo, null); 605 } 607 private void loadTrustAliasesActionPerformed(java.awt.event.ActionEvent evt) { boolean success = reloadAliases(true); 609 if (!success) { 610 DialogDisplayer.getDefault().notify( 611 new NotifyDescriptor.Message(NbBundle.getMessage(KeystorePanel.class, "MSG_WrongPassword" ))); 613 } 614 } 616 private void loadKeyAliasesActionPerformed(java.awt.event.ActionEvent evt) { boolean success = reloadAliases(false); 618 if (!success) { 619 DialogDisplayer.getDefault().notify( 620 new NotifyDescriptor.Message(NbBundle.getMessage(KeystorePanel.class, "MSG_WrongPassword" ))); 622 } 623 } 625 private void truststoreLocationButtonActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser(); 627 FileUtil.preventFileChooserSymlinkTraversal(chooser, null); 628 chooser.setDialogTitle(NbBundle.getMessage(KeystorePanel.class, "LBL_TruststoreBrowse_Title")); 629 chooser.setFileSelectionMode (JFileChooser.FILES_ONLY); 630 chooser.setMultiSelectionEnabled(false); 631 chooser.setFileFilter(new StoreFileFilter()); 632 File f = new File (truststoreLocationTextField.getText()); 633 File dir = null; 634 if ((f != null) && (f.exists())) { 635 if (f.isDirectory()) { 636 chooser.setCurrentDirectory(f); 637 } else { 638 chooser.setCurrentDirectory(f.getParentFile()); 639 } 640 } 641 if (chooser.showOpenDialog(this)== JFileChooser.APPROVE_OPTION) { 642 File file = chooser.getSelectedFile(); 643 if (file != null) { 644 setTruststorePath(file.getPath()); 645 String extension = FileUtil.getExtension(file.getName()); 646 keystoreType = StoreFileFilter.JKS_EXT.equals(extension) ? JKS : PKCS12; 647 setValue(truststoreLocationTextField, null); 648 } 649 } 650 } 652 private void keystoreLocationButtonActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser(); 654 FileUtil.preventFileChooserSymlinkTraversal(chooser, null); 655 chooser.setDialogTitle(NbBundle.getMessage(KeystorePanel.class, "LBL_KeystoreBrowse_Title")); 656 chooser.setFileSelectionMode (JFileChooser.FILES_ONLY); 657 chooser.setMultiSelectionEnabled(false); 658 chooser.setFileFilter(new StoreFileFilter()); 659 File f = new File (truststoreLocationTextField.getText()); 660 File dir = null; 661 if ((f != null) && (f.exists())) { 662 if (f.isDirectory()) { 663 chooser.setCurrentDirectory(f); 664 } else { 665 chooser.setCurrentDirectory(f.getParentFile()); 666 } 667 } 668 if (chooser.showOpenDialog(this)== JFileChooser.APPROVE_OPTION) { 669 File file = chooser.getSelectedFile(); 670 if (file != null) { 671 setKeystorePath(file.getPath()); 672 String extension = FileUtil.getExtension(file.getName()); 673 truststoreType = StoreFileFilter.JKS_EXT.equals(extension) ? JKS : PKCS12; 674 setValue(keystoreLocationTextField, null); 675 } 676 } 677 } 679 private boolean reloadAliases(boolean trust) { 680 JComboBox combo = trust ? trustAliasCombo : keyAliasCombo; 681 String path = trust ? getTruststorePath() : getKeystorePath(); 682 String type = trust ? truststoreType : keystoreType; 683 Enumeration <String > aliases; 684 try { 685 aliases = Util.getAliases(path, getCharPassword(trust), truststoreType); 686 } catch (IOException ex) { 687 ex.printStackTrace(); 688 return false; 689 } 690 combo.removeAllItems(); 691 if (aliases != null) { 692 combo.addItem(""); while (aliases.hasMoreElements()){ 694 String alias = aliases.nextElement(); 695 combo.addItem(alias); 696 } 697 if (combo.getItemCount() > 1) { 698 combo.setSelectedIndex(1); 699 } 700 } 701 return true; 702 } 703 704 private javax.swing.JComboBox keyAliasCombo; 706 private javax.swing.JLabel keyAliasLabel; 707 private javax.swing.JPasswordField keyPasswordField; 708 private javax.swing.JLabel keyPasswordLabel; 709 private javax.swing.JButton keystoreLocationButton; 710 private javax.swing.JLabel keystoreLocationLabel; 711 private javax.swing.JTextField keystoreLocationTextField; 712 private javax.swing.JPasswordField keystorePasswordField; 713 private javax.swing.JLabel keystorePasswordLabel; 714 private javax.swing.JButton loadKeyAliases; 715 private javax.swing.JButton loadTrustAliases; 716 private javax.swing.JComboBox trustAliasCombo; 717 private javax.swing.JLabel trustAliasLabel; 718 private javax.swing.JPasswordField trustPasswordField; 719 private javax.swing.JButton truststoreLocationButton; 720 private javax.swing.JLabel truststoreLocationLbl; 721 private javax.swing.JTextField truststoreLocationTextField; 722 private javax.swing.JLabel truststorePasswordLabel; 723 725 } 726 | Popular Tags |