1 23 24 package com.sun.enterprise.deployment.node.runtime; 25 26 import java.security.Principal ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Map ; 30 import org.w3c.dom.Node ; 31 import org.w3c.dom.Document ; 32 33 import com.sun.enterprise.deployment.Application; 34 import com.sun.enterprise.deployment.Descriptor; 35 import com.sun.enterprise.deployment.EjbBundleDescriptor; 36 import com.sun.enterprise.deployment.EjbDescriptor; 37 import com.sun.enterprise.deployment.Group; 38 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapper; 39 import com.sun.enterprise.deployment.node.runtime.common.SecurityRoleMappingNode; 40 import com.sun.enterprise.deployment.node.XMLElement; 41 import com.sun.enterprise.deployment.RelationshipDescriptor; 42 import com.sun.enterprise.deployment.ResourceReferenceDescriptor; 43 import com.sun.enterprise.deployment.Role; 44 import com.sun.enterprise.deployment.runtime.common.PrincipalNameDescriptor; 45 import com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping; 46 import com.sun.enterprise.deployment.util.DOLUtils; 47 import com.sun.enterprise.deployment.xml.DTDRegistry; 48 import com.sun.enterprise.deployment.xml.RuntimeTagNames; 49 import com.sun.enterprise.deployment.xml.WebServicesTagNames; 50 51 57 public class EjbBundleRuntimeNode extends RuntimeBundleNode { 58 59 EjbBundleDescriptor descriptor=null; 60 61 62 public EjbBundleRuntimeNode(EjbBundleDescriptor descriptor) { 63 super(descriptor); 64 this.descriptor = descriptor; 65 registerElementHandler(new XMLElement(RuntimeTagNames.SECURITY_ROLE_MAPPING), 66 SecurityRoleMappingNode.class); 67 registerElementHandler(new XMLElement(RuntimeTagNames.EJBS), 68 EntrepriseBeansRuntimeNode.class); 69 } 70 71 72 public EjbBundleRuntimeNode() { 73 super(null); 74 } 75 76 79 public String getDocType() { 80 return DTDRegistry.SUN_EJBJAR_300_DTD_PUBLIC_ID; 81 } 82 83 86 public String getSystemID() { 87 return DTDRegistry.SUN_EJBJAR_300_DTD_SYSTEM_ID; 88 } 89 90 93 public List <String > getSystemIDs() { 94 return null; 95 } 96 97 100 protected XMLElement getXMLRootTag() { 101 return new XMLElement(RuntimeTagNames.S1AS_EJB_RUNTIME_TAG); 102 } 103 104 110 public static String registerBundle(Map publicIDToDTD) { 111 publicIDToDTD.put(DTDRegistry.SUN_EJBJAR_200_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_200_DTD_SYSTEM_ID); 112 publicIDToDTD.put(DTDRegistry.SUN_EJBJAR_201_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_201_DTD_SYSTEM_ID); 113 publicIDToDTD.put(DTDRegistry.SUN_EJBJAR_210_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_210_DTD_SYSTEM_ID); 114 publicIDToDTD.put(DTDRegistry.SUN_EJBJAR_211_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_211_DTD_SYSTEM_ID); 115 publicIDToDTD.put(DTDRegistry.SUN_EJBJAR_300_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_300_DTD_SYSTEM_ID); 116 if (!restrictDTDDeclarations()) { 117 publicIDToDTD.put(DTDRegistry.SUN_EJBJAR_210beta_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_210beta_DTD_SYSTEM_ID); 118 } 119 return RuntimeTagNames.S1AS_EJB_RUNTIME_TAG; 120 } 121 122 125 public Object getDescriptor() { 126 return descriptor; 127 } 128 129 135 public void addDescriptor(Object newDescriptor) { 136 if (newDescriptor instanceof SecurityRoleMapping) { 137 SecurityRoleMapping roleMap = (SecurityRoleMapping)newDescriptor; 138 descriptor.addSecurityRoleMapping(roleMap); 139 Application app = descriptor.getApplication(); 140 if (app!=null && app.isVirtual()) { 141 Role role = new Role(roleMap.getRoleName()); 142 SecurityRoleMapper rm = app.getRoleMapper(); 143 if (rm != null) { 144 List <PrincipalNameDescriptor> principals = roleMap.getPrincipalNames(); 145 for (int i = 0; i < principals.size(); i++) { 146 rm.assignRole(principals.get(i).getPrincipal(), role); 147 } 148 List <String > groups = roleMap.getGroupNames(); 149 for (int i = 0; i < groups.size(); i++) { 150 rm.assignRole(new Group(groups.get(i)), role); 151 } 152 } 153 } 154 } 155 } 156 157 164 public Node writeDescriptor(Node parent, Descriptor descriptor) { 165 if (! (descriptor instanceof EjbBundleDescriptor)) { 166 throw new IllegalArgumentException (getClass() + 167 " cannot handles descriptors of type " + descriptor.getClass()); 168 } 169 EjbBundleDescriptor bundleDescriptor = (EjbBundleDescriptor) descriptor; 170 Node ejbs = super.writeDescriptor(parent, descriptor); 171 172 List <SecurityRoleMapping> roleMappings = bundleDescriptor.getSecurityRoleMappings(); 174 for (int i = 0; i < roleMappings.size(); i++) { 175 SecurityRoleMappingNode srmn = new SecurityRoleMappingNode(); 176 srmn.writeDescriptor(ejbs, RuntimeTagNames.SECURITY_ROLE_MAPPING, roleMappings.get(i)); 177 } 178 179 EntrepriseBeansRuntimeNode ejbsNode = new EntrepriseBeansRuntimeNode(); 181 ejbsNode.writeDescriptor(ejbs, RuntimeTagNames.EJBS, bundleDescriptor); 182 return ejbs; 183 } 184 } 185 | Popular Tags |