1 19 20 package org.netbeans.modules.websvc.wsitconf.ui.service.subpanels; 21 22 import java.text.NumberFormat ; 23 import java.util.Set ; 24 import javax.swing.JCheckBox ; 25 import javax.swing.JPanel ; 26 import javax.swing.text.DefaultFormatterFactory ; 27 import javax.swing.text.NumberFormatter ; 28 import org.jdesktop.layout.GroupLayout; 29 import org.netbeans.api.project.Project; 30 import org.netbeans.modules.websvc.wsitconf.ui.ClassDialog; 31 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProprietarySecurityPolicyModelHelper; 32 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.STSConfiguration; 33 import org.netbeans.modules.xml.multiview.ui.SectionView; 34 import org.netbeans.modules.xml.wsdl.model.Binding; 35 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 36 37 41 public class STSConfigServicePanel extends JPanel { 42 43 private ServiceProvidersTablePanel panel; 44 45 private WSDLModel model; 46 private Binding binding; 47 private SectionView view; 48 49 private Project project; 50 51 private boolean inSync = false; 52 53 private DefaultFormatterFactory lifeTimeDff = null; 54 55 58 public STSConfigServicePanel(WSDLModel model, Project p, Binding binding) { 59 this.model = model; 60 this.project = p; 61 this.binding = binding; 62 63 lifeTimeDff = new DefaultFormatterFactory (); 64 NumberFormat lifetimeFormat = NumberFormat.getIntegerInstance(); 65 lifetimeFormat.setGroupingUsed(false); 66 lifetimeFormat.setParseIntegerOnly(true); 67 lifetimeFormat.setMaximumFractionDigits(0); 68 NumberFormatter lifetimeFormatter = new NumberFormatter (lifetimeFormat); 69 lifetimeFormatter.setCommitsOnValidEdit(true); 70 lifetimeFormatter.setMinimum(0); 71 lifeTimeDff.setDefaultFormatter(lifetimeFormatter); 72 73 initComponents(); 74 75 inSync = true; 76 ServiceProvidersTablePanel.ServiceProvidersTableModel tablemodel = new ServiceProvidersTablePanel.ServiceProvidersTableModel(); 77 this.remove(serviceProvidersPanel); 78 79 STSConfiguration stsConfig = ProprietarySecurityPolicyModelHelper.getSTSConfiguration(binding); 80 if (stsConfig == null) { 81 stsConfig = ProprietarySecurityPolicyModelHelper.createSTSConfiguration(binding); 82 } 83 serviceProvidersPanel = new ServiceProvidersTablePanel(tablemodel, model, stsConfig); 84 ((ServiceProvidersTablePanel)serviceProvidersPanel).populateModel(); 85 inSync = false; 86 87 sync(); 88 89 } 90 91 private void sync() { 92 inSync = true; 93 94 String lifeTime = ProprietarySecurityPolicyModelHelper.getSTSLifeTime(binding); 95 if (lifeTime == null) { setLifeTime(ProprietarySecurityPolicyModelHelper.DEFAULT_LIFETIME); 97 ProprietarySecurityPolicyModelHelper.setSTSLifeTime(binding, ProprietarySecurityPolicyModelHelper.DEFAULT_LIFETIME); 98 } else { 99 setLifeTime(lifeTime); 100 } 101 102 boolean encryptKey = ProprietarySecurityPolicyModelHelper.getSTSEncryptKey(binding); 103 setChBox(encryptKeyChBox, encryptKey); 104 105 boolean encryptToken = ProprietarySecurityPolicyModelHelper.getSTSEncryptToken(binding); 106 setChBox(encryptTokenChBox, encryptToken); 107 108 String issuer = ProprietarySecurityPolicyModelHelper.getSTSIssuer(binding); 109 if (issuer != null) { 110 setIssuer(issuer); 111 } 112 113 String cclass = ProprietarySecurityPolicyModelHelper.getSTSContractClass(binding); 114 if (cclass == null) { setContractClass(ProprietarySecurityPolicyModelHelper.DEFAULT_CONTRACT_CLASS); 116 ProprietarySecurityPolicyModelHelper.setSTSContractClass(binding, ProprietarySecurityPolicyModelHelper.DEFAULT_CONTRACT_CLASS); 117 } else { 118 setContractClass(cclass); 119 } 120 121 refreshPanels(); 122 123 inSync = false; 124 } 125 126 private String getLifeTime() { 127 return this.lifeTimeTextField.getText(); 128 } 129 130 private void setLifeTime(String time) { 131 this.lifeTimeTextField.setText(time); 132 } 133 134 private String getIssuer() { 135 return this.issuerField.getText(); 136 } 137 138 private void setIssuer(String issuer) { 139 this.issuerField.setText(issuer); 140 } 141 142 private void setChBox(JCheckBox chBox, Boolean enable) { 143 if (enable == null) { 144 chBox.setSelected(false); 145 } else { 146 chBox.setSelected(enable); 147 } 148 } 149 150 private void setContractClass(String classname) { 151 this.contractTextField.setText(classname); 152 } 153 154 private String getContractClass() { 155 return contractTextField.getText(); 156 } 157 158 private void refreshPanels() { 159 updateLayout(); 160 } 161 162 private void updateLayout() { 163 GroupLayout layout = (GroupLayout)this.getLayout(); 164 this.setLayout(layout); 165 layout.setHorizontalGroup( 166 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 167 .add(layout.createSequentialGroup() 168 .addContainerGap() 169 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 170 .add(serviceProvidersPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 171 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 172 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 173 .add(layout.createSequentialGroup() 174 .add(2, 2, 2) 175 .add(lifeTimeLabel)) 176 .add(contractLabel) 177 .add(issuerLabel)) 178 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 179 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 180 .add(lifeTimeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 90, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 181 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 182 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 183 .add(contractTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE) 184 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 185 .add(contractButton)) 186 .add(issuerField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)) 187 .add(10, 10, 10)) 188 .add(layout.createSequentialGroup() 189 .add(encryptKeyChBox) 190 .addContainerGap(493, Short.MAX_VALUE)) 191 .add(layout.createSequentialGroup() 192 .add(encryptTokenChBox) 193 .addContainerGap(483, Short.MAX_VALUE)))) 194 ); 195 layout.setVerticalGroup( 196 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 197 .add(layout.createSequentialGroup() 198 .addContainerGap() 199 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 200 .add(issuerLabel) 201 .add(issuerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 202 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 203 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 204 .add(contractLabel) 205 .add(contractButton) 206 .add(contractTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 207 .add(8, 8, 8) 208 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 209 .add(lifeTimeLabel) 210 .add(lifeTimeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 211 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 212 .add(encryptKeyChBox) 213 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 214 .add(encryptTokenChBox) 215 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 216 .add(serviceProvidersPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 217 .addContainerGap()) 218 ); 219 } 220 221 226 private void initComponents() { 228 229 serviceProvidersPanel = new javax.swing.JPanel (); 230 lifeTimeLabel = new javax.swing.JLabel (); 231 contractLabel = new javax.swing.JLabel (); 232 contractTextField = new javax.swing.JTextField (); 233 contractButton = new javax.swing.JButton (); 234 issuerLabel = new javax.swing.JLabel (); 235 issuerField = new javax.swing.JTextField (); 236 encryptKeyChBox = new javax.swing.JCheckBox (); 237 encryptTokenChBox = new javax.swing.JCheckBox (); 238 lifeTimeTextField = new javax.swing.JFormattedTextField (); 239 240 serviceProvidersPanel.setAutoscrolls(true); 241 242 org.jdesktop.layout.GroupLayout serviceProvidersPanelLayout = new org.jdesktop.layout.GroupLayout(serviceProvidersPanel); 243 serviceProvidersPanel.setLayout(serviceProvidersPanelLayout); 244 serviceProvidersPanelLayout.setHorizontalGroup( 245 serviceProvidersPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 246 .add(0, 648, Short.MAX_VALUE) 247 ); 248 serviceProvidersPanelLayout.setVerticalGroup( 249 serviceProvidersPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 250 .add(0, 90, Short.MAX_VALUE) 251 ); 252 253 lifeTimeLabel.setText(org.openide.util.NbBundle.getMessage(STSConfigServicePanel.class, "LBL_STSConfig_Lifetime")); 255 contractLabel.setText(org.openide.util.NbBundle.getMessage(STSConfigServicePanel.class, "LBL_STSConfig_Contract")); 257 contractTextField.addKeyListener(new java.awt.event.KeyAdapter () { 258 public void keyReleased(java.awt.event.KeyEvent evt) { 259 contractTextFieldKeyReleased(evt); 260 } 261 }); 262 263 contractButton.setText(org.openide.util.NbBundle.getMessage(STSConfigServicePanel.class, "LBL_STSConfig_Browse")); contractButton.addActionListener(new java.awt.event.ActionListener () { 265 public void actionPerformed(java.awt.event.ActionEvent evt) { 266 contractButtonActionPerformed(evt); 267 } 268 }); 269 270 issuerLabel.setText(org.openide.util.NbBundle.getMessage(STSConfigServicePanel.class, "LBL_STSConfig_Issuer")); 272 issuerField.addKeyListener(new java.awt.event.KeyAdapter () { 273 public void keyReleased(java.awt.event.KeyEvent evt) { 274 issuerFieldKeyReleased(evt); 275 } 276 }); 277 278 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/wsitconf/ui/service/subpanels/Bundle"); encryptKeyChBox.setText(bundle.getString("LBL_STSConfig_EncryptKey")); encryptKeyChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 281 encryptKeyChBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 282 encryptKeyChBox.addActionListener(new java.awt.event.ActionListener () { 283 public void actionPerformed(java.awt.event.ActionEvent evt) { 284 encryptKeyChBoxActionPerformed(evt); 285 } 286 }); 287 288 encryptTokenChBox.setText(bundle.getString("LBL_STSConfig_EncryptToken")); encryptTokenChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 290 encryptTokenChBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 291 encryptTokenChBox.addActionListener(new java.awt.event.ActionListener () { 292 public void actionPerformed(java.awt.event.ActionEvent evt) { 293 encryptTokenChBoxActionPerformed(evt); 294 } 295 }); 296 297 lifeTimeTextField.setFormatterFactory(lifeTimeDff); 298 lifeTimeTextField.addKeyListener(new java.awt.event.KeyAdapter () { 299 public void keyReleased(java.awt.event.KeyEvent evt) { 300 lifeTimeTextFieldKeyReleased(evt); 301 } 302 }); 303 304 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 305 this.setLayout(layout); 306 layout.setHorizontalGroup( 307 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 308 .add(layout.createSequentialGroup() 309 .addContainerGap() 310 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 311 .add(serviceProvidersPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 312 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 313 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 314 .add(layout.createSequentialGroup() 315 .add(2, 2, 2) 316 .add(lifeTimeLabel)) 317 .add(contractLabel) 318 .add(issuerLabel)) 319 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 320 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 321 .add(issuerField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE) 322 .add(layout.createSequentialGroup() 323 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 324 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 325 .add(lifeTimeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 95, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 326 .add(layout.createSequentialGroup() 327 .add(contractTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE) 328 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 329 .add(contractButton))))) 330 .add(10, 10, 10)) 331 .add(layout.createSequentialGroup() 332 .add(encryptKeyChBox) 333 .addContainerGap(523, Short.MAX_VALUE)) 334 .add(layout.createSequentialGroup() 335 .add(encryptTokenChBox) 336 .addContainerGap(509, Short.MAX_VALUE)))) 337 ); 338 layout.setVerticalGroup( 339 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 340 .add(layout.createSequentialGroup() 341 .addContainerGap() 342 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 343 .add(issuerLabel) 344 .add(issuerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 345 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 346 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 347 .add(contractLabel) 348 .add(contractButton) 349 .add(contractTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 350 .add(8, 8, 8) 351 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 352 .add(lifeTimeLabel) 353 .add(lifeTimeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 354 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 355 .add(encryptKeyChBox) 356 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 357 .add(encryptTokenChBox) 358 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 359 .add(serviceProvidersPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 360 .addContainerGap()) 361 ); 362 } 364 private void lifeTimeTextFieldKeyReleased(java.awt.event.KeyEvent evt) { Object o = lifeTimeTextField.getValue(); 366 if (o instanceof Integer ) { 367 String ltime = o.toString(); 368 ProprietarySecurityPolicyModelHelper.setSTSLifeTime(binding, ltime); 369 } 370 } 372 private void encryptTokenChBoxActionPerformed(java.awt.event.ActionEvent evt) { ProprietarySecurityPolicyModelHelper.setSTSEncryptKey(binding, encryptTokenChBox.isSelected()); 374 } 376 private void encryptKeyChBoxActionPerformed(java.awt.event.ActionEvent evt) { ProprietarySecurityPolicyModelHelper.setSTSEncryptToken(binding, encryptKeyChBox.isSelected()); 378 } 380 private void contractTextFieldKeyReleased(java.awt.event.KeyEvent evt) { String c = contractTextField.getText(); 382 ProprietarySecurityPolicyModelHelper.setSTSContractClass(binding, c); 383 } 385 private void issuerFieldKeyReleased(java.awt.event.KeyEvent evt) { String issuer = issuerField.getText(); 387 ProprietarySecurityPolicyModelHelper.setSTSIssuer(binding, issuer); 388 } 390 private void contractButtonActionPerformed(java.awt.event.ActionEvent evt) { if (project != null) { 392 ClassDialog classDialog = new ClassDialog(project, "com.sun.xml.ws.trust.WSTrustContract"); classDialog.show(); 394 if (classDialog.okButtonPressed()) { 395 Set <String > selectedClasses = classDialog.getSelectedClasses(); 396 for (String selectedClass : selectedClasses) { 397 setContractClass(selectedClass); 398 ProprietarySecurityPolicyModelHelper.setSTSContractClass(binding, selectedClass); 399 break; 400 } 401 } 402 } 403 } 405 406 private javax.swing.JButton contractButton; 408 private javax.swing.JLabel contractLabel; 409 private javax.swing.JTextField contractTextField; 410 private javax.swing.JCheckBox encryptKeyChBox; 411 private javax.swing.JCheckBox encryptTokenChBox; 412 private javax.swing.JTextField issuerField; 413 private javax.swing.JLabel issuerLabel; 414 private javax.swing.JLabel lifeTimeLabel; 415 private javax.swing.JFormattedTextField lifeTimeTextField; 416 private javax.swing.JPanel serviceProvidersPanel; 417 419 } 420 | Popular Tags |