KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > handlers > SSLHandlers


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * CommonHandlers.java
26  *
27  */

28
29 package com.sun.enterprise.tools.admingui.handlers;
30
31 import java.io.IOException JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.EventObject JavaDoc;
34 import java.util.StringTokenizer JavaDoc;
35 import java.util.Enumeration JavaDoc;
36
37 import com.iplanet.jato.RequestContext;
38 import com.iplanet.jato.RequestContextImpl;
39 import com.iplanet.jato.RequestManager;
40 import com.iplanet.jato.ViewBeanManager;
41 import com.iplanet.jato.model.DefaultModel;
42 import com.iplanet.jato.model.Model;
43 import com.iplanet.jato.util.RootCauseException;
44 import com.iplanet.jato.view.ContainerView;
45 import com.iplanet.jato.view.ContainerViewBase;
46 import com.iplanet.jato.view.View;
47 import com.iplanet.jato.view.DisplayFieldImpl;
48 import com.iplanet.jato.view.DisplayField;
49 import com.iplanet.jato.view.ViewBase;
50 import com.iplanet.jato.view.ViewBean;
51 import com.iplanet.jato.view.html.SelectableGroup;
52 import com.iplanet.jato.view.html.OptionList;
53 import com.iplanet.jato.view.event.RequestInvocationEvent;
54 import com.iplanet.jato.view.event.ViewRequestInvocationEvent;
55 import com.iplanet.jato.view.event.ViewCommandEvent;
56
57 import javax.management.MBeanException JavaDoc;
58 import javax.management.ObjectName JavaDoc;
59 import javax.management.AttributeList JavaDoc;
60 import javax.management.Attribute JavaDoc;
61
62 import javax.servlet.ServletException JavaDoc;
63 import javax.servlet.ServletRequest JavaDoc;
64 import javax.servlet.http.HttpServletRequest JavaDoc;
65
66 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
67 import com.sun.enterprise.tools.guiframework.model.ModelManager;
68 import com.sun.enterprise.tools.guiframework.view.DescriptorCCPageTitle;
69 import com.sun.enterprise.tools.guiframework.view.DescriptorCCTabs;
70 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView;
71 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
72 import com.sun.enterprise.tools.guiframework.view.ViewDescriptorManager;
73 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor;
74 import com.sun.enterprise.tools.guiframework.view.descriptors.CCActionTableDescriptor;
75 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent;
76 import com.sun.enterprise.tools.guiframework.view.event.ErrorEvent;
77
78 import com.sun.web.ui.model.CCActionTableModelInterface;
79 import com.sun.web.ui.view.html.CCTextField;
80 import com.sun.web.ui.view.html.CCCheckBox;
81 import com.sun.web.ui.taglib.html.CCDropDownMenuTag;
82 import com.sun.web.ui.view.propertysheet.CCPropertySheet;
83 import com.sun.web.ui.view.tabs.CCTabs;
84
85 import com.sun.enterprise.tools.admingui.util.MBeanUtil;
86 import com.sun.enterprise.tools.admingui.util.Util;
87 import com.sun.enterprise.tools.admingui.tree.IndexTreeNode;
88 import com.sun.enterprise.tools.admingui.tree.IndexTreeModelImpl;
89 import com.sun.enterprise.tools.admingui.tree.IndexTreeModel;
90
91 import com.sun.enterprise.security.CipherInfo;
92
93
94 /**
95  *
96  */

97 public class SSLHandlers {
98
99     
100     public void displayCiphersValues(RequestContext ctx, HandlerContext handlerCtx) {
101     View view = handlerCtx.getView();
102         if (!(view instanceof DescriptorContainerView)) {
103             View parent = view.getParent();
104             if (!(parent instanceof DescriptorContainerView)) {
105         throw new FrameworkException("View is not a DescriptorContainerView!", null, view);
106             } else {
107                 view = parent;
108             }
109         }
110         if (view instanceof DescriptorCCPageTitle) {
111             view = view.getParent();
112         }
113         DescriptorContainerView descView = (DescriptorContainerView)view;
114
115         ArrayList JavaDoc cipherNames = (ArrayList JavaDoc)handlerCtx.getInputValue("cipherNames");
116         if (cipherNames == null)
117             throw new FrameworkException("cipherNames not specified", descView.getViewDescriptor(), view);
118         
119         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
120         if (objectName == null)
121             throw new FrameworkException("objectName not specified", descView.getViewDescriptor(), view);
122         
123         Object JavaDoc values = null;
124         try {
125             values = MBeanUtil.getMBeanServer().getAttributes(new ObjectName JavaDoc(objectName),
126                     (String JavaDoc[])cipherNames.toArray(new String JavaDoc[cipherNames.size()]));
127         } catch (Exception JavaDoc ex) {
128             throw new FrameworkException("displayCiphersValues: failed to get MBean values",
129                 ex, descView.getViewDescriptor(), view);
130         }
131
132         AttributeList JavaDoc attrList = (AttributeList JavaDoc)values;
133         boolean allNull = true;
134         for (int i = 0; i < attrList.size(); i++) {
135             Attribute JavaDoc attr = (Attribute JavaDoc)attrList.get(i);
136             Object JavaDoc attrValue = attr.getValue();
137             if (attrValue != null) allNull = false;
138             parseAndSet(descView, attrValue);
139         }
140         if (allNull) {
141             descView.setDisplayFieldValue("allSupported", "true");
142         }
143     }
144     
145     public void createSSL(RequestContext ctx, HandlerContext handlerCtx) {
146     View view = handlerCtx.getView();
147         if (!(view instanceof DescriptorContainerView)) {
148             View parent = view.getParent();
149             if (!(parent instanceof DescriptorContainerView)) {
150         throw new FrameworkException("View is not a DescriptorContainerView!", null, view);
151             } else {
152                 view = parent;
153             }
154         }
155         if (view instanceof DescriptorCCPageTitle) {
156             view = view.getParent();
157         }
158         DescriptorContainerView descView = (DescriptorContainerView)view;
159         
160         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
161         if (objectName == null)
162             throw new FrameworkException("objectName not specified", descView.getViewDescriptor(), view);
163
164         /* We should not delete/create SSL based on whether security is enabled. refer to bug#6172174
165         String securityEnabled = (String)descView.getDisplayFieldValue("securityEnabled"); //fix: hard coded value
166         if (securityEnabled.equalsIgnoreCase("false")){
167             // security not enabled, remove ssl if one exist.
168             deleteSSL(objectName);
169             return;
170         }
171          */

172         
173         //Remove SSL if cert nickname is not entered.
174
String JavaDoc certNickName = (String JavaDoc)descView.getDisplayFieldValue("certificateNickName"); //fix: hard coded value
175
if (Util.isEmpty(certNickName)){
176             deleteSSL(objectName);
177             return;
178         }
179         
180         ArrayList JavaDoc displayNames = (ArrayList JavaDoc)handlerCtx.getInputValue("sslDisplayNames");
181         if (displayNames == null)
182             throw new FrameworkException("sslDisplayNames not specified", descView.getViewDescriptor(), view);
183         
184         ArrayList JavaDoc modelNames = (ArrayList JavaDoc)handlerCtx.getInputValue("sslAttributeNames");
185         if (modelNames == null)
186             throw new FrameworkException("sslModelNames not specified", descView.getViewDescriptor(), view);
187         
188         //ArrayList ssl2CiphersNames = (ArrayList)handlerCtx.getInputValue("ssl2CipherNames");
189
//if (ssl2CiphersNames == null)
190
// throw new FrameworkException("ssl2CipherNames not specified", descView.getViewDescriptor(), view);
191

192         ArrayList JavaDoc ssl3CiphersNames = (ArrayList JavaDoc)handlerCtx.getInputValue("ssl3CipherNames");
193         if (ssl3CiphersNames == null)
194             throw new FrameworkException("ssl3CipherNames not specified", descView.getViewDescriptor(), view);
195
196
197         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
198         if (methodName == null)
199             throw new FrameworkException("methodName not specified", descView.getViewDescriptor(), view);
200         AttributeList JavaDoc attrList = new AttributeList JavaDoc();
201         Attribute JavaDoc attr;
202         for (int i = 0; i < displayNames.size(); i++) {
203             attr = new Attribute JavaDoc((String JavaDoc)modelNames.get(i),
204                 (String JavaDoc)descView.getDisplayFieldValue(((String JavaDoc)(displayNames.get(i)))));
205             attrList.add(attr);
206         if (Util.isLoggableFINEST()) {
207         Util.logFINEST(":::"+modelNames.get(i)+"="+
208             descView.getDisplayFieldValue((String JavaDoc)(displayNames.get(i))));
209         }
210         }
211         
212         //String ciphers = makeCipherList(descView, ssl2CiphersNames);
213
//if (ciphers.equals("") == false) {
214
// attr = new Attribute("ssl2-ciphers", ciphers);
215
// if (Util.isLoggableFINEST()) {
216
// Util.logFINEST("ssl2_ciphers=" + ciphers);
217
// }
218
// attrList.add(attr);
219
//}
220
String JavaDoc allSupported = (String JavaDoc)((CCCheckBox)descView.getChild("allSupported")).getValue();
221         if (allSupported.equals("false")) {
222             String JavaDoc ciphers = makeCipherList(descView, ssl3CiphersNames);
223             if (ciphers.equals("") == false) {
224                 attr = new Attribute JavaDoc("ssl3-tls-ciphers", ciphers);
225                 //util.logFINEST("ssl3_ciphers=" + ciphers);
226
attrList.add(attr);
227             }
228         }
229         // First delete the existing SSL, then create a new one.
230
deleteSSL(objectName);
231         Object JavaDoc returnValue = createSSL(objectName, methodName, attrList);
232
233     if (Util.isLoggableFINER()) {
234         Util.logFINER("createSSLReturnValue: " + returnValue);
235     }
236     }
237
238     private void parseAndSet(DescriptorContainerView view, Object JavaDoc attrValue) {
239         if (attrValue == null) {
240             return;
241         }
242         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(attrValue.toString(),",", false);
243         while (st.hasMoreTokens()) {
244             String JavaDoc cipher = st.nextToken();
245             if (cipher.charAt(0) == '+') {
246                 CipherInfo ci = CipherInfo.getCipherInfo(cipher.substring(1));
247                 if (ci != null) {
248                     view.setDisplayFieldValue(ci.getCipherName(), "true");
249                 }
250             } else if (cipher.charAt(0) == '-') {
251                 CipherInfo ci = CipherInfo.getCipherInfo(cipher.substring(1));
252                 if (ci != null) {
253                     view.setDisplayFieldValue(ci.getCipherName(), "false");
254                 }
255             }
256         }
257     }
258     
259     private String JavaDoc makeCipherList(DescriptorContainerView descView, ArrayList JavaDoc names) {
260         String JavaDoc ciphers = "";
261         for (int i = 0; i < names.size(); i++) {
262             String JavaDoc value = (String JavaDoc)descView.getDisplayFieldValue((String JavaDoc)(names.get(i)));
263             if (value.equalsIgnoreCase("true")) {
264                 if (i != 0) ciphers += ",";
265                 ciphers += "+" + names.get(i);
266             } else {
267                 if (i != 0) ciphers += ",";
268                 ciphers += "-" + names.get(i);
269             }
270         }
271         return ciphers;
272     }
273     
274     private Object JavaDoc deleteSSL(String JavaDoc objectName) {
275         Object JavaDoc returnValue = null;
276         try {
277             returnValue = MBeanUtil.invoke(objectName, "getSsl", null, null);
278         } catch (Exception JavaDoc ex) {
279         //throw new FrameworkException(
280
// "Exception while attempting to peform getSsl.", ex, null, null);
281
}
282         if (returnValue == null)
283             return null;
284         try {
285             returnValue = MBeanUtil.invoke(objectName, "removeSsl", null, null);
286         } catch (Exception JavaDoc ex) {
287         throw new FrameworkException(
288         "Exception while attempting to peform deleteSsl.", ex, null, null);
289         }
290         return returnValue;
291     }
292     
293     private Object JavaDoc createSSL(String JavaDoc objectName, String JavaDoc methodName, AttributeList JavaDoc attrList) {
294         Object JavaDoc params[] = {attrList};
295         String JavaDoc types[] = {"javax.management.AttributeList"};
296         Object JavaDoc returnValue = null;
297         try {
298             returnValue = MBeanUtil.invoke(objectName, methodName, params, types);
299         } catch (Exception JavaDoc ex) {
300         throw new FrameworkException(
301         "Exception while attempting to peform create.", ex, null, null);
302         }
303         return returnValue;
304     }
305         
306     
307 }
308
Popular Tags