1 19 20 package org.netbeans.modules.websvc.wsitconf.ui.client.subpanels; 21 22 import java.util.Set ; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.modules.websvc.wsitconf.ui.ClassDialog; 25 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProprietarySecurityPolicyModelHelper; 26 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.CallbackHandler; 27 import org.netbeans.modules.xml.wsdl.model.Binding; 28 29 33 34 public class DynamicCredsPanel extends javax.swing.JPanel { 35 36 private boolean inSync = false; 37 38 private Binding binding; 39 private boolean enable; 40 41 private Project project; 42 43 44 public DynamicCredsPanel(Binding b, Project project, boolean enable) { 45 this.binding = b; 46 this.enable = enable; 47 this.project = project; 48 49 initComponents(); 50 51 sync(); 56 } 57 58 public void sync() { 59 inSync = true; 60 61 String usernameCallback = ProprietarySecurityPolicyModelHelper.getCallbackHandler(binding, CallbackHandler.USERNAME_CBHANDLER); 62 if (usernameCallback != null) { 63 setCallbackHandler(usernameCallback, CallbackHandler.USERNAME_CBHANDLER); 64 } 65 String passwdCallback = ProprietarySecurityPolicyModelHelper.getCallbackHandler(binding, CallbackHandler.PASSWORD_CBHANDLER); 66 if (passwdCallback != null) { 67 setCallbackHandler(passwdCallback, CallbackHandler.PASSWORD_CBHANDLER); 68 } 69 70 enableDisable(); 71 72 inSync = false; 73 } 74 75 public void setValue(javax.swing.JComponent source, Object value) { 76 if (inSync) return; 77 78 if (source.equals(usernameHandlerField)) { 79 String classname = getCallbackHandler(CallbackHandler.USERNAME_CBHANDLER); 80 if ((classname != null) && (classname.length() == 0)) { 81 classname = null; 82 } 83 ProprietarySecurityPolicyModelHelper.setCallbackHandler(binding, CallbackHandler.USERNAME_CBHANDLER, classname, null, true); 84 return; 85 } 86 87 if (source.equals(passwdHandlerField)) { 88 String classname = getCallbackHandler(CallbackHandler.PASSWORD_CBHANDLER); 89 if ((classname != null) && (classname.length() == 0)) { 90 classname = null; 91 } 92 ProprietarySecurityPolicyModelHelper.setCallbackHandler(binding, CallbackHandler.PASSWORD_CBHANDLER, classname, null, true); 93 return; 94 } 95 96 enableDisable(); 97 } 98 99 private void enableDisable() { 100 passwdBrowseButton.setEnabled(enable); 101 passwdHandlerField.setEnabled(enable); 102 passwdHandlerLabel.setEnabled(enable); 103 usernameBrowseButton.setEnabled(enable); 104 usernameHandlerField.setEnabled(enable); 105 usernameHandlerLabel.setEnabled(enable); 106 } 107 108 private String getCallbackHandler(String type) { 109 if (CallbackHandler.USERNAME_CBHANDLER.equals(type)) return usernameHandlerField.getText(); 110 if (CallbackHandler.PASSWORD_CBHANDLER.equals(type)) return passwdHandlerField.getText(); 111 return null; 112 } 113 114 private void setCallbackHandler(String classname, String type) { 115 if (CallbackHandler.USERNAME_CBHANDLER.equals(type)) this.usernameHandlerField.setText(classname); 116 if (CallbackHandler.PASSWORD_CBHANDLER.equals(type)) this.passwdHandlerField.setText(classname); 117 } 118 119 124 private void initComponents() { 126 127 usernameHandlerLabel = new javax.swing.JLabel (); 128 usernameHandlerField = new javax.swing.JTextField (); 129 passwdHandlerLabel = new javax.swing.JLabel (); 130 passwdHandlerField = new javax.swing.JTextField (); 131 usernameBrowseButton = new javax.swing.JButton (); 132 passwdBrowseButton = new javax.swing.JButton (); 133 134 org.openide.awt.Mnemonics.setLocalizedText(usernameHandlerLabel, org.openide.util.NbBundle.getMessage(DynamicCredsPanel.class, "LBL_UsernameCBHLabel")); 136 usernameHandlerField.addKeyListener(new java.awt.event.KeyAdapter () { 137 public void keyReleased(java.awt.event.KeyEvent evt) { 138 usernameHandlerFieldKeyReleased(evt); 139 } 140 }); 141 142 org.openide.awt.Mnemonics.setLocalizedText(passwdHandlerLabel, org.openide.util.NbBundle.getMessage(DynamicCredsPanel.class, "LBL_PasswordCBHLabel")); 144 passwdHandlerField.addKeyListener(new java.awt.event.KeyAdapter () { 145 public void keyReleased(java.awt.event.KeyEvent evt) { 146 passwdHandlerFieldKeyReleased(evt); 147 } 148 }); 149 150 org.openide.awt.Mnemonics.setLocalizedText(usernameBrowseButton, org.openide.util.NbBundle.getMessage(DynamicCredsPanel.class, "LBL_Username_Browse")); usernameBrowseButton.addActionListener(new java.awt.event.ActionListener () { 152 public void actionPerformed(java.awt.event.ActionEvent evt) { 153 usernameBrowseButtonActionPerformed(evt); 154 } 155 }); 156 157 org.openide.awt.Mnemonics.setLocalizedText(passwdBrowseButton, org.openide.util.NbBundle.getMessage(DynamicCredsPanel.class, "LBL_Password_Browse")); passwdBrowseButton.addActionListener(new java.awt.event.ActionListener () { 159 public void actionPerformed(java.awt.event.ActionEvent evt) { 160 passwdBrowseButtonActionPerformed(evt); 161 } 162 }); 163 164 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 165 this.setLayout(layout); 166 layout.setHorizontalGroup( 167 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 168 .add(layout.createSequentialGroup() 169 .addContainerGap() 170 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 171 .add(layout.createSequentialGroup() 172 .add(passwdHandlerLabel) 173 .add(13, 13, 13)) 174 .add(layout.createSequentialGroup() 175 .add(usernameHandlerLabel) 176 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))) 177 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 178 .add(usernameHandlerField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE) 179 .add(passwdHandlerField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)) 180 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 181 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 182 .add(usernameBrowseButton) 183 .add(passwdBrowseButton)) 184 .addContainerGap()) 185 ); 186 layout.setVerticalGroup( 187 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 188 .add(layout.createSequentialGroup() 189 .addContainerGap() 190 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 191 .add(usernameBrowseButton) 192 .add(usernameHandlerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 193 .add(usernameHandlerLabel)) 194 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 195 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 196 .add(passwdBrowseButton) 197 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 198 .add(passwdHandlerLabel) 199 .add(passwdHandlerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) 200 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 201 ); 202 } 204 private void passwdHandlerFieldKeyReleased(java.awt.event.KeyEvent evt) { setValue(passwdHandlerField, null); 206 } 208 private void usernameHandlerFieldKeyReleased(java.awt.event.KeyEvent evt) { setValue(usernameHandlerField, null); 210 } 212 private void passwdBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) { if (project != null) { 214 ClassDialog classDialog = new ClassDialog(project, "javax.security.auth.callback.CallbackHandler"); classDialog.show(); 216 if (classDialog.okButtonPressed()) { 217 Set <String > selectedClasses = classDialog.getSelectedClasses(); 218 for (String selectedClass : selectedClasses) { 219 setCallbackHandler(selectedClass, CallbackHandler.PASSWORD_CBHANDLER); 220 ProprietarySecurityPolicyModelHelper.setCallbackHandler(binding, CallbackHandler.PASSWORD_CBHANDLER, selectedClass, null, true); 221 break; 222 } 223 } 224 } 225 } 227 private void usernameBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) { if (project != null) { 229 ClassDialog classDialog = new ClassDialog(project, "javax.security.auth.callback.CallbackHandler"); classDialog.show(); 231 if (classDialog.okButtonPressed()) { 232 Set <String > selectedClasses = classDialog.getSelectedClasses(); 233 for (String selectedClass : selectedClasses) { 234 setCallbackHandler(selectedClass, CallbackHandler.USERNAME_CBHANDLER); 235 ProprietarySecurityPolicyModelHelper.setCallbackHandler(binding, CallbackHandler.USERNAME_CBHANDLER, selectedClass, null, true); 236 break; 237 } 238 } 239 } 240 } 242 243 private javax.swing.JButton passwdBrowseButton; 245 private javax.swing.JTextField passwdHandlerField; 246 private javax.swing.JLabel passwdHandlerLabel; 247 private javax.swing.JButton usernameBrowseButton; 248 private javax.swing.JTextField usernameHandlerField; 249 private javax.swing.JLabel usernameHandlerLabel; 250 252 } 253 | Popular Tags |