1 23 24 25 package com.sun.enterprise.deployment.node.runtime.application; 26 27 import com.sun.enterprise.deployment.Application; 28 import com.sun.enterprise.deployment.ApplicationClientDescriptor; 29 import com.sun.enterprise.deployment.Descriptor; 30 import com.sun.enterprise.deployment.Group; 31 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapper; 32 import com.sun.enterprise.deployment.io.DeploymentDescriptorFile; 33 import com.sun.enterprise.deployment.node.runtime.common.SecurityRoleMappingNode; 34 import com.sun.enterprise.deployment.node.runtime.RuntimeBundleNode; 35 import com.sun.enterprise.deployment.node.XMLElement; 36 import com.sun.enterprise.deployment.node.XMLNode; 37 import com.sun.enterprise.deployment.Role; 38 import com.sun.enterprise.deployment.runtime.common.PrincipalNameDescriptor; 39 import com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping; 40 import com.sun.enterprise.deployment.util.ModuleDescriptor; 41 import com.sun.enterprise.deployment.xml.DTDRegistry; 42 import com.sun.enterprise.deployment.xml.RuntimeTagNames; 43 import java.util.Iterator ; 44 import java.util.List ; 45 import java.util.Map ; 46 import java.util.Vector ; 47 import javax.enterprise.deploy.shared.ModuleType ; 48 import org.w3c.dom.Element ; 49 import org.w3c.dom.Node ; 50 51 61 public class ApplicationRuntimeNode extends RuntimeBundleNode { 62 63 private Application descriptor=null; 64 private String currentWebUri=null; 65 66 public ApplicationRuntimeNode(Application descriptor) { 67 super(descriptor); 68 this.descriptor=descriptor; 69 } 70 71 74 protected void Init() { 75 super.Init(); 76 registerElementHandler(new XMLElement(RuntimeTagNames.SECURITY_ROLE_MAPPING), 77 SecurityRoleMappingNode.class); 78 } 79 80 86 public static String registerBundle(Map publicIDToDTD) { 87 publicIDToDTD.put(DTDRegistry.SUN_APPLICATION_130_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_130_DTD_SYSTEM_ID); 88 publicIDToDTD.put(DTDRegistry.SUN_APPLICATION_140_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_140_DTD_SYSTEM_ID); 89 publicIDToDTD.put(DTDRegistry.SUN_APPLICATION_141_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_141_DTD_SYSTEM_ID); 90 publicIDToDTD.put(DTDRegistry.SUN_APPLICATION_500_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_500_DTD_SYSTEM_ID); 91 if (!restrictDTDDeclarations()) { 92 publicIDToDTD.put(DTDRegistry.SUN_APPLICATION_140beta_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_140beta_DTD_SYSTEM_ID); 93 } 94 return RuntimeTagNames.S1AS_APPLICATION_RUNTIME_TAG; 95 } 96 97 100 protected XMLElement getXMLRootTag() { 101 return new XMLElement(RuntimeTagNames.S1AS_APPLICATION_RUNTIME_TAG); 102 } 103 104 107 public String getDocType() { 108 return DTDRegistry.SUN_APPLICATION_500_DTD_PUBLIC_ID; 109 } 110 111 114 public String getSystemID() { 115 return DTDRegistry.SUN_APPLICATION_500_DTD_SYSTEM_ID; 116 } 117 118 121 public List <String > getSystemIDs() { 122 return null; 123 } 124 125 131 protected Map getDispatchTable() { 132 Map table = super.getDispatchTable(); 133 table.put(RuntimeTagNames.REALM, "setRealm"); 134 return table; 135 } 136 137 143 public void setElementValue(XMLElement element, String value) { 144 if (element.getQName().equals(RuntimeTagNames.PASS_BY_REFERENCE)) { 145 descriptor.setPassByReference("true".equalsIgnoreCase(value)); 146 } else 147 if (element.getQName().equals(RuntimeTagNames.UNIQUE_ID)) { 148 descriptor.setUniqueId(Long.parseLong(value)); 149 } else 150 if (element.getQName().equals(RuntimeTagNames.WEB_URI)) { 151 currentWebUri=value; 152 } else 153 if (element.getQName().equals(RuntimeTagNames.CONTEXT_ROOT)) { 154 if (currentWebUri!=null) { 155 ModuleDescriptor md = descriptor.getModuleDescriptorByUri(currentWebUri); 156 if (md==null) { 157 throw new RuntimeException ("No bundle in application with uri " + currentWebUri); 158 } 159 currentWebUri=null; 160 if (md.getModuleType().equals(ModuleType.WAR)) { 161 md.setContextRoot(value); 162 } else { 163 throw new RuntimeException (currentWebUri + " uri does not point to a web bundle"); 164 } 165 } else { 166 throw new RuntimeException ("No uri provided for this context-root " + value); 167 } 168 } else super.setElementValue(element, value); 169 } 170 171 177 public void addDescriptor(Object newDescriptor) { 178 if (newDescriptor instanceof SecurityRoleMapping) { 179 SecurityRoleMapping roleMap = (SecurityRoleMapping)newDescriptor; 180 descriptor.addSecurityRoleMapping(roleMap); 181 if (descriptor!=null && !descriptor.isVirtual()) { 182 Role role = new Role(roleMap.getRoleName()); 183 SecurityRoleMapper rm = descriptor.getRoleMapper(); 184 if (rm != null) { 185 List <PrincipalNameDescriptor> principals = roleMap.getPrincipalNames(); 186 for (int i = 0; i < principals.size(); i++) { 187 rm.assignRole(principals.get(i).getPrincipal(), role); 188 } 189 List <String > groups = roleMap.getGroupNames(); 190 for (int i = 0; i < groups.size(); i++) { 191 rm.assignRole(new Group(groups.get(i)), role); 192 } 193 } 194 } 195 } 196 } 197 198 199 206 public Node writeDescriptor(Node parent, String nodeName, Descriptor descriptor) { 207 if (! (descriptor instanceof Application)) { 208 throw new IllegalArgumentException (getClass() + " cannot handles descriptors of type " + descriptor.getClass()); 209 } 210 Application application = (Application) descriptor; 211 Node appNode = super.writeDescriptor(parent, nodeName, descriptor); 212 213 for (Iterator modules=application.getModules();modules.hasNext();) { 215 ModuleDescriptor module = (ModuleDescriptor) modules.next(); 216 if (module.getModuleType().equals(ModuleType.WAR)) { 217 Node web = appendChild(appNode, RuntimeTagNames.WEB); 218 appendTextChild(web, RuntimeTagNames.WEB_URI, module.getArchiveUri()); 219 appendTextChild(web, RuntimeTagNames.CONTEXT_ROOT, module.getContextRoot()); 220 } 221 } 222 223 if (application.isPassByReferenceDefined()) { 225 appendTextChild(appNode, RuntimeTagNames.PASS_BY_REFERENCE, String.valueOf(application.getPassByReference())); 226 } 227 228 appendTextChild(appNode, RuntimeTagNames.UNIQUE_ID, String.valueOf(application.getUniqueId())); 230 231 List <SecurityRoleMapping> roleMappings = application.getSecurityRoleMappings(); 233 for (int i = 0; i < roleMappings.size(); i++) { 234 SecurityRoleMappingNode srmn = new SecurityRoleMappingNode(); 235 srmn.writeDescriptor(appNode, RuntimeTagNames.SECURITY_ROLE_MAPPING, roleMappings.get(i)); 236 } 237 238 appendTextChild(appNode, RuntimeTagNames.REALM, application.getRealm()); 240 241 return appNode; 242 } 243 } 244 | Popular Tags |