1 23 24 29 30 package com.sun.enterprise.deployment.backend; 31 32 import com.sun.ejb.codegen.IASEJBCTimes; 33 import com.sun.enterprise.config.ConfigException; 34 import com.sun.enterprise.config.serverbeans.WebModule; 35 import com.sun.enterprise.deployment.Application; 36 import com.sun.enterprise.deployment.archivist.Archivist; 37 import com.sun.enterprise.deployment.autodeploy.AutoDeployConstants; 38 import com.sun.enterprise.deployment.BundleDescriptor; 39 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 40 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapper; 41 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactory; 42 import com.sun.enterprise.deployment.phasing.DeploymentServiceUtils; 43 import com.sun.enterprise.deployment.RootDeploymentDescriptor; 44 import com.sun.enterprise.deployment.WebBundleDescriptor; 45 import com.sun.enterprise.deployment.WebService; 46 import com.sun.enterprise.deployment.WebServicesDescriptor; 47 import com.sun.enterprise.instance.BaseManager; 48 import com.sun.enterprise.instance.InstanceEnvironment; 49 import com.sun.enterprise.instance.ModuleEnvironment; 50 import com.sun.enterprise.instance.WebModulesManager; 51 import com.sun.enterprise.loader.EJBClassPathUtils; 52 import com.sun.enterprise.security.SecurityUtil; 53 import com.sun.enterprise.security.util.IASSecurityException; 54 import com.sun.enterprise.util.i18n.StringManager; 55 import com.sun.enterprise.util.io.FileUtils; 56 import com.sun.enterprise.util.StringUtils; 57 import com.sun.enterprise.util.zip.ZipFileException; 58 import com.sun.enterprise.util.zip.ZipItem; 59 import com.sun.web.security.*; 60 import java.io.File ; 61 import java.io.IOException ; 62 import java.util.*; 63 import java.util.logging.Level ; 64 65 72 public class WebModuleDeployer extends ModuleDeployer 73 { 74 WebModuleDeployer(DeploymentRequest r) throws IASDeploymentException 75 { 76 super(r); 77 } 78 79 81 protected BaseManager createConfigManager(InstanceEnvironment ienv, ModuleEnvironment menv) 82 throws IASDeploymentException, ConfigException 83 { 84 webModulesMgr = new WebModulesManager(ienv); 85 return webModulesMgr; 86 } 87 88 90 protected void preDeploy() throws IASDeploymentException 91 { 92 try 93 { 94 assert moduleDir != null; 95 assert StringUtils.ok(moduleName); 96 97 if(isRegistered()) { 98 String msg = localStrings.getString( 99 "enterprise.deployment.backend.deploy_error_module_exists" ); 100 throw new IASDeploymentException( msg ); 101 } 102 103 liquidateModuleDirAndStubsDirIfTheyHappenToExist(); 107 108 if(request.isArchive()) 109 { 110 if (request.getFileSource().getFile().getName().endsWith(".class")) { 112 File subDir = new File (moduleDir, "WEB-INF"); 114 subDir = new File (subDir, "classes"); 115 copyAutodeployedClassFile(request.getFileSource().getFile(), subDir); 116 } else { 117 118 129 J2EEModuleExploder.explodeJar(request.getFileSource().getFile(), moduleDir); 130 } 131 } 132 133 xmlDir.mkdirs(); 134 stubsDir.mkdirs(); 135 } 136 catch(Exception e) 137 { 138 throw new IASDeploymentException(e); 139 } 140 } 141 142 144 protected void deploy() throws IASDeploymentException 145 { 146 String mLocation; 148 try { 149 mLocation = moduleDir.getCanonicalPath(); 150 } catch(java.io.IOException e) { 151 throw new IASDeploymentException(e); 152 } 153 154 Application app = loadDescriptors(); 156 request.getDescriptor().setGeneratedXMLDirectory(xmlDir.getAbsolutePath()); 158 159 WebBundleDescriptor bundleDesc = (WebBundleDescriptor) app.getStandaloneBundleDescriptor(); 160 161 169 if (request.getContextRoot() == null || 170 request.getContextRoot().trim().equals("")) { 171 if (bundleDesc.getContextRoot() != null && 172 !bundleDesc.getContextRoot().trim().equals("")) { 173 request.setContextRoot(bundleDesc.getContextRoot()); 174 } else { 175 request.setContextRoot(request.getDefaultContextRoot()); 176 } 177 } 178 179 ZipItem[] clientStubs = runEJBC(); 180 181 try 182 { 183 197 if(request.getPrecompileJSP()) 199 { 200 long time = System.currentTimeMillis(); 201 JSPCompiler.compile( 202 moduleDir, 203 jspDir, 204 bundleDesc, 205 request.getCompleteClasspath()); 206 addJSPCTime(System.currentTimeMillis() - time); 207 } 208 runVerifier(); 210 } 211 catch(IASDeploymentException de) 212 { 213 throw de; 214 } 215 catch(Exception e) 216 { 217 throw new IASDeploymentException(e); 218 } 219 } 220 221 223 protected void preRedeploy() throws IASDeploymentException, ConfigException 224 { 225 assert moduleDir != null; 226 assert StringUtils.ok(moduleName); 227 228 setOldDirs(); 229 230 if(request.isArchive()) 231 { 232 try 233 { 234 if (request.getFileSource().getFile().getName().endsWith(".class")) { 236 File subDir = new File (moduleDir, "WEB-INF"); 238 subDir = new File (subDir, "classes"); 239 copyAutodeployedClassFile(request.getFileSource().getFile(), subDir); 240 241 } else { 242 243 244 247 J2EEModuleExploder.explodeJar(request.getFileSource().getFile(), moduleDir); 248 } 249 } 250 catch(IOException e) 251 { 252 throw new IASDeploymentException(e.toString(), e); 253 } 254 } 255 256 xmlDir.mkdirs(); 257 stubsDir.mkdirs(); 258 } 259 260 261 protected boolean needsStubs() 262 { 263 return true; 265 } 266 267 269 protected boolean needsJSPs() 270 { 271 return true; 273 } 274 275 276 278 protected void generatePolicy() throws IASDeploymentException 279 { 280 284 try{ 286 if(webModulesMgr == null){ 287 webModulesMgr = 288 (WebModulesManager)createConfigManager(getInstanceEnv(), 289 moduleEnv); 290 } 291 Application app = request.getDescriptor(); 292 WebBundleDescriptor wbd = (WebBundleDescriptor) app.getStandaloneBundleDescriptor(); 293 294 WebSecurityManagerFactory wsmf = null; 296 wsmf = WebSecurityManagerFactory.getInstance(); 297 wsmf.newWebSecurityManager(wbd); 299 if(request.isApplication()){ 303 return; 304 } 305 String name = WebSecurityManager.getContextID(wbd) ; 306 SecurityUtil.generatePolicyFile(name); 307 }catch(IASDeploymentException iasde){ String msg = 310 localStrings.getString("enterprise.deployment.backend.generate_policy_error" ); 311 logger.log(Level.WARNING, msg, iasde); 312 throw iasde; 313 }catch(ConfigException ce){ 314 String msg = 316 localStrings.getString("enterprise.deployment.backend.generate_policy_error" ); 317 logger.log(Level.WARNING, msg, ce); 318 throw new IASDeploymentException(ce.toString()); 319 } catch(IASSecurityException iassec){ 320 String msg = 322 localStrings.getString("enterprise.deployment.backend.generate_policy_error" ); 323 logger.log(Level.WARNING, msg, iassec); 324 throw new IASDeploymentException(msg, iassec); 325 } 326 327 } 328 329 public void removePolicy() throws IASDeploymentException 331 { 332 if (request.isApplication()) { 333 return; 334 } 335 WebSecurityManagerFactory wsmf = WebSecurityManagerFactory.getInstance(); 336 String requestName = request.getName(); 337 String [] name 338 = wsmf.getAndRemoveContextIdForWebAppName(requestName); 339 try { 340 if(name != null){ 341 if(name[0] != null) 342 SecurityUtil.removePolicy(name[0]); 343 } 344 } catch(IASSecurityException ex) { 345 String msg = localStrings.getString( 346 "enterprise.deployment.backend.remove_policy_error",name); 347 logger.log(Level.WARNING, msg, ex); 348 throw new IASDeploymentException(msg, ex); 349 } 350 } 351 352 354 355 private WebModulesManager webModulesMgr = null; 356 private static StringManager localStrings = 357 StringManager.getManager( WebModuleDeployer.class ); 358 } 359 360 | Popular Tags |