1 19 20 package org.netbeans.modules.websvc.wsitconf.ui.service.subpanels; 21 22 import org.netbeans.api.project.Project; 23 import org.netbeans.modules.websvc.wsitconf.WSITEditor; 24 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProprietarySecurityPolicyModelHelper; 25 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.Validator; 26 import org.netbeans.modules.xml.multiview.ui.SectionVisualTheme; 27 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 28 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 29 import org.openide.util.NbBundle; 30 31 import javax.swing.*; 32 import javax.swing.filechooser.FileFilter ; 33 import java.io.File ; 34 import java.util.Set ; 35 import org.netbeans.modules.websvc.wsitconf.ui.ClassDialog; 36 37 41 public class ValidatorsPanel extends JPanel { 42 43 private WSDLModel model; 44 private WSDLComponent comp; 45 46 private Project p; 47 48 private boolean inSync = false; 49 50 public ValidatorsPanel(WSDLComponent comp, Project p) { 51 super(); 52 this.model = comp.getModel(); 53 this.comp = comp; 54 this.p = p; 55 56 initComponents(); 57 58 usernameValidatorTextField.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 59 usernameValidatorLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 60 timestampValidatorTextField.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 61 timestampValidatorLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 62 certificateValidatorTextField.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 63 certificateValidatorLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 64 samlValidatorTextField.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 65 samlValidatorLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 66 67 sync(); 68 } 69 70 private String getValidator(String type) { 71 if (Validator.USERNAME_VALIDATOR.equals(type)) return usernameValidatorTextField.getText(); 72 if (Validator.TIMESTAMP_VALIDATOR.equals(type)) return timestampValidatorTextField.getText(); 73 if (Validator.CERTIFICATE_VALIDATOR.equals(type)) return certificateValidatorTextField.getText(); 74 if (Validator.SAML_VALIDATOR.equals(type)) return samlValidatorTextField.getText(); 75 return null; 76 } 77 78 private void setValidator(String type, String validator) { 79 if (Validator.USERNAME_VALIDATOR.equals(type)) this.usernameValidatorTextField.setText(validator); 80 if (Validator.TIMESTAMP_VALIDATOR.equals(type)) this.timestampValidatorTextField.setText(validator); 81 if (Validator.CERTIFICATE_VALIDATOR.equals(type)) this.certificateValidatorTextField.setText(validator); 82 if (Validator.SAML_VALIDATOR.equals(type)) this.samlValidatorTextField.setText(validator); 83 } 84 85 public void sync() { 86 inSync = true; 87 88 String usernameValidator = ProprietarySecurityPolicyModelHelper.getValidator(comp, Validator.USERNAME_VALIDATOR); 89 if (usernameValidator != null) { 90 setValidator(Validator.USERNAME_VALIDATOR, usernameValidator); 91 } 92 String timestampValidator = ProprietarySecurityPolicyModelHelper.getValidator(comp, Validator.TIMESTAMP_VALIDATOR); 93 if (timestampValidator != null) { 94 setValidator(Validator.TIMESTAMP_VALIDATOR, timestampValidator); 95 } 96 String certificateValidator = ProprietarySecurityPolicyModelHelper.getValidator(comp, Validator.CERTIFICATE_VALIDATOR); 97 if (certificateValidator != null) { 98 setValidator(Validator.CERTIFICATE_VALIDATOR, certificateValidator); 99 } 100 String samlValidator = ProprietarySecurityPolicyModelHelper.getValidator(comp, Validator.SAML_VALIDATOR); 101 if (samlValidator != null) { 102 setValidator(Validator.SAML_VALIDATOR, samlValidator); 103 } 104 inSync = false; 105 } 106 107 public void setValue(javax.swing.JComponent source, Object value) { 108 if (source.equals(usernameValidatorTextField)) { 109 String validator = getValidator(Validator.USERNAME_VALIDATOR); 110 if ((validator != null) && (validator.length() == 0)) { 111 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.USERNAME_VALIDATOR, null, false); 112 } else { 113 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.USERNAME_VALIDATOR, validator, false); 114 } 115 return; 116 } 117 118 if (source.equals(timestampValidatorTextField)) { 119 String validator = getValidator(Validator.TIMESTAMP_VALIDATOR); 120 if ((validator != null) && (validator.length() == 0)) { 121 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.TIMESTAMP_VALIDATOR, null, false); 122 } else { 123 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.TIMESTAMP_VALIDATOR, validator, false); 124 } 125 return; 126 } 127 128 if (source.equals(certificateValidatorTextField)) { 129 String validator = getValidator(Validator.CERTIFICATE_VALIDATOR); 130 if ((validator != null) && (validator.length() == 0)) { 131 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.CERTIFICATE_VALIDATOR, null, false); 132 } else { 133 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.CERTIFICATE_VALIDATOR,validator, false); 134 } 135 return; 136 } 137 138 if (source.equals(samlValidatorTextField)) { 139 String validator = getValidator(Validator.SAML_VALIDATOR); 140 if ((validator != null) && (validator.length() == 0)) { 141 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.SAML_VALIDATOR, null, false); 142 } else { 143 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.SAML_VALIDATOR, validator, false); 144 } 145 return; 146 } 147 } 148 149 private class JavaFileFilter extends FileFilter { 150 private static final String JAVA_EXT = ".java"; public boolean accept(File f) { 152 if ((f != null) && f.exists() && (f.getName() != null) && ((f.getName().contains(JAVA_EXT)) || (f.isDirectory()))) { 153 return true; 154 } 155 return false; 156 } 157 public String getDescription() { 158 return NbBundle.getMessage(WSITEditor.class, "JAVA_FILE"); } 160 } 161 162 public void storeState() { 163 String usernameV = getValidator(Validator.USERNAME_VALIDATOR); 164 if ((usernameV == null) || (usernameV.length() == 0)) { 165 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.USERNAME_VALIDATOR, null, false); 166 } else { 167 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.USERNAME_VALIDATOR, usernameV, false); 168 } 169 170 String certV = getValidator(Validator.CERTIFICATE_VALIDATOR); 171 if ((certV == null) || (certV.length() == 0)) { 172 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.CERTIFICATE_VALIDATOR, null, false); 173 } else { 174 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.CERTIFICATE_VALIDATOR, certV, false); 175 } 176 177 String timeV = getValidator(Validator.TIMESTAMP_VALIDATOR); 178 if ((timeV == null) || (timeV.length() == 0)) { 179 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.TIMESTAMP_VALIDATOR, null, false); 180 } else { 181 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.TIMESTAMP_VALIDATOR, timeV, false); 182 } 183 184 String samlV = getValidator(Validator.SAML_VALIDATOR); 185 if ((samlV == null) || (samlV.length() == 0)) { 186 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.SAML_VALIDATOR, null, false); 187 } else { 188 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.SAML_VALIDATOR, samlV, false); 189 } 190 } 191 192 197 private void initComponents() { 199 jToggleButton1 = new javax.swing.JToggleButton (); 200 usernameValidatorLabel = new javax.swing.JLabel (); 201 timestampValidatorLabel = new javax.swing.JLabel (); 202 certificateValidatorLabel = new javax.swing.JLabel (); 203 samlValidatorLabel = new javax.swing.JLabel (); 204 usernameValidatorTextField = new javax.swing.JTextField (); 205 timestampValidatorTextField = new javax.swing.JTextField (); 206 certificateValidatorTextField = new javax.swing.JTextField (); 207 samlValidatorTextField = new javax.swing.JTextField (); 208 usernameValidatorButton = new javax.swing.JButton (); 209 timestampValidatorButton = new javax.swing.JButton (); 210 certificateValidatorButton = new javax.swing.JButton (); 211 samlValidatorButton = new javax.swing.JButton (); 212 213 jToggleButton1.setText("jToggleButton1"); 214 215 usernameValidatorLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/wsitconf/ui/service/subpanels/Bundle").getString("LBL_ValidatorPanel_UsernameVLabel")); 216 217 timestampValidatorLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/wsitconf/ui/service/subpanels/Bundle").getString("LBL_ValidatorPanel_TimestampVLabel")); 218 219 certificateValidatorLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/wsitconf/ui/service/subpanels/Bundle").getString("LBL_ValidatorPanel_CertificateVLabel")); 220 221 samlValidatorLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/wsitconf/ui/service/subpanels/Bundle").getString("LBL_ValidatorPanel_SAMLVLabel")); 222 223 usernameValidatorButton.setText("Browse..."); 224 usernameValidatorButton.addActionListener(new java.awt.event.ActionListener () { 225 public void actionPerformed(java.awt.event.ActionEvent evt) { 226 usernameValidatorButtonActionPerformed(evt); 227 } 228 }); 229 230 timestampValidatorButton.setText("Browse..."); 231 timestampValidatorButton.addActionListener(new java.awt.event.ActionListener () { 232 public void actionPerformed(java.awt.event.ActionEvent evt) { 233 timestampValidatorButtonActionPerformed(evt); 234 } 235 }); 236 237 certificateValidatorButton.setText("Browse..."); 238 certificateValidatorButton.addActionListener(new java.awt.event.ActionListener () { 239 public void actionPerformed(java.awt.event.ActionEvent evt) { 240 certificateValidatorButtonActionPerformed(evt); 241 } 242 }); 243 244 samlValidatorButton.setText("Browse..."); 245 samlValidatorButton.addActionListener(new java.awt.event.ActionListener () { 246 public void actionPerformed(java.awt.event.ActionEvent evt) { 247 samlValidatorButtonActionPerformed(evt); 248 } 249 }); 250 251 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 252 this.setLayout(layout); 253 layout.setHorizontalGroup( 254 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 255 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 256 .addContainerGap() 257 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 258 .add(layout.createSequentialGroup() 259 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 260 .add(layout.createSequentialGroup() 261 .add(126, 126, 126) 262 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 263 .add(timestampValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 264 .add(certificateValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 265 .add(usernameValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 266, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 266 .add(org.jdesktop.layout.GroupLayout.LEADING, samlValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 267 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 268 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 269 .add(samlValidatorButton) 270 .add(certificateValidatorButton) 271 .add(timestampValidatorButton) 272 .add(usernameValidatorButton))) 273 .add(timestampValidatorLabel)) 274 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 11, Short.MAX_VALUE) 275 .add(jToggleButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 276 .add(layout.createSequentialGroup() 277 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 278 .add(certificateValidatorLabel) 279 .add(samlValidatorLabel) 280 .add(usernameValidatorLabel)) 281 .addContainerGap(389, Short.MAX_VALUE)))) 282 ); 283 284 layout.linkSize(new java.awt.Component [] {certificateValidatorTextField, samlValidatorTextField, timestampValidatorTextField, usernameValidatorTextField}, org.jdesktop.layout.GroupLayout.HORIZONTAL); 285 286 layout.setVerticalGroup( 287 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 288 .add(layout.createSequentialGroup() 289 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 290 .add(layout.createSequentialGroup() 291 .add(69, 69, 69) 292 .add(jToggleButton1)) 293 .add(layout.createSequentialGroup() 294 .addContainerGap() 295 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 296 .add(usernameValidatorLabel) 297 .add(usernameValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 298 .add(usernameValidatorButton)) 299 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 300 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 301 .add(timestampValidatorLabel) 302 .add(timestampValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 303 .add(timestampValidatorButton)) 304 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 305 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 306 .add(certificateValidatorLabel) 307 .add(certificateValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 308 .add(certificateValidatorButton)) 309 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 310 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 311 .add(samlValidatorLabel) 312 .add(samlValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 313 .add(samlValidatorButton)))) 314 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 315 ); 316 } 318 private void samlValidatorButtonActionPerformed(java.awt.event.ActionEvent evt) { if (p != null) { 320 ClassDialog classDialog = new ClassDialog(p, "com.sun.xml.wss.impl.callback.SAMLAssertionValidator"); classDialog.show(); 322 if (classDialog.okButtonPressed()) { 323 Set <String > selectedClasses = classDialog.getSelectedClasses(); 324 for (String selectedClass : selectedClasses) { 325 setValidator(Validator.SAML_VALIDATOR, selectedClass); 326 break; 327 } 328 } 329 } 330 } 332 private void certificateValidatorButtonActionPerformed(java.awt.event.ActionEvent evt) { if (p != null) { 334 ClassDialog classDialog = new ClassDialog(p, "com.sun.xml.wss.impl.callback.CertificateValidationCallback.CertificateValidator"); classDialog.show(); 336 if (classDialog.okButtonPressed()) { 337 Set <String > selectedClasses = classDialog.getSelectedClasses(); 338 for (String selectedClass : selectedClasses) { 339 setValidator(Validator.CERTIFICATE_VALIDATOR, selectedClass); 340 break; 341 } 342 } 343 } 344 } 346 private void timestampValidatorButtonActionPerformed(java.awt.event.ActionEvent evt) { if (p != null) { 348 ClassDialog classDialog = new ClassDialog(p, "com.sun.xml.wss.impl.callback.TimestampValidationCallback.TimestampValidator"); classDialog.show(); 350 if (classDialog.okButtonPressed()) { 351 Set <String > selectedClasses = classDialog.getSelectedClasses(); 352 for (String selectedClass : selectedClasses) { 353 setValidator(Validator.TIMESTAMP_VALIDATOR, selectedClass); 354 break; 355 } 356 } 357 } 358 } 360 private void usernameValidatorButtonActionPerformed(java.awt.event.ActionEvent evt) { if (p != null) { 362 ClassDialog classDialog = new ClassDialog(p, "com.sun.xml.wss.impl.callback.PasswordValidationCallback.PasswordValidator"); classDialog.show(); 364 if (classDialog.okButtonPressed()) { 365 Set <String > selectedClasses = classDialog.getSelectedClasses(); 366 for (String selectedClass : selectedClasses) { 367 setValidator(Validator.USERNAME_VALIDATOR, selectedClass); 368 break; 369 } 370 } 371 } 372 } 374 private javax.swing.JButton certificateValidatorButton; 376 private javax.swing.JLabel certificateValidatorLabel; 377 private javax.swing.JTextField certificateValidatorTextField; 378 private javax.swing.JToggleButton jToggleButton1; 379 private javax.swing.JButton samlValidatorButton; 380 private javax.swing.JLabel samlValidatorLabel; 381 private javax.swing.JTextField samlValidatorTextField; 382 private javax.swing.JButton timestampValidatorButton; 383 private javax.swing.JLabel timestampValidatorLabel; 384 private javax.swing.JTextField timestampValidatorTextField; 385 private javax.swing.JButton usernameValidatorButton; 386 private javax.swing.JLabel usernameValidatorLabel; 387 private javax.swing.JTextField usernameValidatorTextField; 388 390 } 391 | Popular Tags |