J2eeContext earJ2eeContext = earContext.getJ2eeContext();
J2eeContext moduleJ2eeContext = J2eeContextImpl.newModuleContextFromApplication(earJ2eeContext, NameFactory.WEB_MODULE, module.getName());
WebModule webModule = (WebModule) module;
WebAppType webApp = (WebAppType) webModule.getSpecDD();
GerWebAppType tomcatWebApp = (GerWebAppType) webModule.getVendorDD();
boolean contextPriorityClassLoader = false;
if (tomcatWebApp != null) {
contextPriorityClassLoader = Boolean.valueOf(tomcatWebApp.getContextPriorityClassloader()).booleanValue();
}
// construct the webClassLoader
ClassLoader webClassLoader = getWebClassLoader(earContext, webModule, cl, contextPriorityClassLoader);
if (tomcatWebApp != null) {
GbeanType[] gbeans = tomcatWebApp.getGbeanArray();
ServiceConfigBuilder.addGBeans(gbeans, webClassLoader, moduleJ2eeContext, earContext);
}
ObjectName webModuleName = null;
try {
webModuleName = NameFactory.getModuleName(null, null, null, null, null, moduleJ2eeContext);
} catch (MalformedObjectNameException e) {
throw new DeploymentException("Could not construct module name", e);
}
UserTransaction userTransaction = new OnlineUserTransaction();
//this may add to the web classpath with enhanced classes.
Map compContext = buildComponentContext(earContext, webModule, webApp, tomcatWebApp, userTransaction, webClassLoader);
GBeanData webModuleData = new GBeanData(webModuleName, TomcatWebAppContext.GBEAN_INFO);
try {
webModuleData.setReferencePattern("J2EEServer", earContext.getServerObjectName());
if (!earContext.getJ2EEApplicationName().equals("null")) {
webModuleData.setReferencePattern("J2EEApplication", earContext.getApplicationObjectName());
}
webModuleData.setAttribute("deploymentDescriptor", module.getOriginalSpecDD());
Set securityRoles = collectRoleNames(webApp);
Map rolePermissions = new HashMap();
URI baseUri = earContext.getTargetFile(URI.create(webModule.getTargetPath() + "/")).toURI();
webModuleData.setAttribute("webAppRoot", baseUri);
webModuleData.setAttribute("path", webModule.getContextRoot());
webModuleData.setAttribute("componentContext", compContext);
webModuleData.setAttribute("userTransaction", userTransaction);
//classpath may have been augmented with enhanced classes
webModuleData.setAttribute("webClassPath", getFinalWebClasspath(webModule));
// unsharableResources, applicationManagedSecurityResources
GBeanResourceEnvironmentBuilder rebuilder = new GBeanResourceEnvironmentBuilder(webModuleData);
ENCConfigBuilder.setResourceEnvironment(earContext, webModule.getModuleURI(), rebuilder, webApp.getResourceRefArray(), tomcatWebApp.getResourceRefArray());
webModuleData.setAttribute("contextPriorityClassLoader", Boolean.valueOf(contextPriorityClassLoader));
webModuleData.setReferencePattern("transactionContextManager", earContext.getTransactionContextManagerObjectName());
webModuleData.setReferencePattern("trackedConnectionAssociator", earContext.getConnectionTrackerObjectName());
webModuleData.setReferencePattern("Container", tomcatContainerObjectName);
String virtualServer = null;
// Process the Tomcat container-config elements
if (tomcatWebApp != null && tomcatWebApp.sizeOfContainerConfigArray() > 0) {
Map values = new HashMap();
GerContainerConfigType[] configs = tomcatWebApp.getContainerConfigArray();
for (int i = 0; i < configs.length; i++) {
GerContainerConfigType config = configs[i];
if(config.getContainer().intValue() != GerWebContainerType.INT_TOMCAT) {
continue;
}
GerConfigParamType[] params = config.getConfigParamArray();
for (int j = 0; j < params.length; j++) {
GerConfigParamType param = params[j];
values.put(param.getName(), param.getStringValue());
}
}
//Is there a Tomcat virtual server declaration?
virtualServer = (String) values.remove("VirtualServer");
//Is there a Tomcat realm declaration?
String tomcatRealm = (String) values.remove("TomcatRealm");
if (tomcatRealm != null) {
ObjectName realmName = NameFactory.getComponentName(null, null, null, null, tomcatRealm.trim(), RealmGBean.GBEAN_INFO.getJ2eeType(), moduleJ2eeContext);
webModuleData.setReferencePattern("TomcatRealm", realmName);
}
//Is there a Tomcat Valve Chain declaration?
String tomcatValveChain = (String) values.remove("TomcatValveChain");
if (tomcatValveChain != null) {
ObjectName valveName = NameFactory.getComponentName(null, null, null, null, tomcatValveChain.trim(), ValveGBean.J2EE_TYPE, moduleJ2eeContext);
//NameFactory.getComponentName(null, null, null, null, tomcatValveChain.trim(), ValveGbean., moduleJ2eeContext);
webModuleData.setReferencePattern("TomcatValveChain", valveName);
}
// Are there any leftover values? If so, that's a problem.
if(values.size() > 0) {
StringBuffer msg = new StringBuffer();
msg.append("Unexpected container-config/config-params found for Tomcat in web app deployment plan (");
boolean first = true;
for (Iterator it = values.keySet().iterator(); it.hasNext();) {
String value = (String) it.next();
if(!first) {
msg.append(",");
}
msg.append(value);
}
msg.append(")");
throw new DeploymentException(msg.toString());
}
}
Map portMap = webModule.getPortMap();
//Handle the role permissions and webservices on the servlets.
ServletType[] servletTypes = webApp.getServletArray();
Map webServices = new HashMap();
for (int i = 0; i < servletTypes.length; i++) {
ServletType servletType = servletTypes[i];
//Handle the Role Ref Permissions
processRoleRefPermissions(servletType, securityRoles, rolePermissions);
//Do we have webservices configured?
if (portMap != null) {
//Check if the Servlet is a Webservice
String servletName = servletType.getServletName().getStringValue().trim();
if (portMap.containsKey(servletName)) {
//Yes, this servlet is a web service so let the web service builder
// deal with configuring the web service stack
String servletClassName = servletType.getServletClass().getStringValue().trim();
Object portInfo = portMap.get(servletName);
if (portInfo == null) {
throw new DeploymentException("No web service deployment info for servlet name " + servletName);
}
StoredObject wsContainer = configurePOJO(webModule.getModuleFile(), portInfo, servletClassName, webClassLoader);
webServices.put(servletName, wsContainer);
}
}
}
webModuleData.setAttribute("webServices", webServices);
if (tomcatWebApp.isSetSecurityRealmName()) {
SecurityHolder securityHolder = new SecurityHolder();
String securityRealmName = tomcatWebApp.getSecurityRealmName().trim();
/**
* TODO - go back to commented version when possible.
*/
String policyContextID = webModuleName.getCanonicalName().replaceAll("[, :]", "_");
securityHolder.setPolicyContextID(policyContextID);
ComponentPermissions componentPermissions = buildSpecSecurityConfig(webApp, securityRoles, rolePermissions);
securityHolder.setExcluded(componentPermissions.getExcludedPermissions());
PermissionCollection checkedPermissions = new Permissions();
for (Iterator iterator = rolePermissions.values().iterator(); iterator.hasNext();) {
PermissionCollection permissionsForRole = (PermissionCollection) iterator.next();
for (Enumeration iterator2 = permissionsForRole.elements(); iterator2.hasMoreElements();) {
Permission permission = (Permission) iterator2.nextElement();
checkedPermissions.add(permission);
}
}
securityHolder.setChecked(checkedPermissions);
earContext.addSecurityContext(policyContextID, componentPermissions);
if (tomcatWebApp.isSetSecurity()) {
SecurityConfiguration securityConfiguration = SecurityBuilder.buildSecurityConfiguration(tomcatWebApp.getSecurity());
earContext.setSecurityConfiguration(securityConfiguration);
}
DefaultPrincipal defaultPrincipal = earContext.getSecurityConfiguration().getDefaultPrincipal();
securityHolder.setDefaultPrincipal(defaultPrincipal);