earContext.setSecurityConfiguration(securityConfiguration);
}
}
public void addGBeans(EARContext earContext, Module module, ClassLoader cl, Collection repository) throws DeploymentException {
EARContext moduleContext = module.getEarContext();
ClassLoader moduleClassLoader = moduleContext.getClassLoader();
AbstractName moduleName = moduleContext.getModuleName();
WebModule webModule = (WebModule) module;
WebAppType webApp = (WebAppType) webModule.getSpecDD();
TomcatWebAppType tomcatWebApp = (TomcatWebAppType) webModule.getVendorDD();
GbeanType[] gbeans = tomcatWebApp.getGbeanArray();
ServiceConfigBuilder.addGBeans(gbeans, moduleClassLoader, moduleName, moduleContext);
UserTransaction userTransaction = new OnlineUserTransaction();
//this may add to the web classpath with enhanced classes.
//N.B. we use the ear context which has all the gbeans we could possibly be looking up from this ear.
Map compContext = buildComponentContext(earContext, webModule, webApp, tomcatWebApp, userTransaction, moduleClassLoader);
GBeanData webModuleData = new GBeanData(moduleName, TomcatWebAppContext.GBEAN_INFO);
try {
webModuleData.setReferencePattern("J2EEServer", moduleContext.getServerName());
if (!module.isStandAlone()) {
webModuleData.setReferencePattern("J2EEApplication", earContext.getModuleName());
}
webModuleData.setAttribute("deploymentDescriptor", module.getOriginalSpecDD());
Set securityRoles = collectRoleNames(webApp);
Map rolePermissions = new HashMap();
webModuleData.setAttribute("contextPath", webModule.getContextRoot());
//Add dependencies on managed connection factories and ejbs in this app
//This is overkill, but allows for people not using java:comp context (even though we don't support it)
//and sidesteps the problem of circular references between ejbs.
Set dependencies = findGBeanDependencies(earContext);
webModuleData.addDependencies(dependencies);
webModuleData.setAttribute("componentContext", compContext);
webModuleData.setAttribute("userTransaction", userTransaction);
// unsharableResources, applicationManagedSecurityResources
GBeanResourceEnvironmentBuilder rebuilder = new GBeanResourceEnvironmentBuilder(webModuleData);
//N.B. use earContext not moduleContext
ENCConfigBuilder.setResourceEnvironment(rebuilder, webApp.getResourceRefArray(), tomcatWebApp.getResourceRefArray());
webModuleData.setReferencePattern("TransactionContextManager", earContext.getTransactionContextManagerObjectName());
webModuleData.setReferencePattern("TrackedConnectionAssociator", earContext.getConnectionTrackerObjectName());
if (tomcatWebApp.isSetWebContainer()) {
AbstractNameQuery webContainerName = ENCConfigBuilder.getGBeanQuery(NameFactory.GERONIMO_SERVICE, tomcatWebApp.getWebContainer());
webModuleData.setReferencePattern("Container", webContainerName);
} else {
webModuleData.setReferencePattern("Container", tomcatContainerName);
}
// Process the Tomcat container-config elements
if (tomcatWebApp.isSetHost()) {
String virtualServer = tomcatWebApp.getHost().trim();
webModuleData.setAttribute("virtualServer", virtualServer);
}
if (tomcatWebApp.isSetCrossContext()) {
webModuleData.setAttribute("crossContext", Boolean.TRUE);
}
if (tomcatWebApp.isSetDisableCookies()) {
webModuleData.setAttribute("disableCookies", Boolean.TRUE);
}
if (tomcatWebApp.isSetTomcatRealm()) {
String tomcatRealm = tomcatWebApp.getTomcatRealm().trim();
AbstractName realmName = earContext.getNaming().createChildName(moduleName, tomcatRealm, RealmGBean.GBEAN_INFO.getJ2eeType());
webModuleData.setReferencePattern("TomcatRealm", realmName);
}
if (tomcatWebApp.isSetValveChain()) {
String valveChain = tomcatWebApp.getValveChain().trim();
AbstractName valveName = earContext.getNaming().createChildName(moduleName, valveChain, ValveGBean.J2EE_TYPE);
webModuleData.setReferencePattern("TomcatValveChain", valveName);
}
if (tomcatWebApp.isSetCluster()) {
String cluster = tomcatWebApp.getCluster().trim();
AbstractName clusterName =earContext.getNaming().createChildName(moduleName, cluster, CatalinaClusterGBean.J2EE_TYPE);
webModuleData.setReferencePattern("Cluster", clusterName);
}
if (tomcatWebApp.isSetManager()) {
String manager = tomcatWebApp.getManager().trim();
AbstractName managerName = earContext.getNaming().createChildName(moduleName, manager, ManagerGBean.J2EE_TYPE);
webModuleData.setReferencePattern("Manager", managerName);
}
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 +" in web app "+module.getName());
}
WebServiceContainer wsContainer = configurePOJO(webModule.getModuleFile(), portInfo, servletClassName, moduleClassLoader);
webServices.put(servletName, wsContainer);
}
}
}
// JACC v1.0 secion B.19
addUnmappedJSPPermissions(securityRoles, rolePermissions);
webModuleData.setAttribute("webServices", webServices);
if (tomcatWebApp.isSetSecurityRealmName()) {
if (earContext.getSecurityConfiguration() == null) {
throw new DeploymentException("You have specified a <security-realm-name> for the webapp " + moduleName + " but no <security> configuration (role mapping) is supplied in the Geronimo plan for the web application (or the Geronimo plan for the EAR if the web app is in an EAR)");
}
SecurityHolder securityHolder = new SecurityHolder();
securityHolder.setSecurityRealm(tomcatWebApp.getSecurityRealmName().trim());
/**
* TODO - go back to commented version when possible.
*/
String policyContextID = moduleName.toString().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);
DefaultPrincipal defaultPrincipal = earContext.getSecurityConfiguration().getDefaultPrincipal();
securityHolder.setDefaultPrincipal(defaultPrincipal);
if (defaultPrincipal != null) {
securityHolder.setSecurity(true);
}
webModuleData.setAttribute("securityHolder", securityHolder);
webModuleData.setReferencePattern("RoleDesignateSource", earContext.getJaccManagerName());
}
moduleContext.addGBean(webModuleData);
if (!module.isStandAlone()) {
ConfigurationData moduleConfigurationData = moduleContext.getConfigurationData();
earContext.addChildConfiguration(module.getTargetPath(), moduleConfigurationData);
}
} catch (DeploymentException de) {
throw de;
} catch (Exception e) {