1 23 24 29 30 package com.sun.enterprise.tools.admingui.handlers; 31 32 33 import java.util.Map ; 34 35 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 36 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 37 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 38 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 39 import com.iplanet.jato.view.html.SelectableGroup; 40 import com.iplanet.jato.view.html.OptionList; 41 import com.iplanet.jato.RequestContext; 42 43 import javax.management.Attribute ; 44 import javax.management.AttributeList ; 45 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 46 import com.sun.enterprise.tools.admingui.util.AMXUtil; 47 import com.sun.enterprise.tools.admingui.util.Util; 48 49 import com.sun.appserv.management.config.ConfigConfig; 50 import com.sun.appserv.management.config.SecurityServiceConfig; 51 52 56 public class MsgSecurityConfigHandler { 57 58 65 public void createMessageSecurityProvider(RequestContext reqCtx, HandlerContext handlerCtx) { 66 String objectName = (String )handlerCtx.getInputValue("objectName"); 67 String configName = (String )handlerCtx.getInputValue("configName"); 68 String msgSecurityName = (String )handlerCtx.getInputValue("msgSecurityName"); 69 String isDefaultProvider = (String )handlerCtx.getInputValue("isDefaultProvider"); 70 Object providerProperties = handlerCtx.getInputValue("providerProperties"); 71 AttributeList providerAttr = (AttributeList )handlerCtx.getInputValue("providerAttr"); 72 AttributeList requestAttr = (AttributeList )handlerCtx.getInputValue("requestAttr"); 73 AttributeList responseAttr = (AttributeList )handlerCtx.getInputValue("responseAttr"); 74 75 if (objectName == null) { 76 throw new IllegalArgumentException ( 77 "The parameter map did not contain objectName"); 78 } 79 try { 80 String providerId = getAttrValue( providerAttr, "provider-id"); 81 String providerType = getAttrValue( providerAttr, "provider-type"); 82 String className = getAttrValue( providerAttr, "class-name"); 83 84 String requestAuthSource = getAttrValue( requestAttr, "auth-source"); 85 String requestRecipient = getAttrValue( requestAttr, "auth-recipient"); 86 87 String responseAuthSource = getAttrValue( responseAttr, "auth-source"); 88 String responseRecipient = getAttrValue( responseAttr, "auth-recipient"); 89 90 if(Util.isEmpty(requestAuthSource)) requestAuthSource = null; 91 if(Util.isEmpty(requestRecipient)) requestRecipient = null; 92 if(Util.isEmpty(responseAuthSource)) responseAuthSource = null; 93 if(Util.isEmpty(responseRecipient)) responseRecipient = null; 94 95 Object [] params = new Object [] { 96 msgSecurityName, providerId, providerType, className, requestAuthSource, requestRecipient, responseAuthSource, responseRecipient, new Boolean (isDefaultProvider), providerProperties, configName }; 108 109 String [] types = new String [] { 110 "java.lang.String", 111 "java.lang.String", 112 "java.lang.String", 113 "java.lang.String", 114 "java.lang.String", 115 "java.lang.String", 116 "java.lang.String", 117 "java.lang.String", 118 "boolean", 119 "java.util.Properties", 120 "java.lang.String" 121 }; 122 123 130 MBeanUtil.invoke( 131 objectName, 132 "createMessageSecurityProvider", 133 params, 134 types); 135 } catch (Exception ex) { 136 throw new FrameworkException( 137 "Error while calling createMessageSecurityProvider() on MBean '"+objectName+ 138 "'!", ex, handlerCtx.getViewDescriptor(), 139 handlerCtx.getView()); 140 } 141 } 142 143 144 private String getAttrValue(AttributeList attrList, String attrName){ 145 if (attrList == null) 146 return null; 147 for (int i=0; i < attrList.size(); i++) { 148 Attribute attr = (Attribute ) attrList.get(i); 149 String name = attr.getName(); 150 if(attrName.equals(name)) 151 return attr.getValue().toString(); 152 } 153 return null; 154 } 155 156 157 163 public void saveRequestAndResponsePolicy(RequestContext reqCtx, HandlerContext handlerCtx) { 164 String objectName = (String )handlerCtx.getInputValue("objectName"); 165 AttributeList requestAttr = (AttributeList )handlerCtx.getInputValue("requestAttr"); 166 AttributeList responseAttr = (AttributeList )handlerCtx.getInputValue("responseAttr"); 167 boolean requestExist = ((Boolean )handlerCtx.getInputValue("requestExist")).booleanValue(); 168 boolean responseExist = ((Boolean )handlerCtx.getInputValue("responseExist")).booleanValue(); 169 170 if (objectName == null) { 171 throw new IllegalArgumentException ( 172 "The parameter map did not contain objectName"); 173 } 174 try { 175 savePolicy(objectName, responseAttr, responseExist, "removeResponsePolicy", "createResponsePolicy"); 176 savePolicy(objectName, requestAttr, requestExist, "removeRequestPolicy", "createRequestPolicy"); 177 }catch (Exception ex) { 178 throw new FrameworkException( 179 "Error while calling saveRequestAndResponsePolicy() on MBean '"+objectName+ 180 "'!", ex, handlerCtx.getViewDescriptor(), 181 handlerCtx.getView()); 182 } 183 } 184 185 public Boolean testNewButtonAllowed(RequestContext reqCtx, HandlerContext handlerCtx) { 186 Object value = handlerCtx.getInputValue("value"); 187 if (value == null) 188 return TRUE; 189 if (value instanceof Object []){ 190 if (((Object [])value).length < 2) 191 return TRUE; 192 } 193 return FALSE; 196 } 197 198 199 public void popularMsgLayerAllowed(RequestContext reqCtx, HandlerContext handlerCtx) { 200 SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView(); 202 DescriptorContainerView parent = (DescriptorContainerView) dropDownChild.getParent(); 204 205 ViewDescriptor vd = parent.getViewDescriptor(); 207 ViewDescriptor cvd = vd.getChildDescriptor(dropDownChild.getName()); 208 209 String configName = (String ) handlerCtx.getInputValue("configName"); 210 Map cmap = (Map ) AMXUtil.getDomainConfig().getConfigConfigMap(); 211 SecurityServiceConfig ssc = ((ConfigConfig) cmap.get(configName)).getSecurityServiceConfig(); 212 Map msgSCMap = ssc.getMessageSecurityConfigMap(); 213 boolean hasSOAP = false; 214 boolean hasHttpServlet = false; 215 int count = 2; 216 217 if (msgSCMap != null ){ 218 if (msgSCMap.get("SOAP") != null){ 219 hasSOAP=true; 220 count--; 221 } 222 if (msgSCMap.get("HttpServlet") != null){ 223 hasHttpServlet=true; 224 count--; 225 } 226 } 227 String [] options = null; 228 229 if (count == 0) return; 231 if (count == 2){ 232 options = new String [] {"SOAP", "HttpServlet"}; 233 }else 234 if (count == 1){ 235 if (hasSOAP) 236 options = new String [] { "HttpServlet"}; 237 else 238 options = new String [] {"SOAP"}; 239 240 } 241 OptionList optionList = new OptionList(options, options); 242 dropDownChild.setOptions(optionList); 243 } 244 245 246 private void savePolicy(String objectName, AttributeList attrs, boolean exist, String removeMethod, String createMethod) 247 { 248 boolean hasValue = attrHasValue(attrs); 249 if (hasValue){ 250 if (exist){ 251 MBeanUtil.invoke(objectName, removeMethod, null, null); 252 } 253 Object [] params = new Object [] {attrs}; 254 String [] types = new String [] {"javax.management.AttributeList" }; 255 MBeanUtil.invoke( objectName, createMethod, params, types); 256 return; 257 }else{ 258 if(exist){ 259 MBeanUtil.invoke(objectName, removeMethod, null, null); 260 } 261 } 262 } 263 264 private boolean attrHasValue(AttributeList attrList){ 265 for (int i=0; i < attrList.size(); i++) { 266 Attribute attr = (Attribute ) attrList.get(i); 267 if (hasValue(attr.getValue().toString())) 268 return true; 269 } 270 return false; 271 } 272 273 private boolean hasValue(String val){ 274 return (val != null) && !"".equals(val); 275 } 276 277 280 public static final Boolean FALSE = new Boolean (false); 281 282 285 public static final Boolean TRUE = new Boolean (true); 286 } 287 | Popular Tags |