1 23 24 33 34 package com.sun.enterprise.deployment.backend; 35 36 import java.io.*; 37 import java.util.Properties ; 38 import java.util.Vector ; 39 import java.util.Iterator ; 40 import java.util.ArrayList ; 41 import java.util.List ; 42 import java.util.Set ; 43 import javax.enterprise.deploy.shared.ModuleType ; 44 import java.util.logging.Level ; 45 46 import com.sun.enterprise.instance.ApplicationEnvironment; 47 import com.sun.enterprise.instance.AppsManager; 48 import com.sun.enterprise.instance.BaseManager; 49 import com.sun.enterprise.util.StringUtils; 50 import com.sun.enterprise.util.io.FileUtils; 51 import com.sun.enterprise.config.ConfigException; 52 import com.sun.enterprise.util.i18n.StringManager; 53 import com.sun.enterprise.security.SecurityUtil; 54 import com.sun.enterprise.deployment.Application; 55 import com.sun.enterprise.deployment.EjbBundleDescriptor; 56 import com.sun.enterprise.deployment.archivist.Archivist; 57 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 58 import com.sun.enterprise.deployment.util.ModuleDescriptor; 59 import com.sun.enterprise.deployment.phasing.DeploymentServiceUtils; 60 import com.sun.enterprise.server.Constants; 61 import com.sun.enterprise.security.util.IASSecurityException; 62 import com.sun.enterprise.security.application.EJBSecurityManager; 63 import com.sun.enterprise.security.factory.EJBSecurityManagerFactory; 64 import com.sun.enterprise.loader.EJBClassPathUtils; 65 import com.sun.web.security.WebSecurityManager; 66 import com.sun.enterprise.deployment.WebBundleDescriptor; 67 import com.sun.enterprise.deployment.BundleDescriptor; 68 import com.sun.enterprise.deployment.WebServiceEndpoint; 69 import com.sun.enterprise.deployment.WebServicesDescriptor; 70 import com.sun.enterprise.deployment.WebService; 71 import javax.security.jacc.PolicyConfiguration ; 72 import javax.security.jacc.PolicyConfigurationFactory ; 73 import javax.security.jacc.PolicyContextException ; 74 import com.sun.web.security.WebSecurityManagerFactory; 75 77 78 abstract class AppDeployerBase extends Deployer 79 { 80 AppDeployerBase(DeploymentRequest r) throws IASDeploymentException 81 { 82 super(r); 83 } 84 abstract protected File setAppDir() throws IASDeploymentException; 88 89 93 96 protected void begin() throws IASDeploymentException 97 { 98 super.begin(); 99 100 try 101 { 102 appEnv = request.getAppEnv(); 103 104 if(appEnv == null) { 105 String msg = localStrings.getString( 106 "enterprise.deployment.backend.null_applicationenvironment_object"); 107 throw new IASDeploymentException( msg ); 108 } 109 110 appMgr = new AppsManager(getInstanceEnv()); 111 appName = request.getName(); 112 113 if(!StringUtils.ok(appName)) { 114 String msg = localStrings.getString( 115 "enterprise.deployment.backend.null_appname" ); 116 117 throw new IASDeploymentException( msg ); 118 } 119 120 isReg = DeploymentServiceUtils.isRegistered( 121 getAppName(), request.getType()); 122 if(isReg) { 123 isSystem = isSystem(); 124 } 125 verify(); 126 } 127 catch(IASDeploymentException e) 128 { 129 throw e; 130 } 131 catch(Exception e) 132 { 133 throw new IASDeploymentException(e); 134 } 135 136 } 137 138 140 143 protected void predeploy() throws IASDeploymentException 144 { 145 try 146 { 147 appDir = setAppDir(); 148 request.setDeployedDirectory(appDir); 149 setGeneratedDirs(); 150 } 151 catch(IASDeploymentException e) 152 { 153 throw e; 154 } 155 catch(Exception e) 156 { 157 throw new IASDeploymentException(e); 158 } 159 } 160 161 163 protected final void verify() throws IASDeploymentException 164 { 165 if(!request.isApplication()) { 166 String msg = localStrings.getString( 167 "enterprise.deployment.backend.attempt_to_deploy_non_application"); 168 throw new IASDeploymentException( msg ); 169 } 170 171 if(request.isUnDeploy()) 172 { 173 if(!isReg) { 174 String msg = localStrings.getString( 175 "enterprise.deployment.backend.undeploy_error_application_not_registered"); 176 throw new IASDeploymentException( msg ); 177 }else if(isSystem) 178 { 179 String msg = localStrings.getString( 180 "enterprise.deployment.backend.undeploy_error_application_is_a_system_resource"); 181 throw new IASDeploymentException( msg ); 182 } 183 } 184 185 else if(request.isDeploy()) 186 { 187 if(isReg) 188 { 189 String msg = localStrings.getString( 190 "enterprise.deployment.backend.deploy_error_application_exists"); 191 throw new IASDeploymentException( msg ); 192 } 193 194 199 checkRegisteredAnywhereElse(appName); 200 } 201 else if(request.isReDeploy()) 202 { 203 if(!isReg) 204 { 205 String msg = localStrings.getString( 206 "enterprise.deployment.backend.redeploy_error_application_does_not_exist"); 207 throw new IASDeploymentException( msg ); 208 }else if(isSystem) 209 { 210 String msg = localStrings.getString( 211 "enterprise.deployment.backend.redeploy_error_application_is_a_system_resource"); 212 throw new IASDeploymentException( msg ); 213 } 214 } 215 } 216 217 private final void setGeneratedDirs() throws IASDeploymentException 221 { 222 try 223 { 224 stubsDir = new File(getAppEnv().getAppStubPath()); 225 jspDir = new File(getAppEnv().getAppJSPPath()); 226 xmlDir = new File(getAppEnv().getAppGeneratedXMLPath()); 227 jwsDir = new File(getAppEnv().getJavaWebStartPath()); 228 request.setJSPDirectory(jspDir); 229 request.setStubsDirectory(stubsDir); 230 request.setGeneratedXMLDirectory(xmlDir); 231 } 232 catch(Exception e) 233 { 234 String msg = localStrings.getString( 235 "enterprise.deployment.backend.error_getting_generated_dirs", 236 e ); 237 throw new IASDeploymentException( msg ); 238 } 239 } 240 protected final ApplicationEnvironment getAppEnv() 244 { 245 return appEnv; 246 } 247 248 250 protected BaseManager getManager() 251 { 252 return appMgr; 253 } 254 255 257 protected final String getAppName() 258 { 259 return appName; 260 } 261 262 264 protected final File getStubsDir() 265 { 266 return stubsDir; 267 } 268 269 271 protected final File getJSPDir() 272 { 273 return jspDir; 274 } 275 276 278 protected final File getXMLDir() 279 { 280 return xmlDir; 281 } 282 283 285 protected final File getJWSDir() 286 { 287 return jwsDir; 288 } 289 290 291 293 protected final File getAppDir() 294 { 295 return appDir; 296 } 297 298 299 protected final File getModuleDir() { 300 return appDir; 301 } 302 303 306 protected List getModuleClasspath(Archivist archivist, 307 AbstractArchive archive) throws IASDeploymentException 308 { 309 try { 310 Application application = request.getDescriptor(); 311 if (application==null) { 312 application = (Application)archivist.readStandardDeploymentDescriptor(archive); 313 application.setRegistrationName(request.getName()); 314 } 315 return EJBClassPathUtils.getAppClassPath( 316 application, request.getDeployedDirectory().getAbsolutePath(), getManager()); 317 } catch(Exception e) { 318 throw new IASDeploymentException(e); 319 } 320 } 321 322 326 protected Application loadDescriptors() throws IASDeploymentException { 327 Application app = super.loadDescriptors(); 328 (new com.sun.enterprise.webservice.WsUtil()).genWSInfo(app, request); 329 return app; 330 } 331 332 334 protected final boolean isSystem() throws IASDeploymentException 335 { 336 try{ 337 boolean isSystem = DeploymentServiceUtils.isSystem(getAppName(), request.getType()); 338 boolean guardSystemApp = !(Boolean.valueOf(System.getProperty(Constants.ALLOW_SYSAPP_DEPLOYMENT, "false")).booleanValue()); 339 if(isSystem && guardSystemApp) 340 return true; 341 else 342 return false; 343 }catch(Exception e) { 344 throw new IASDeploymentException(e); 345 } 346 } 347 348 349 351 protected void generatePolicy() throws IASDeploymentException { 352 try{ 353 Application applicationDD = request.getDescriptor(); 357 358 String linkName = null; 360 boolean lastInService = false; 361 for (Iterator iter = applicationDD.getWebBundleDescriptors().iterator(); 362 iter.hasNext();){ 363 String name 364 = WebSecurityManager.getContextID((WebBundleDescriptor)iter.next()); 365 lastInService = SecurityUtil.linkPolicyFile(name, linkName, lastInService); 366 linkName = name; 367 } 368 for (Iterator iter = applicationDD.getEjbBundleDescriptors().iterator(); iter.hasNext();) { 369 String name = 370 EJBSecurityManager.getContextID((EjbBundleDescriptor)iter.next()); 371 lastInService = SecurityUtil.linkPolicyFile(name, linkName, lastInService); 372 linkName = name; 373 } 374 for (Iterator iter = applicationDD.getWebBundleDescriptors().iterator(); 376 iter.hasNext();){ 377 String name 378 = WebSecurityManager.getContextID((WebBundleDescriptor)iter.next()); 379 SecurityUtil.generatePolicyFile(name); 380 } 381 for (Iterator iter = applicationDD.getEjbBundleDescriptors().iterator(); iter.hasNext();) { 382 String name = 383 EJBSecurityManager.getContextID((EjbBundleDescriptor)iter.next()); 384 SecurityUtil.generatePolicyFile(name); 385 } 386 } catch(IASSecurityException se){ 387 String msg = 389 localStrings.getString("enterprise.deployment.backend.generate_policy_error", request.getName()); 390 throw new IASDeploymentException(msg, se); 391 } 392 } 393 394 public void removePolicy() throws IASDeploymentException 395 { 396 String name = request.getName(); 397 398 try { 399 String [] webcontexts 400 = WebSecurityManagerFactory.getInstance().getAndRemoveContextIdForWebAppName(name); 401 if(webcontexts !=null){ 402 for(int i=0; i<webcontexts.length; i++){ 403 if(webcontexts[i] != null){ 404 SecurityUtil.removePolicy(webcontexts[i]); 405 } 406 } 407 } 408 409 String [] ejbContextIds 411 = ((EJBSecurityManagerFactory)EJBSecurityManagerFactory.getInstance()).getAndRemoveContextIdForEjbAppName(name); 412 if (ejbContextIds != null) { 413 for (String ejbContextId : ejbContextIds) { 414 if (ejbContextId != null) { 415 SecurityUtil.removePolicy(ejbContextId); 416 } 417 } 418 } 419 420 String policyRootDir = System.getProperty( 427 "com.sun.enterprise.jaccprovider.property.repository"); 428 if (policyRootDir != null) { 429 List <String > contextIds = new ArrayList <String >(); 430 File policyDir = new File( 431 policyRootDir + File.separator + name); 432 if (policyDir.exists()) { 433 File[] policies = policyDir.listFiles(); 434 for (int i = 0; i < policies.length; i++) { 435 if (policies[i].isDirectory()) { 436 contextIds.add(name + '/' + policies[i].getName()); 437 } 438 } 439 } else { 440 } 442 443 if (contextIds.size() > 0) { 444 for (String cId : contextIds) { 445 SecurityUtil.removePolicy(cId); 446 } 447 } 448 } 449 450 } catch(IASSecurityException ex) { 451 String msg = localStrings.getString( 452 "enterprise.deployment.backend.remove_policy_error", name); 453 logger.log(Level.WARNING, msg, ex); 454 throw new IASDeploymentException(msg, ex); 455 } 456 } 457 458 459 private ApplicationEnvironment appEnv; 460 private AppsManager appMgr; 461 private String appName; 462 private boolean isReg; 463 private boolean isSystem = false; 464 private File stubsDir; 465 private File jspDir; 466 private File xmlDir; 467 private File jwsDir; 468 private File appDir; 469 private static StringManager localStrings = 470 StringManager.getManager( AppDeployerBase.class ); 471 } 472 473 474 475 | Popular Tags |