1 19 20 package org.netbeans.modules.websvc.wsitconf.ui.client; 21 22 import java.awt.Color ; 23 import java.util.Set ; 24 import javax.swing.JPanel ; 25 import org.jdesktop.layout.GroupLayout; 26 import org.netbeans.api.project.FileOwnerQuery; 27 import org.netbeans.api.project.Project; 28 import org.netbeans.modules.websvc.wsitconf.ui.ClassDialog; 29 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.CallbackHandler; 30 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProprietarySecurityPolicyModelHelper; 31 import org.netbeans.modules.xml.multiview.ui.SectionInnerPanel; 32 import org.netbeans.modules.xml.multiview.ui.SectionView; 33 import org.netbeans.modules.xml.multiview.ui.SectionVisualTheme; 34 import org.netbeans.modules.xml.wsdl.model.Binding; 35 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 36 import org.openide.filesystems.FileObject; 37 import org.openide.nodes.Node; 38 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel; 39 import org.netbeans.modules.websvc.wsitconf.spi.SecurityCheckerRegistry; 40 import org.netbeans.modules.websvc.wsitconf.ui.ComboConstants; 41 import org.netbeans.modules.websvc.wsitconf.ui.client.subpanels.DynamicCredsPanel; 42 import org.netbeans.modules.websvc.wsitconf.ui.client.subpanels.StaticCredsPanel; 43 import org.netbeans.modules.xml.multiview.ui.NodeSectionPanel; 44 45 49 public class CallbackPanel extends SectionInnerPanel { 50 51 private WSDLModel model; 52 private Node node; 53 private Binding binding; 54 55 private boolean inSync = false; 56 57 private Project project; 58 59 private SectionView view; 60 private JaxWsModel jaxwsmodel; 61 62 public CallbackPanel(SectionView view, WSDLModel model, Node node, Binding binding, JaxWsModel jaxWsModel) { 63 super(view); 64 this.view = view; 65 this.model = model; 66 this.node = node; 67 this.binding = binding; 68 this.jaxwsmodel = jaxWsModel; 69 70 FileObject fo = (FileObject) node.getLookup().lookup(FileObject.class); 71 if (fo != null) project = FileOwnerQuery.getOwner(fo); 72 73 initComponents(); 74 75 samlHandlerField.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 76 samlHandlerLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 77 78 credTypeCombo.removeAllItems(); 79 credTypeCombo.addItem(ComboConstants.STATIC); 80 credTypeCombo.addItem(ComboConstants.DYNAMIC); 81 82 addImmediateModifier(samlHandlerField); 83 addImmediateModifier(credTypeCombo); 84 85 sync(); 86 } 87 88 public void sync() { 89 inSync = true; 90 91 String samlCallback = ProprietarySecurityPolicyModelHelper.getCallbackHandler(binding, CallbackHandler.SAML_CBHANDLER); 92 if (samlCallback != null) { 93 setCallbackHandler(samlCallback); 94 } 95 96 String usernameCBH = ProprietarySecurityPolicyModelHelper.getCallbackHandler(binding, CallbackHandler.USERNAME_CBHANDLER); 97 if ((usernameCBH != null) && (usernameCBH.length() > 0)) { 98 setCredType(ComboConstants.DYNAMIC); 99 credTypeCombo.setSelectedItem(ComboConstants.DYNAMIC); 100 } else { 101 setCredType(ComboConstants.STATIC); 102 credTypeCombo.setSelectedItem(ComboConstants.STATIC); 103 } 104 105 enableDisable(); 106 107 inSync = false; 108 } 109 110 private JPanel getPanel(String type) { 111 boolean amSec = SecurityCheckerRegistry.getDefault().isNonWsitSecurityEnabled(node, jaxwsmodel); 112 113 if (ComboConstants.DYNAMIC.equals(type)) { 114 return new DynamicCredsPanel(binding, project, !amSec); 115 } 116 return new StaticCredsPanel(binding, project, !amSec); 117 } 118 119 private void setCredType(String credType) { 120 this.remove(credPanel); 121 credPanel = getPanel(credType); 122 NodeSectionPanel panel = view.getActivePanel(); 123 boolean active = (panel == null) ? false : panel.isActive(); 124 Color c = active ? SectionVisualTheme.getSectionActiveBackgroundColor() : SectionVisualTheme.getDocumentBackgroundColor(); 125 credPanel.setBackground(c); 126 refreshLayout(); 127 } 128 129 @Override 130 public void setValue(javax.swing.JComponent source, Object value) { 131 if (inSync) return; 132 133 if (source.equals(credTypeCombo)) { 134 ProprietarySecurityPolicyModelHelper.setCallbackHandler(binding, CallbackHandler.USERNAME_CBHANDLER, null, null, true); 135 ProprietarySecurityPolicyModelHelper.setCallbackHandler(binding, CallbackHandler.PASSWORD_CBHANDLER, null, null, true); 136 setCredType((String )credTypeCombo.getSelectedItem()); 137 } 138 139 if (source.equals(samlHandlerField)) { 140 String classname = getCallbackHandler(); 141 if ((classname != null) && (classname.length() == 0)) { 142 classname = null; 143 } 144 ProprietarySecurityPolicyModelHelper.setCallbackHandler(binding, CallbackHandler.SAML_CBHANDLER, classname, null, true); 145 return; 146 } 147 148 enableDisable(); 149 } 150 151 @Override 152 public void documentChanged(javax.swing.text.JTextComponent comp, String value) { 153 enableDisable(); 154 } 155 156 @Override 157 public void rollbackValue(javax.swing.text.JTextComponent source) { 158 } 159 160 @Override 161 protected void endUIChange() { 162 } 163 164 public void linkButtonPressed(Object ddBean, String ddProperty) { 165 } 166 167 public javax.swing.JComponent getErrorComponent(String errorId) { 168 return null; 169 } 170 171 private void enableDisable() { 172 173 boolean amSec = SecurityCheckerRegistry.getDefault().isNonWsitSecurityEnabled(node, jaxwsmodel); 174 175 credTypeLabel.setEnabled(!amSec); 176 credTypeCombo.setEnabled(!amSec); 177 samlBrowseButton.setEnabled(!amSec); 178 samlHandlerField.setEnabled(!amSec); 179 samlHandlerLabel.setEnabled(!amSec); 180 } 181 182 private void setCallbackHandler(String classname) { 183 this.samlHandlerField.setText(classname); 184 } 185 186 private String getCallbackHandler() { 187 return samlHandlerField.getText(); 188 } 189 190 private void refreshLayout() { 191 org.jdesktop.layout.GroupLayout layout = (GroupLayout) this.getLayout(); 192 this.setLayout(layout); 193 layout.setHorizontalGroup( 194 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 195 .add(layout.createSequentialGroup() 196 .addContainerGap() 197 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 198 .add(layout.createSequentialGroup() 199 .add(credTypeLabel) 200 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 201 .add(credTypeCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 202 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 203 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 204 .add(org.jdesktop.layout.GroupLayout.LEADING, credPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 205 .add(layout.createSequentialGroup() 206 .add(samlHandlerLabel) 207 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 208 .add(samlHandlerField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE) 209 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 210 .add(samlBrowseButton))) 211 .add(35, 35, 35))) 212 .add(0, 0, 0)) 213 ); 214 layout.setVerticalGroup( 215 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 216 .add(layout.createSequentialGroup() 217 .addContainerGap() 218 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 219 .add(credTypeLabel) 220 .add(credTypeCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 221 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 222 .add(credPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 223 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 224 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 225 .add(samlHandlerLabel) 226 .add(samlHandlerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 227 .add(samlBrowseButton)) 228 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 229 ); 230 } 231 232 237 private void initComponents() { 239 240 samlHandlerLabel = new javax.swing.JLabel (); 241 samlHandlerField = new javax.swing.JTextField (); 242 samlBrowseButton = new javax.swing.JButton (); 243 credTypeCombo = new javax.swing.JComboBox (); 244 credTypeLabel = new javax.swing.JLabel (); 245 credPanel = new javax.swing.JPanel (); 246 247 addFocusListener(new java.awt.event.FocusAdapter () { 248 public void focusGained(java.awt.event.FocusEvent evt) { 249 formFocusGained(evt); 250 } 251 }); 252 addAncestorListener(new javax.swing.event.AncestorListener () { 253 public void ancestorMoved(javax.swing.event.AncestorEvent evt) { 254 } 255 public void ancestorAdded(javax.swing.event.AncestorEvent evt) { 256 formAncestorAdded(evt); 257 } 258 public void ancestorRemoved(javax.swing.event.AncestorEvent evt) { 259 } 260 }); 261 262 samlHandlerLabel.setLabelFor(samlHandlerField); 263 org.openide.awt.Mnemonics.setLocalizedText(samlHandlerLabel, org.openide.util.NbBundle.getMessage(CallbackPanel.class, "LBL_KeyStorePanel_SamlLabel")); 265 org.openide.awt.Mnemonics.setLocalizedText(samlBrowseButton, org.openide.util.NbBundle.getMessage(CallbackPanel.class, "LBL_AuthPanel_SCHBrowseButton")); samlBrowseButton.addActionListener(new java.awt.event.ActionListener () { 267 public void actionPerformed(java.awt.event.ActionEvent evt) { 268 samlBrowseButtonActionPerformed(evt); 269 } 270 }); 271 272 credTypeCombo.setModel(new javax.swing.DefaultComboBoxModel (new String [] { "Static", "Dynamic" })); 273 274 org.openide.awt.Mnemonics.setLocalizedText(credTypeLabel, org.openide.util.NbBundle.getMessage(CallbackPanel.class, "LBL_KeyStorePanel_AuthTypeLabel")); 276 org.jdesktop.layout.GroupLayout credPanelLayout = new org.jdesktop.layout.GroupLayout(credPanel); 277 credPanel.setLayout(credPanelLayout); 278 credPanelLayout.setHorizontalGroup( 279 credPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 280 .add(0, 516, Short.MAX_VALUE) 281 ); 282 credPanelLayout.setVerticalGroup( 283 credPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 284 .add(0, 64, Short.MAX_VALUE) 285 ); 286 287 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 288 this.setLayout(layout); 289 layout.setHorizontalGroup( 290 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 291 .add(layout.createSequentialGroup() 292 .addContainerGap() 293 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 294 .add(layout.createSequentialGroup() 295 .add(credTypeLabel) 296 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 297 .add(credTypeCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 298 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 299 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 300 .add(org.jdesktop.layout.GroupLayout.LEADING, credPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 301 .add(layout.createSequentialGroup() 302 .add(samlHandlerLabel) 303 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 304 .add(samlHandlerField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE) 305 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 306 .add(samlBrowseButton))) 307 .add(35, 35, 35))) 308 .add(0, 0, 0)) 309 ); 310 layout.setVerticalGroup( 311 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 312 .add(layout.createSequentialGroup() 313 .addContainerGap() 314 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 315 .add(credTypeLabel) 316 .add(credTypeCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 317 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 318 .add(credPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 319 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 320 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 321 .add(samlHandlerLabel) 322 .add(samlHandlerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 323 .add(samlBrowseButton)) 324 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 325 ); 326 } 328 private void formFocusGained(java.awt.event.FocusEvent evt) { enableDisable(); 330 } 332 private void formAncestorAdded(javax.swing.event.AncestorEvent evt) { enableDisable(); 334 } 336 private void samlBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) { if (project != null) { 338 ClassDialog classDialog = new ClassDialog(project, "javax.security.auth.callback.CallbackHandler"); classDialog.show(); 340 if (classDialog.okButtonPressed()) { 341 Set <String > selectedClasses = classDialog.getSelectedClasses(); 342 for (String selectedClass : selectedClasses) { 343 setCallbackHandler(selectedClass); 344 ProprietarySecurityPolicyModelHelper.setCallbackHandler(binding, CallbackHandler.SAML_CBHANDLER, selectedClass, null, true); 345 break; 346 } 347 } 348 } 349 } 351 private javax.swing.JPanel credPanel; 353 private javax.swing.JComboBox credTypeCombo; 354 private javax.swing.JLabel credTypeLabel; 355 private javax.swing.JButton samlBrowseButton; 356 private javax.swing.JTextField samlHandlerField; 357 private javax.swing.JLabel samlHandlerLabel; 358 360 } 361 | Popular Tags |