1 23 24 28 29 package com.sun.enterprise.tools.admingui.handlers; 30 31 import java.io.IOException ; 32 import java.util.ArrayList ; 33 import java.util.EventObject ; 34 import java.util.StringTokenizer ; 35 import java.util.Enumeration ; 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 ; 58 import javax.management.ObjectName ; 59 import javax.management.AttributeList ; 60 import javax.management.Attribute ; 61 62 import javax.servlet.ServletException ; 63 import javax.servlet.ServletRequest ; 64 import javax.servlet.http.HttpServletRequest ; 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 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 cipherNames = (ArrayList )handlerCtx.getInputValue("cipherNames"); 116 if (cipherNames == null) 117 throw new FrameworkException("cipherNames not specified", descView.getViewDescriptor(), view); 118 119 String objectName = (String )handlerCtx.getInputValue("objectName"); 120 if (objectName == null) 121 throw new FrameworkException("objectName not specified", descView.getViewDescriptor(), view); 122 123 Object values = null; 124 try { 125 values = MBeanUtil.getMBeanServer().getAttributes(new ObjectName (objectName), 126 (String [])cipherNames.toArray(new String [cipherNames.size()])); 127 } catch (Exception ex) { 128 throw new FrameworkException("displayCiphersValues: failed to get MBean values", 129 ex, descView.getViewDescriptor(), view); 130 } 131 132 AttributeList attrList = (AttributeList )values; 133 boolean allNull = true; 134 for (int i = 0; i < attrList.size(); i++) { 135 Attribute attr = (Attribute )attrList.get(i); 136 Object 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 objectName = (String )handlerCtx.getInputValue("objectName"); 161 if (objectName == null) 162 throw new FrameworkException("objectName not specified", descView.getViewDescriptor(), view); 163 164 172 173 String certNickName = (String )descView.getDisplayFieldValue("certificateNickName"); if (Util.isEmpty(certNickName)){ 176 deleteSSL(objectName); 177 return; 178 } 179 180 ArrayList displayNames = (ArrayList )handlerCtx.getInputValue("sslDisplayNames"); 181 if (displayNames == null) 182 throw new FrameworkException("sslDisplayNames not specified", descView.getViewDescriptor(), view); 183 184 ArrayList modelNames = (ArrayList )handlerCtx.getInputValue("sslAttributeNames"); 185 if (modelNames == null) 186 throw new FrameworkException("sslModelNames not specified", descView.getViewDescriptor(), view); 187 188 192 ArrayList ssl3CiphersNames = (ArrayList )handlerCtx.getInputValue("ssl3CipherNames"); 193 if (ssl3CiphersNames == null) 194 throw new FrameworkException("ssl3CipherNames not specified", descView.getViewDescriptor(), view); 195 196 197 String methodName = (String )handlerCtx.getInputValue("methodName"); 198 if (methodName == null) 199 throw new FrameworkException("methodName not specified", descView.getViewDescriptor(), view); 200 AttributeList attrList = new AttributeList (); 201 Attribute attr; 202 for (int i = 0; i < displayNames.size(); i++) { 203 attr = new Attribute ((String )modelNames.get(i), 204 (String )descView.getDisplayFieldValue(((String )(displayNames.get(i))))); 205 attrList.add(attr); 206 if (Util.isLoggableFINEST()) { 207 Util.logFINEST(":::"+modelNames.get(i)+"="+ 208 descView.getDisplayFieldValue((String )(displayNames.get(i)))); 209 } 210 } 211 212 String allSupported = (String )((CCCheckBox)descView.getChild("allSupported")).getValue(); 221 if (allSupported.equals("false")) { 222 String ciphers = makeCipherList(descView, ssl3CiphersNames); 223 if (ciphers.equals("") == false) { 224 attr = new Attribute ("ssl3-tls-ciphers", ciphers); 225 attrList.add(attr); 227 } 228 } 229 deleteSSL(objectName); 231 Object 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 attrValue) { 239 if (attrValue == null) { 240 return; 241 } 242 StringTokenizer st = new StringTokenizer (attrValue.toString(),",", false); 243 while (st.hasMoreTokens()) { 244 String 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 makeCipherList(DescriptorContainerView descView, ArrayList names) { 260 String ciphers = ""; 261 for (int i = 0; i < names.size(); i++) { 262 String value = (String )descView.getDisplayFieldValue((String )(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 deleteSSL(String objectName) { 275 Object returnValue = null; 276 try { 277 returnValue = MBeanUtil.invoke(objectName, "getSsl", null, null); 278 } catch (Exception ex) { 279 } 282 if (returnValue == null) 283 return null; 284 try { 285 returnValue = MBeanUtil.invoke(objectName, "removeSsl", null, null); 286 } catch (Exception ex) { 287 throw new FrameworkException( 288 "Exception while attempting to peform deleteSsl.", ex, null, null); 289 } 290 return returnValue; 291 } 292 293 private Object createSSL(String objectName, String methodName, AttributeList attrList) { 294 Object params[] = {attrList}; 295 String types[] = {"javax.management.AttributeList"}; 296 Object returnValue = null; 297 try { 298 returnValue = MBeanUtil.invoke(objectName, methodName, params, types); 299 } catch (Exception 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 |