1 23 24 29 30 package com.sun.enterprise.deployment.backend; 31 32 import java.io.*; 33 import java.util.List ; 34 import java.util.logging.*; 35 36 import com.sun.ejb.codegen.IASEJBCTimes; 37 import com.sun.enterprise.util.io.FileUtils; 38 import com.sun.enterprise.util.zip.ZipFileException; 39 import com.sun.enterprise.util.zip.ZipItem; 40 import com.sun.enterprise.config.ConfigException; 41 import com.sun.enterprise.instance.BaseManager; 42 import com.sun.enterprise.instance.EjbModulesManager; 43 import com.sun.enterprise.instance.InstanceEnvironment; 44 import com.sun.enterprise.instance.ModuleEnvironment; 45 import com.sun.enterprise.util.diagnostics.Profiler; 46 import com.sun.enterprise.util.i18n.StringManager; 47 import com.sun.enterprise.security.SecurityUtil; 48 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapper; 49 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactory; 50 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactoryMgr; 51 import com.sun.enterprise.deployment.Application; 52 import com.sun.enterprise.deployment.EjbBundleDescriptor; 53 import com.sun.enterprise.deployment.EjbDescriptor; 54 import com.sun.enterprise.deployment.phasing.DeploymentServiceUtils; 55 import com.sun.enterprise.security.util.IASSecurityException; 56 import com.sun.enterprise.security.application.EJBSecurityManager; 57 import com.sun.enterprise.security.factory.EJBSecurityManagerFactory; 58 import com.sun.enterprise.loader.EJBClassPathUtils; 59 60 import com.sun.enterprise.deployment.archivist.Archivist; 62 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 63 import com.sun.enterprise.deployment.interfaces.*; 64 65 66 73 public class EjbModuleDeployer extends ModuleDeployer 74 { 75 EjbModuleDeployer(DeploymentRequest r) throws IASDeploymentException 76 { 77 super(r); 78 } 79 80 82 protected boolean needsStubs() 83 { 84 return true; 85 } 86 87 89 protected BaseManager createConfigManager(InstanceEnvironment ienv, ModuleEnvironment menv) throws IASDeploymentException, ConfigException 90 { 91 manager = new EjbModulesManager(ienv); 92 return manager; 93 } 94 95 97 protected void preDeploy() throws IASDeploymentException 98 { 99 assert stubsDir != null; 100 assert moduleDir != null; 101 assert moduleName != null; 102 103 try 104 { 105 if(isRegistered()) { 106 String msg = localStrings.getString( 107 "enterprise.deployment.backend.deploy_error_module_exists"); 108 throw new IASDeploymentException( msg ); 109 } 110 111 liquidateModuleDirAndStubsDirIfTheyHappenToExist(); 115 116 if(request.isArchive()) { 117 if (request.getFileSource().getFile().getName().endsWith(".class")) { 119 copyAutodeployedClassFile(request.getFileSource().getFile(), moduleDir); 120 } else { 121 J2EEModuleExploder.explodeJar(request.getFileSource().getFile(), moduleDir); 122 } 123 } 124 125 xmlDir.mkdirs(); 126 stubsDir.mkdirs(); 127 } 128 catch(Exception e) 129 { 130 throw new IASDeploymentException(e.toString(), e); 131 } 132 } 133 134 136 protected void deploy() throws IASDeploymentException, ConfigException 137 { 138 loadDescriptors(); 139 runVerifier(); 140 request.getDescriptor().setGeneratedXMLDirectory(xmlDir.getAbsolutePath()); 142 ZipItem[] clientStubs = runEJBC(); 143 createClientJar(clientStubs); 144 } 145 146 148 protected void preRedeploy() throws IASDeploymentException, ConfigException 149 { 150 assert stubsDir != null; 151 assert moduleDir != null; 152 assert moduleName != null; 153 154 setOldDirs(); 155 156 157 try { 158 if(request.isArchive()) { 159 if (request.getFileSource().getFile().getName().endsWith(".class")) { 161 copyAutodeployedClassFile(request.getFileSource().getFile(), moduleDir); 162 } else { 163 J2EEModuleExploder.explodeJar(request.getFileSource().getFile(), moduleDir); 164 } 165 } 166 } catch(IOException e) { 167 throw new IASDeploymentException(e.toString(), e); 168 } 169 xmlDir.mkdirs(); 170 stubsDir.mkdirs(); 171 } 172 173 175 protected void register() throws IASDeploymentException, ConfigException 176 { 177 super.register(); 178 setShared(request.isSharedModule()); 179 } 180 181 protected void generatePolicy() throws IASDeploymentException 183 { 184 try 187 { 188 if(request.isApplication()) 189 { 190 return; 191 } 192 else 193 { 194 Application app = request.getDescriptor(); 195 EjbBundleDescriptor ejbBundleDesc = 196 (EjbBundleDescriptor) 197 app.getStandaloneBundleDescriptor(); 198 String name = EJBSecurityManager.getContextID(ejbBundleDesc); 200 SecurityUtil.generatePolicyFile(name); 201 EJBSecurityManagerFactory ejbsmf = 202 (EJBSecurityManagerFactory)EJBSecurityManagerFactory.getInstance(); 203 ejbsmf.createSecurityManager( 204 (EjbDescriptor)ejbBundleDesc.getEjbs().iterator().next()); 205 } 206 } 207 catch (IASSecurityException se) 208 { 209 String msg = 210 localStrings.getString("enterprise.deployment.backend.generate_policy_error" ); 211 212 logger.log(Level.WARNING, msg, se); 213 throw new IASDeploymentException(msg, se); 214 } 215 } 216 217 DDGenerator ddGenerator = null; 219 220 222 public void removePolicy() throws IASDeploymentException 223 { 224 if (request.isApplication()) 225 { 226 return; 227 } 228 229 String requestName = request.getName(); 230 EJBSecurityManagerFactory ejbsmf = 231 (EJBSecurityManagerFactory)EJBSecurityManagerFactory.getInstance(); 232 String [] names = 233 ejbsmf.getAndRemoveContextIdForEjbAppName(requestName); 234 String name = null; 235 try 236 { 237 if (names != null && names.length > 0 && 238 names[0] != null) { 239 name = names[0]; 240 SecurityUtil.removePolicy(name); 241 } 242 } 243 catch(IASSecurityException ex) 244 { 245 String msg = localStrings.getString( 246 "enterprise.deployment.backend.remove_policy_error",name); 247 logger.log(Level.WARNING, msg, ex); 248 throw new IASDeploymentException(msg, ex); 249 } 250 } 251 252 254 private EjbModulesManager manager = null; 255 private static StringManager localStrings = StringManager.getManager( EjbModuleDeployer.class ); 256 } 257 258 | Popular Tags |