1 22 package org.jboss.deployment; 23 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.LinkedHashMap ; 27 import java.util.Map ; 28 29 import javax.management.MBeanServer ; 30 import javax.management.ObjectName ; 31 32 import org.jboss.metadata.IconMetaData; 33 import org.jboss.metadata.MetaData; 34 import org.jboss.metadata.SecurityRoleMetaData; 35 import org.jboss.mx.loading.LoaderRepositoryFactory; 36 import org.jboss.mx.util.MBeanServerLocator; 37 import org.w3c.dom.Element ; 38 39 47 public class J2eeApplicationMetaData 48 extends MetaData 49 { 50 52 54 private String displayName; 55 56 private String description; 57 58 private IconMetaData icon = new IconMetaData(); 59 60 private String libDirName = "lib"; 61 62 private String version; 63 64 private LoaderRepositoryFactory.LoaderRepositoryConfig loaderCfg; 65 66 69 private HashMap <String , SecurityRoleMetaData> securityRoles = new HashMap <String , SecurityRoleMetaData>(); 70 73 private String securityDomain; 74 77 private String unauthenticatedPrincipal; 78 79 private Map <String , J2eeModuleMetaData> modules = new LinkedHashMap <String , J2eeModuleMetaData>(); 80 81 82 private String jmxName; 83 84 86 88 public String getVersion() 89 { 90 return version; 91 } 92 public void setVersion(String version) 93 { 94 this.version = version; 95 } 96 97 public String getDisplayName() 98 { 99 return displayName; 100 } 101 public void setDisplayName(String name) 102 { 103 this.displayName = name; 104 } 105 106 public String getDescription() 107 { 108 return description; 109 } 110 public void setDescription(String description) 111 { 112 this.description = description; 113 } 114 115 public String getSmallIcon() 116 { 117 return icon.getSmallIcon(); 118 } 119 120 public String getLargeIcon() 121 { 122 return icon.getLargeIcon(); 123 } 124 125 130 public J2eeModuleMetaData getModule(String path) 131 { 132 J2eeModuleMetaData module = modules.get(path); 133 if( path.startsWith("/") ) 134 { 135 path = path.substring(1); 137 module = modules.get(path); 138 } 139 return module; 140 } 141 145 public Iterator <J2eeModuleMetaData> getModules() 146 { 147 return modules.values().iterator(); 148 } 149 150 public boolean hasModule(String name) 151 { 152 return modules.containsKey(name); 153 } 154 155 public Map <String , SecurityRoleMetaData> getSecurityRoles() 156 { 157 return new HashMap <String , SecurityRoleMetaData>(securityRoles); 158 } 159 public void addSecurityRole(SecurityRoleMetaData role) 160 { 161 securityRoles.put(role.getRoleName(), role); 162 } 163 public SecurityRoleMetaData getSecurityRole(String name) 164 { 165 return securityRoles.get(name); 166 } 167 168 public String getSecurityDomain() 169 { 170 return securityDomain; 171 } 172 public void setSecurityDomain(String domain) 173 { 174 this.securityDomain = domain; 175 } 176 177 public String getUnauthenticatedPrincipal() 178 { 179 return unauthenticatedPrincipal; 180 } 181 public void setUnauthenticatedPrincipal(String principal) 182 { 183 this.unauthenticatedPrincipal = principal; 184 } 185 186 public String getJMXName() 187 { 188 return jmxName; 189 } 190 public void setJMXName(String name) 191 { 192 this.jmxName = name; 193 } 194 195 public String getLibraryDirectory() 196 { 197 return libDirName; 198 } 199 public void setLibraryDirectory(String name) 200 { 201 this.libDirName = name; 202 } 203 204 public LoaderRepositoryFactory.LoaderRepositoryConfig getLoaderCfg() 205 { 206 return loaderCfg; 207 } 208 public void setLoaderCfg(LoaderRepositoryFactory.LoaderRepositoryConfig loaderCfg) 209 { 210 this.loaderCfg = loaderCfg; 211 } 212 216 public void addModule(J2eeModuleMetaData moduleMetaData) 217 { 218 this.modules.put(moduleMetaData.getFileName(), moduleMetaData); 219 } 220 221 227 public void importXml(Element rootElement) throws DeploymentException 228 { 229 String rootTag = rootElement.getOwnerDocument().getDocumentElement().getTagName(); 230 if (rootTag.equals("application")) 231 { 232 importApplicationXml(rootElement); 233 } 234 else if (rootTag.equals("jboss-app")) 235 { 236 importJBossAppXml(rootElement); 237 } 238 else 239 { 240 throw new DeploymentException("Unrecognized root tag: " + rootTag); 241 } 242 } 243 244 protected void importApplicationXml(Element rootElement) throws DeploymentException 245 { 246 version = getElementAttribute(rootElement, "version"); 247 displayName = super.getOptionalChildContent(rootElement, "display-name", ""); 249 250 Element descrElement = getOptionalChild(rootElement, "description"); 251 description = descrElement != null ? getElementContent(descrElement) : ""; 252 253 Element iconElement = getOptionalChild(rootElement, "icon"); 254 if (iconElement != null) 255 { 256 Element element = getOptionalChild(iconElement, "small-icon"); 257 String value = element != null ? getElementContent(element) : ""; 258 icon.setSmallIcon(value); 259 260 element = getOptionalChild(iconElement, "large-icon"); 261 value = element != null ? getElementContent(element) : ""; 262 icon.setLargeIcon(value); 263 } 264 265 libDirName = getOptionalChildContent(rootElement, "library-directory", "lib"); 267 if( libDirName != null && libDirName.length() == 0 ) 268 libDirName = null; 269 270 for (Iterator it = getChildrenByTagName(rootElement, "module"); it.hasNext();) 272 { 273 J2eeModuleMetaData moduleMetaData = new J2eeModuleMetaData(); 274 moduleMetaData.importXml((Element ) it.next()); 275 addModule(moduleMetaData); 276 } 277 } 278 279 protected void importJBossAppXml(Element rootElement) throws DeploymentException 280 { 281 Element securityDomainElement = getOptionalChild(rootElement, "security-domain"); 283 if (securityDomainElement != null) 284 { 285 securityDomain = getElementContent(securityDomainElement); 286 } 287 288 Element unauth = getOptionalChild(rootElement, "unauthenticated-principal"); 290 if (unauth != null) 291 { 292 unauthenticatedPrincipal = getElementContent(unauth); 293 } 294 else 295 { 296 try 297 { 298 MBeanServer server = MBeanServerLocator.locateJBoss(); 299 ObjectName oname = new ObjectName ("jboss.security:service=JaasSecurityManager"); 300 unauthenticatedPrincipal = (String ) server.getAttribute(oname, "DefaultUnauthenticatedPrincipal"); 301 } 302 catch (Exception e) 303 { 304 log.error("Cannot obtain unauthenticated principal"); 305 } 306 } 307 308 Iterator iterator = getChildrenByTagName(rootElement, "security-role"); 310 while (iterator.hasNext()) 311 { 312 Element securityRole = (Element ) iterator.next(); 313 String roleName = getElementContent(getUniqueChild(securityRole, "role-name")); 314 SecurityRoleMetaData srMetaData = new SecurityRoleMetaData(roleName); 315 316 Iterator itPrincipalNames = getChildrenByTagName(securityRole, "principal-name"); 317 while (itPrincipalNames.hasNext()) 318 { 319 String principalName = getElementContent((Element ) itPrincipalNames.next()); 320 srMetaData.addPrincipalName(principalName); 321 } 322 securityRoles.put(roleName, srMetaData); 323 } 324 325 Element jmxNameElement = getOptionalChild(rootElement, "jmx-name"); 327 if (jmxNameElement != null) 328 jmxName = getElementContent(jmxNameElement); 329 330 for (Iterator it = getChildrenByTagName(rootElement, "module"); it.hasNext();) 332 { 333 J2eeModuleMetaData moduleMetaData = new J2eeModuleMetaData(); 334 moduleMetaData.importXml((Element ) it.next()); 335 addModule(moduleMetaData); 336 } 337 } 338 } 339 | Popular Tags |