1 23 24 29 30 package com.sun.enterprise.tools.upgrade.gui; 31 32 36 import java.util.*; 37 import com.sun.enterprise.tools.upgrade.common.*; 38 import com.sun.enterprise.tools.upgrade.gui.util.*; 39 import java.util.logging.*; 40 import java.io.File ; 41 42 import com.sun.enterprise.util.i18n.StringManager; 43 import com.sun.enterprise.tools.upgrade.logging.*; 44 45 public class CertificatePanel extends javax.swing.JPanel { 46 47 private javax.swing.JButton addDomainButton; 49 private javax.swing.JButton deleteDomainButton; 50 private javax.swing.JTable domainTable; 51 private DomainsTableModel domainsTableModel; 52 private javax.swing.JScrollPane domainTableScrollPane; 53 54 private CommonInfoModel commonInfoModel; 55 private javax.swing.JFrame parent = null; 56 private List domainNamesInTable = null; 57 private AddDomainDialog addDomainDialog = null; 58 59 private StringManager stringManager = StringManager.getManager("com.sun.enterprise.tools.upgrade.gui"); 60 private Logger logger = com.sun.enterprise.tools.upgrade.common.CommonInfoModel.getDefaultLogger(); 61 62 63 64 public CertificatePanel(CommonInfoModel model, javax.swing.JFrame parent) { 65 this.commonInfoModel = model; 66 this.parent = parent; 67 this.domainNamesInTable = new ArrayList(); 68 initComponents(); 69 } 70 71 76 private void initComponents() { 77 java.awt.GridBagConstraints gridBagConstraints; 78 79 javax.swing.JPanel tablePanel = new javax.swing.JPanel (); 80 domainTableScrollPane = new javax.swing.JScrollPane (); 81 domainTable = new javax.swing.JTable (); 82 addDomainButton = new javax.swing.JButton (); 83 addDomainButton.addActionListener(new java.awt.event.ActionListener (){ 84 public void actionPerformed(java.awt.event.ActionEvent ae){ 85 performAddDomainAction(); 86 } 87 }); 88 deleteDomainButton = new javax.swing.JButton (); 89 deleteDomainButton.addActionListener(new java.awt.event.ActionListener (){ 90 public void actionPerformed(java.awt.event.ActionEvent ae){ 91 performDeleteDomainAction(); 92 } 93 }); 94 javax.swing.JPanel dummyPanel1 = new javax.swing.JPanel (); 95 javax.swing.JPanel dummyPanel2 = new javax.swing.JPanel (); 96 97 javax.swing.JPanel dummyContentPanel = new javax.swing.JPanel (); 98 99 this.setLayout(new java.awt.BorderLayout ()); 100 HeaderPanel headerPanel = new HeaderPanel(stringManager.getString("upgrade.gui.certpanel.headerPanel")); 101 headerPanel.setInsets(new java.awt.Insets (12, 10, 5, 10)); 102 this.add(headerPanel, "North"); 103 104 dummyContentPanel.setLayout(new java.awt.GridBagLayout ()); 105 FlowLabel flowContentLabel = new FlowLabel(); 106 flowContentLabel.setText(stringManager.getString("upgrade.gui.certpanel.flowContentLabel")); 107 gridBagConstraints = new java.awt.GridBagConstraints (); 108 gridBagConstraints.gridx = 0; 109 gridBagConstraints.gridy = 0; 110 gridBagConstraints.gridheight = 1; 111 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 112 gridBagConstraints.insets = new java.awt.Insets (0, 10, 10, 10); 113 gridBagConstraints.weightx = 1.0; 114 gridBagConstraints.weighty = 0.0; 115 dummyContentPanel.add(flowContentLabel, gridBagConstraints); 116 117 tablePanel.setLayout(new java.awt.GridBagLayout ()); 118 119 tablePanel.setBorder(new javax.swing.border.TitledBorder (stringManager.getString("upgrade.gui.certpanel.certPanelTitle"))); 120 domainsTableModel = new DomainsTableModel(domainNamesInTable); 121 domainTable.setModel(domainsTableModel); 122 123 domainTableScrollPane.setViewportView(domainTable); 124 125 gridBagConstraints = new java.awt.GridBagConstraints (); 126 gridBagConstraints.gridx = 0; 127 gridBagConstraints.gridy = 0; 128 gridBagConstraints.gridheight = 4; 129 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 130 gridBagConstraints.insets = new java.awt.Insets (5, 5, 5, 5); 131 gridBagConstraints.weightx = 1.0; 132 gridBagConstraints.weighty = 1.0; 133 tablePanel.add(domainTableScrollPane, gridBagConstraints); 134 135 addDomainButton.setText(stringManager.getString("upgrade.gui.certpanel.addDomainButtonText")); 136 gridBagConstraints = new java.awt.GridBagConstraints (); 137 gridBagConstraints.gridx = 1; 138 gridBagConstraints.gridy = 1; 139 gridBagConstraints.insets = new java.awt.Insets (10, 15, 10, 10); 140 tablePanel.add(addDomainButton, gridBagConstraints); 141 142 deleteDomainButton.setText(stringManager.getString("upgrade.gui.certpanel.deleteDomainButtonText")); 143 gridBagConstraints = new java.awt.GridBagConstraints (); 144 gridBagConstraints.gridx = 1; 145 gridBagConstraints.gridy = 2; 146 gridBagConstraints.insets = new java.awt.Insets (10, 15, 10, 10); 147 tablePanel.add(deleteDomainButton, gridBagConstraints); 148 149 gridBagConstraints = new java.awt.GridBagConstraints (); 150 gridBagConstraints.gridx = 1; 151 gridBagConstraints.gridy = 0; 152 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; 153 gridBagConstraints.weighty = 0.5; 154 tablePanel.add(dummyPanel1, gridBagConstraints); 155 156 gridBagConstraints = new java.awt.GridBagConstraints (); 157 gridBagConstraints.gridx = 1; 158 gridBagConstraints.gridy = 3; 159 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; 160 gridBagConstraints.weighty = 0.5; 161 tablePanel.add(dummyPanel2, gridBagConstraints); 162 163 gridBagConstraints = new java.awt.GridBagConstraints (); 164 gridBagConstraints.gridx = 0; 165 gridBagConstraints.gridy = 1; 166 gridBagConstraints.gridheight = 1; 167 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 168 gridBagConstraints.insets = new java.awt.Insets (10, 10, 10, 10); 169 gridBagConstraints.weightx = 1.0; 170 gridBagConstraints.weighty = 1.0; 171 dummyContentPanel.add(tablePanel, gridBagConstraints); 172 173 add(dummyContentPanel, java.awt.BorderLayout.CENTER); 174 175 } 176 void performAddDomainAction(){ 177 getAddDomainDialog().clearFields(); 178 getAddDomainDialog().setVisible(true); 179 } 180 void performDeleteDomainAction(){ 181 int selRow = this.domainTable.getSelectedRow(); 182 if(selRow != -1){ 183 int option = javax.swing.JOptionPane.showConfirmDialog(this, stringManager.getString("upgrade.gui.certpanel.deleteConfirmMsg"), 184 stringManager.getString("upgrade.gui.certpanel.deleteConfirmTitle"), 185 javax.swing.JOptionPane.YES_NO_OPTION, 186 javax.swing.JOptionPane.QUESTION_MESSAGE); 187 if (option == javax.swing.JOptionPane.NO_OPTION) { 188 return; 189 } 190 commonInfoModel.setCertDbPassword((String )domainNamesInTable.get(selRow),""); 191 commonInfoModel.setJksKeystorePassword((String )domainNamesInTable.get(selRow),""); 192 domainsTableModel.removeDomain(selRow); 193 } 194 } 195 private AddDomainDialog getAddDomainDialog(){ 196 if(this.addDomainDialog == null){ 197 int sourceToTarget = 0; 198 if(this.commonInfoModel.isUpgradeNSStoJKS()){ 199 sourceToTarget = AddDomainDialog.NSStoJKS; 200 }else if(this.commonInfoModel.isUpgradeJKStoJKS()){ 201 sourceToTarget = AddDomainDialog.JKStoJKS; 202 }else if(this.commonInfoModel.isUpgradeJKStoNSS()){ 203 sourceToTarget = AddDomainDialog.JKStoNSS; 204 }else{ 205 sourceToTarget = AddDomainDialog.NSStoNSS; } 207 208 addDomainDialog = new AddDomainDialog(parent, true, commonInfoModel, sourceToTarget); 209 centerDialog(addDomainDialog); 210 addDomainDialog.addDialogListener(new DialogListener(){ 211 public void dialogProcessed(DialogEvent evt){ 212 processAddDomainDialogEvent(evt); 213 } 214 }); 215 } 216 return addDomainDialog; 217 } 218 public void reInitializeAddDomainDialog(){ 219 this.addDomainDialog = null; 220 } 221 public void centerDialog(javax.swing.JDialog dialog) { 222 java.awt.Rectangle bounds = parent.getBounds(); 223 224 java.awt.Rectangle dialogLocation = new java.awt.Rectangle (); 225 dialogLocation.x = bounds.x+((bounds.width-dialog.getWidth())/2); 226 dialogLocation.y = bounds.y+((bounds.height-dialog.getHeight())/2); 227 dialogLocation.setSize(dialog.getWidth(),dialog.getHeight()); 228 dialog.setBounds(dialogLocation); 229 230 } 231 private java.util.List processv70PESEto8xPE(String selectedDomainName, String selectedInstanceName, String pwd1, String pwd2, String pwd3){ 232 237 commonInfoModel.setCurrentDomain(selectedDomainName); 240 commonInfoModel.setCurrentSourceInstance(selectedInstanceName); 241 commonInfoModel.setCertDbPassword(pwd1); 242 boolean validpwd = PasswordVerifier.verifySourceNSSPassword(commonInfoModel); 243 if(!validpwd) { 244 commonInfoModel.recover(); 245 List errorList = new ArrayList(); 246 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidNSSPWDMsg")); 247 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidNSSPWDTitle")); 248 return errorList; 249 } 250 251 commonInfoModel.setJksKeystorePassword(pwd2); 252 String jksPath=commonInfoModel.getTargetJKSKeyStorePath(); 253 validpwd = PasswordVerifier.verifyKeystorePassword(jksPath,pwd2 ); 254 if(!validpwd) { 255 commonInfoModel.recover(); 256 List errorList = new ArrayList(); 257 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidJKSPWDMsg")); 258 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidJKSPWDTitle")); 259 return errorList; 260 } 261 262 commonInfoModel.setJksCAKeystorePassword(pwd3); 263 String trustJksPath=commonInfoModel.getTargetTrustedJKSKeyStorePath(); 264 validpwd = PasswordVerifier.verifyKeystorePassword(trustJksPath,pwd3 ); 265 if(!validpwd) { 266 commonInfoModel.recover(); 267 List errorList = new ArrayList(); 268 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidCAPWDMsg")); 269 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidCAPWDTitle")); 270 return errorList; 271 } 272 return null; 273 } 274 private java.util.List processv8xPEto8xSEEE(String selectedDomainName, String pwd1, String pwd2, String pwd3){ 275 commonInfoModel.setCurrentDomain(selectedDomainName); 277 commonInfoModel.setCertDbPassword(pwd3); 278 commonInfoModel.setTargetCertDbPassword(pwd3); 279 boolean validpwd = PasswordVerifier.verifyTargetNSSPassword(commonInfoModel,commonInfoModel.getTargetConfig()); 280 if(!validpwd) { 281 commonInfoModel.recover(); 282 List errorList = new ArrayList(); 283 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidTargetNSSPWDMsg")); 284 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidTargetNSSPWDTitle")); 285 return errorList; 286 } 287 commonInfoModel.setJksKeystorePassword(pwd1); 288 String jksPath=commonInfoModel.getSourceJKSKeyStorePath(); 289 validpwd = PasswordVerifier.verifyKeystorePassword(jksPath,pwd1 ); 290 if(!validpwd) { 291 commonInfoModel.recover(); 292 List errorList = new ArrayList(); 293 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidJKSPWDMsg")); 294 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidJKSPWDTitle")); 295 return errorList; 296 } 297 commonInfoModel.setJksCAKeystorePassword(pwd2); 298 String trustJksPath=commonInfoModel.getSourceTrustedJKSKeyStorePath(); 299 validpwd = PasswordVerifier.verifyKeystorePassword(trustJksPath,pwd2 ); 300 if(!validpwd) { 301 commonInfoModel.recover(); 302 List errorList = new ArrayList(); 303 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidCAPWDMsg")); 304 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidCAPWDTitle")); 305 return errorList; 306 } 307 return null; 308 } 309 private java.util.List processv80PEto81PE(String selectedDomainName, String pwd1, String pwd2){ 310 commonInfoModel.setCurrentDomain(selectedDomainName); 311 commonInfoModel.setJksKeystorePassword(pwd1); 312 String jksPath=commonInfoModel.getSourceJKSKeyStorePath(); 313 boolean validpwd = PasswordVerifier.verifyKeystorePassword(jksPath,pwd1 ); 314 if(!validpwd) { 315 commonInfoModel.recover(); 316 List errorList = new ArrayList(); 317 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidJKSPWDMsg")); 318 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidJKSPWDTitle")); 319 return errorList; 320 } 321 322 commonInfoModel.setJksCAKeystorePassword(pwd2); 323 String trustJksPath=commonInfoModel.getSourceTrustedJKSKeyStorePath(); 324 validpwd = PasswordVerifier.verifyKeystorePassword(trustJksPath,pwd2 ); 325 if(!validpwd) { 326 commonInfoModel.recover(); 327 List errorList = new ArrayList(); 328 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidCAPWDMsg")); 329 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidCAPWDTitle")); 330 return errorList; 331 } 332 return null; 333 } 334 private java.util.List processv7xEEto90EE(String selectedDomainName, String selectedInstanceName, String pwd1, String pwd2){ 335 commonInfoModel.setCurrentDomain(selectedDomainName); 336 commonInfoModel.setCurrentSourceInstance(selectedInstanceName); 337 commonInfoModel.setCertDbPassword(pwd1); 338 boolean validpwd = PasswordVerifier.verifySourceNSSPassword(commonInfoModel); 339 if(!validpwd) { 340 commonInfoModel.recover(); 341 List errorList = new ArrayList(); 342 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidNSSPWDMsg")); 343 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidNSSPWDTitle")); 344 return errorList; 345 } 346 commonInfoModel.setTargetCertDbPassword(pwd2); 347 validpwd = PasswordVerifier.verifyTargetNSSPassword(commonInfoModel,commonInfoModel.getTargetConfig()); 348 if(!validpwd) { 349 commonInfoModel.recover(); 350 List errorList = new ArrayList(); 351 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidTargetNSSPWDMsg")); 352 errorList.add(stringManager.getString("upgrade.gui.certpanel.invalidTargetNSSPWDTitle")); 353 return errorList; 354 } 355 return null; 356 } 357 358 private void processAddDomainDialogEvent(DialogEvent evt){ 359 if(evt.getAction() == DialogEvent.CANCEL_ACTION){ 360 addDomainDialog.setVisible(false); 361 addDomainDialog.dispose(); 362 }if(evt.getAction() == DialogEvent.HELP_ACTION){ 363 }else if(evt.getAction() == DialogEvent.FINISH_ACTION){ 365 java.util.Vector data = (java.util.Vector )evt.getObject(); 366 int sourceToTargetVersion = ((Integer )data.get(0)).intValue(); 367 if(data.get(1) == null || data.size() < 4){ 368 javax.swing.JOptionPane.showMessageDialog(this,stringManager.getString("upgrade.gui.certpanel.chooseDomainMsg"),stringManager.getString("upgrade.gui.certpanel.chooseDomainTitle"),javax.swing.JOptionPane.ERROR_MESSAGE); 370 return; 371 } 372 String domainTableEntry = (String )data.get(1); 373 if(commonInfoModel.getSourceVersion().equals(UpgradeConstants.VERSION_7X)) { 374 domainTableEntry = domainTableEntry + ":" + (String )data.get(2); 375 } 376 if(!this.domainNamesInTable.contains(domainTableEntry)) { 377 domainsTableModel.addDomain(domainTableEntry); 378 commonInfoModel.addDomainOptionName(domainTableEntry); 379 } 380 if(sourceToTargetVersion == AddDomainDialog.NSStoJKS && (data.size() > 5)){ 381 java.util.List errorMessageList = this.processv70PESEto8xPE((String )data.get(1), (String )data.get(2), (String )data.get(3),(String )data.get(4),(String )data.get(5)); 382 if(errorMessageList != null){ 383 javax.swing.JOptionPane.showMessageDialog(this, (String )errorMessageList.get(0),(String )errorMessageList.get(1),javax.swing.JOptionPane.ERROR_MESSAGE); 385 return; 386 } 387 }else if(sourceToTargetVersion == AddDomainDialog.JKStoNSS && (data.size() > 5)){ 388 java.util.List errorMessageList = this.processv8xPEto8xSEEE((String )data.get(1),(String )data.get(3),(String )data.get(4),(String )data.get(5)); 389 if(errorMessageList != null){ 390 javax.swing.JOptionPane.showMessageDialog(this, (String )errorMessageList.get(0),(String )errorMessageList.get(1),javax.swing.JOptionPane.ERROR_MESSAGE); 392 return; 393 } 394 }else if(sourceToTargetVersion == AddDomainDialog.JKStoJKS && (data.size() > 4)){ 395 java.util.List errorMessageList = this.processv80PEto81PE((String )data.get(1),(String )data.get(3),(String )data.get(4)); 396 if(errorMessageList != null){ 397 javax.swing.JOptionPane.showMessageDialog(this, (String )errorMessageList.get(0),(String )errorMessageList.get(1),javax.swing.JOptionPane.ERROR_MESSAGE); 399 return; 400 } 401 }else if(sourceToTargetVersion == AddDomainDialog.NSStoNSS && (data.size() > 4)){ 402 java.util.List errorMessageList = this.processv7xEEto90EE((String )data.get(1),(String )data.get(2),(String )data.get(3), (String )data.get(4)); 404 if(errorMessageList != null){ 405 javax.swing.JOptionPane.showMessageDialog(this, (String )errorMessageList.get(0),(String )errorMessageList.get(1),javax.swing.JOptionPane.ERROR_MESSAGE); 407 return; 408 } 409 } else { 410 javax.swing.JOptionPane.showMessageDialog(this,stringManager.getString("upgrade.gui.certpanel.chooseDomainMsg"),stringManager.getString("upgrade.gui.certpanel.chooseDomainTitle"),javax.swing.JOptionPane.ERROR_MESSAGE); 411 return; 412 } 413 addDomainDialog.setVisible(false); 414 addDomainDialog.dispose(); 415 } 416 } 417 class DomainsTableModel extends javax.swing.table.AbstractTableModel { 419 private List domains = null; 420 private String columnNames[] = {stringManager.getString("upgrade.gui.certpanel.tableColumnName")}; 421 424 public DomainsTableModel(List doms) { 425 super(); 426 this.domains = doms; 427 } 428 public int getColumnCount() { 429 return columnNames.length; 430 } 431 public java.lang.String getColumnName(int column) { 432 return columnNames[column]; 433 } 434 435 public int getRowCount() { 436 return domains.size(); 437 } 438 public boolean isCellEditable(int row, int col) { 439 return false; 440 } 441 public Class getColumnClass(int c) { 442 return java.lang.String .class; 443 } 444 447 public Object getValueAt(int row, int col) { 448 return (String ) domains.get(row); 449 } 450 public void removeDomain(int domainIndex){ 451 if(domains.size() > domainIndex){ 452 domains.remove(domainIndex); 453 fireTableDataChanged(); 454 } 455 } 456 public void addDomain(String domainName){ 457 if(domainName != null){ 458 domains.add(domainName); 459 fireTableDataChanged(); 460 } 461 } 462 } 463 } 464 | Popular Tags |