KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > ui > client > CallbackPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.wsitconf.ui.client;
21
22 import java.awt.Color JavaDoc;
23 import java.util.Set JavaDoc;
24 import javax.swing.JPanel JavaDoc;
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 /**
46  *
47  * @author Martin Grebac
48  */

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 JavaDoc samlCallback = ProprietarySecurityPolicyModelHelper.getCallbackHandler(binding, CallbackHandler.SAML_CBHANDLER);
92         if (samlCallback != null) {
93             setCallbackHandler(samlCallback);
94         }
95         
96         String JavaDoc 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 JavaDoc getPanel(String JavaDoc 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 JavaDoc credType) {
120         this.remove(credPanel);
121         credPanel = getPanel(credType);
122         NodeSectionPanel panel = view.getActivePanel();
123         boolean active = (panel == null) ? false : panel.isActive();
124         Color JavaDoc c = active ? SectionVisualTheme.getSectionActiveBackgroundColor() : SectionVisualTheme.getDocumentBackgroundColor();
125         credPanel.setBackground(c);
126         refreshLayout();
127     }
128
129     @Override JavaDoc
130     public void setValue(javax.swing.JComponent JavaDoc source, Object JavaDoc 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 JavaDoc)credTypeCombo.getSelectedItem());
137         }
138         
139         if (source.equals(samlHandlerField)) {
140             String JavaDoc 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 JavaDoc
152     public void documentChanged(javax.swing.text.JTextComponent JavaDoc comp, String JavaDoc value) {
153         enableDisable();
154     }
155
156     @Override JavaDoc
157     public void rollbackValue(javax.swing.text.JTextComponent JavaDoc source) {
158     }
159     
160     @Override JavaDoc
161     protected void endUIChange() {
162     }
163
164     public void linkButtonPressed(Object JavaDoc ddBean, String JavaDoc ddProperty) {
165     }
166
167     public javax.swing.JComponent JavaDoc getErrorComponent(String JavaDoc 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 JavaDoc classname) {
183         this.samlHandlerField.setText(classname);
184     }
185
186     private String JavaDoc 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     /** This method is called from within the constructor to
233      * initialize the form.
234      * WARNING: Do NOT modify this code. The content of this method is
235      * always regenerated by the Form Editor.
236      */

237     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
238
private void initComponents() {
239
240         samlHandlerLabel = new javax.swing.JLabel JavaDoc();
241         samlHandlerField = new javax.swing.JTextField JavaDoc();
242         samlBrowseButton = new javax.swing.JButton JavaDoc();
243         credTypeCombo = new javax.swing.JComboBox JavaDoc();
244         credTypeLabel = new javax.swing.JLabel JavaDoc();
245         credPanel = new javax.swing.JPanel JavaDoc();
246
247         addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
248             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
249                 formFocusGained(evt);
250             }
251         });
252         addAncestorListener(new javax.swing.event.AncestorListener JavaDoc() {
253             public void ancestorMoved(javax.swing.event.AncestorEvent JavaDoc evt) {
254             }
255             public void ancestorAdded(javax.swing.event.AncestorEvent JavaDoc evt) {
256                 formAncestorAdded(evt);
257             }
258             public void ancestorRemoved(javax.swing.event.AncestorEvent JavaDoc 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")); // NOI18N
264

265         org.openide.awt.Mnemonics.setLocalizedText(samlBrowseButton, org.openide.util.NbBundle.getMessage(CallbackPanel.class, "LBL_AuthPanel_SCHBrowseButton")); // NOI18N
266
samlBrowseButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
267             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
268                 samlBrowseButtonActionPerformed(evt);
269             }
270         });
271
272         credTypeCombo.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(new String JavaDoc[] { "Static", "Dynamic" }));
273
274         org.openide.awt.Mnemonics.setLocalizedText(credTypeLabel, org.openide.util.NbBundle.getMessage(CallbackPanel.class, "LBL_KeyStorePanel_AuthTypeLabel")); // NOI18N
275

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     }// </editor-fold>//GEN-END:initComponents
327

328 private void formFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_formFocusGained
329
enableDisable();
330 }//GEN-LAST:event_formFocusGained
331

332 private void formAncestorAdded(javax.swing.event.AncestorEvent JavaDoc evt) {//GEN-FIRST:event_formAncestorAdded
333
enableDisable();
334 }//GEN-LAST:event_formAncestorAdded
335

336     private void samlBrowseButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_samlBrowseButtonActionPerformed
337
if (project != null) {
338             ClassDialog classDialog = new ClassDialog(project, "javax.security.auth.callback.CallbackHandler"); //NOI18N
339
classDialog.show();
340             if (classDialog.okButtonPressed()) {
341                 Set JavaDoc<String JavaDoc> selectedClasses = classDialog.getSelectedClasses();
342                 for (String JavaDoc selectedClass : selectedClasses) {
343                     setCallbackHandler(selectedClass);
344                     ProprietarySecurityPolicyModelHelper.setCallbackHandler(binding, CallbackHandler.SAML_CBHANDLER, selectedClass, null, true);
345                     break;
346                 }
347             }
348         }
349     }//GEN-LAST:event_samlBrowseButtonActionPerformed
350

351     // Variables declaration - do not modify//GEN-BEGIN:variables
352
private javax.swing.JPanel JavaDoc credPanel;
353     private javax.swing.JComboBox JavaDoc credTypeCombo;
354     private javax.swing.JLabel JavaDoc credTypeLabel;
355     private javax.swing.JButton JavaDoc samlBrowseButton;
356     private javax.swing.JTextField JavaDoc samlHandlerField;
357     private javax.swing.JLabel JavaDoc samlHandlerLabel;
358     // End of variables declaration//GEN-END:variables
359

360 }
361
Popular Tags