1 22 package org.jboss.ejb; 23 24 import java.lang.reflect.Constructor ; 25 import java.lang.reflect.Method ; 26 import java.net.URL ; 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.Collections ; 30 import java.util.LinkedList ; 31 import java.util.HashMap ; 32 import java.util.Iterator ; 33 import java.util.Map ; 34 import java.util.ListIterator ; 35 import java.util.Set ; 36 import java.util.HashSet ; 37 38 import javax.ejb.EJBLocalHome ; 39 import javax.management.ObjectName ; 40 import javax.naming.InitialContext ; 41 import javax.naming.NamingException ; 42 import javax.security.jacc.PolicyConfiguration ; 43 import javax.security.jacc.PolicyConfigurationFactory ; 44 import javax.security.jacc.EJBMethodPermission ; 45 import javax.security.jacc.PolicyContextException ; 46 import javax.security.jacc.EJBRoleRefPermission ; 47 import javax.transaction.TransactionManager ; 48 49 import org.jboss.deployers.spi.deployer.DeploymentUnit; 50 import org.jboss.deployers.spi.structure.DeploymentContext; 51 import org.jboss.deployment.DeploymentException; 52 import org.jboss.deployment.DeploymentInfo; 53 import org.jboss.deployment.EARDeployerMBean; 54 import org.jboss.logging.Logger; 55 import org.jboss.metadata.ApplicationMetaData; 56 import org.jboss.metadata.BeanMetaData; 57 import org.jboss.metadata.ConfigurationMetaData; 58 import org.jboss.metadata.EntityMetaData; 59 import org.jboss.metadata.InvokerProxyBindingMetaData; 60 import org.jboss.metadata.MetaData; 61 import org.jboss.metadata.SessionMetaData; 62 import org.jboss.metadata.XmlLoadable; 63 import org.jboss.metadata.MethodMetaData; 64 import org.jboss.metadata.SecurityRoleRefMetaData; 65 import org.jboss.mx.loading.RepositoryClassLoader; 66 import org.jboss.ejb.deployers.EjbDeployer; 67 import org.jboss.ejb.plugins.SecurityProxyInterceptor; 68 import org.jboss.ejb.plugins.StatefulSessionInstancePool; 69 import org.jboss.security.AuthenticationManager; 70 import org.jboss.security.AuthorizationManager; 71 import org.jboss.security.RealmMapping; 72 import org.jboss.security.SecurityConstants; 73 import org.jboss.security.Util; 74 import org.jboss.security.authorization.PolicyRegistration; 75 import org.jboss.system.Registry; 76 import org.jboss.system.ServiceControllerMBean; 77 import org.jboss.system.ServiceMBeanSupport; 78 import org.jboss.mx.util.MBeanProxyExt; 79 import org.jboss.mx.util.ObjectNameFactory; 80 import org.jboss.util.loading.DelegatingClassLoader; 81 import org.jboss.virtual.VirtualFile; 82 import org.jboss.web.WebClassLoader; 83 import org.jboss.web.WebServiceMBean; 84 import org.jboss.invocation.InvocationType; 85 import org.jboss.tm.TransactionManagerFactory; 86 87 import org.w3c.dom.Element ; 88 89 109 public class EjbModule 110 extends ServiceMBeanSupport 111 implements EjbModuleMBean 112 { 113 public static final String BASE_EJB_MODULE_NAME = "jboss.j2ee:service=EjbModule"; 114 115 public static final ObjectName EJB_MODULE_QUERY_NAME = ObjectNameFactory.create(BASE_EJB_MODULE_NAME + ",*"); 116 117 public static String DEFAULT_STATELESS_CONFIGURATION = "Default Stateless SessionBean"; 118 public static String DEFAULT_STATEFUL_CONFIGURATION = "Default Stateful SessionBean"; 119 public static String DEFAULT_ENTITY_BMP_CONFIGURATION = "Default BMP EntityBean"; 120 public static String DEFAULT_ENTITY_CMP_CONFIGURATION = "Default CMP EntityBean"; 121 public static String DEFAULT_MESSAGEDRIVEN_CONFIGURATION = "Default MesageDriven Bean"; 122 123 public static final int BMT = 1; 125 public static final int CMT = 2; 126 public static final int ANY = 3; 127 128 static final String BMT_VALUE = "Bean"; 129 static final String CMT_VALUE = "Container"; 130 static final String ANY_VALUE = "Both"; 131 132 133 private static final Logger log = Logger.getLogger(EjbModule.class); 134 135 137 139 140 HashMap containers = new HashMap (); 141 142 LinkedList containerOrdering = new LinkedList (); 143 144 HashMap localHomes = new HashMap (); 145 146 147 ClassLoader classLoader = null; 148 149 150 final String name; 151 152 private DeploymentUnit deploymentUnit; 153 154 private ServiceControllerMBean serviceController; 155 156 private final Map moduleData = 157 Collections.synchronizedMap(new HashMap ()); 158 159 private ObjectName webServiceName; 160 161 private TransactionManagerFactory tmFactory; 162 163 164 private boolean callByValue; 165 private ApplicationMetaData appMetaData; 166 167 public EjbModule(final DeploymentUnit unit, ApplicationMetaData metaData) 168 { 169 this.appMetaData = metaData; 170 this.deploymentUnit = unit; 171 String name = deploymentUnit.getName(); 172 if (name.endsWith("/")) 173 { 174 name = name.substring(0, name.length() - 1); 175 } 176 this.name = name; 177 } 178 181 public EjbModule(final DeploymentInfo di, TransactionManager tm, 182 ObjectName webServiceName) 183 { 184 this.name = "deprecated"; 185 } 186 187 public void setTransactionManagerFactory(TransactionManagerFactory tm) 188 { 189 this.tmFactory = tm; 190 } 191 192 public ObjectName getWebServiceName() 193 { 194 return webServiceName; 195 } 196 public void setWebServiceName(ObjectName webServiceName) 197 { 198 this.webServiceName = webServiceName; 199 } 200 201 public Map getModuleDataMap() 202 { 203 return moduleData; 204 } 205 206 public Object getModuleData(Object key) 207 { 208 return moduleData.get(key); 209 } 210 211 public void putModuleData(Object key, Object value) 212 { 213 moduleData.put(key, value); 214 } 215 216 public void removeModuleData(Object key) 217 { 218 moduleData.remove(key); 219 } 220 221 226 private void addContainer(Container con) 227 throws DeploymentException 228 { 229 String ejbName = con.getBeanMetaData().getEjbName(); 230 if (containers.containsKey(ejbName)) 231 throw new DeploymentException("Duplicate ejb-name. Container for " 232 + ejbName + " already exists."); 233 containers.put(ejbName, con); 234 containerOrdering.add(con); 235 con.setEjbModule(this); 236 } 237 238 243 public void removeContainer(Container con) 244 { 245 containers.remove(con.getBeanMetaData().getEjbName()); 246 containerOrdering.remove(con); 247 } 248 249 public void addLocalHome(Container con, EJBLocalHome localHome) 250 { 251 localHomes.put(con.getBeanMetaData().getEjbName(), localHome); 252 } 253 254 public void removeLocalHome(Container con) 255 { 256 localHomes.remove(con.getBeanMetaData().getEjbName()); 257 } 258 259 public EJBLocalHome getLocalHome(Container con) 260 { 261 return (EJBLocalHome ) localHomes.get(con.getBeanMetaData().getEjbName()); 262 } 263 264 269 public boolean isCallByValue() 270 { 271 return callByValue; 272 } 273 274 282 public Container getContainer(String name) 283 { 284 return (Container) containers.get(name); 285 } 286 287 294 public Collection getContainers() 295 { 296 return containerOrdering; 297 } 298 299 304 public ClassLoader getClassLoader() 305 { 306 return classLoader; 307 } 308 309 314 public void setClassLoader(ClassLoader cl) 315 { 316 this.classLoader = cl; 317 } 318 319 324 public URL getURL() 325 { 326 return appMetaData.getUrl(); 327 } 328 329 331 protected void createService() throws Exception 332 { 333 serviceController = (ServiceControllerMBean) 334 MBeanProxyExt.create(ServiceControllerMBean.class, 335 ServiceControllerMBean.OBJECT_NAME, 336 server); 337 338 log.debug("createService, begin"); 339 340 try 342 { 343 if (((Boolean ) server.getAttribute(EJBDeployerMBean.OBJECT_NAME, "CallByValue")).booleanValue()) 344 callByValue = true; 345 } 346 catch (Exception ignored) 347 { 348 log.debug("Unable to ask the EJBDeployer whether we are call by value", ignored); 349 } 350 351 try 353 { 354 if (callByValue == false && ((Boolean ) server.getAttribute(EARDeployerMBean.OBJECT_NAME, "CallByValue")).booleanValue()) 355 callByValue = true; 356 } 357 catch (Exception ignored) 358 { 359 log.debug("Unable to ask the EARDeployer whether we are call by value", ignored); 360 } 361 362 try 364 { 365 Iterator beans = appMetaData.getEnterpriseBeans(); 366 String contextID = appMetaData.getJaccContextID(); 367 if( contextID == null ) 368 contextID = EjbDeployer.shortNameFromDeploymentName(deploymentUnit.getName()); 369 appMetaData.setJaccContextID(contextID); 370 PolicyConfigurationFactory pcFactory = PolicyConfigurationFactory.getPolicyConfigurationFactory(); 371 PolicyConfiguration pc = pcFactory.getPolicyConfiguration(contextID, true); 372 while (beans.hasNext()) 373 { 374 BeanMetaData bean = (BeanMetaData) beans.next(); 375 log.info("Deploying " + bean.getEjbName()); 376 Container con = createContainer(bean, deploymentUnit); 377 addContainer(con); 378 con.setJaccContextID(contextID); 380 createPermissions(bean, pc); 382 deploymentUnit.addAttachment(PolicyConfiguration .class, pc); 383 DeploymentContext current = deploymentUnit.getDeploymentContext(); 385 while (current.getParent() != null) 386 current = current.getParent(); 387 PolicyConfiguration parentPC = 388 current.getTransientAttachments().getAttachment(PolicyConfiguration .class); 389 if (parentPC != null && parentPC != pc) 390 parentPC.linkConfiguration(pc); 391 } 392 pc.commit(); 393 394 ListIterator iter = containerOrdering.listIterator(); 399 while( iter.hasNext() ) 400 { 401 Container con = (Container) iter.next(); 402 ObjectName jmxName = con.getJmxName(); 403 406 server.registerMBean(con, jmxName); 407 BeanMetaData metaData = con.getBeanMetaData(); 409 Collection depends = metaData.getDepends(); 410 serviceController.create(jmxName, depends); 411 int jmxHash = jmxName.hashCode(); 413 Registry.bind(new Integer (jmxHash), jmxName); 414 log.debug("Bound jmxName=" + jmxName + ", hash=" + jmxHash + "into Registry"); 415 } 416 417 String securityDomain = Util.unprefixSecurityDomain(appMetaData.getSecurityDomain()); 419 if(securityDomain == null) 420 securityDomain = SecurityConstants.DEFAULT_EJB_APPLICATION_POLICY; VirtualFile xacmlFile = deploymentUnit.getMetaDataFile("jboss-xacml-policy.xml"); 422 if(xacmlFile != null) 423 { 424 AuthorizationManager authzmgr = Util.getAuthorizationManager(securityDomain); 425 if(authzmgr instanceof PolicyRegistration) 426 { 427 PolicyRegistration xam = (PolicyRegistration)authzmgr; 428 xam.registerPolicy(contextID, xacmlFile.toURL()); 429 } 430 } 431 } 432 catch (Exception e) 433 { 434 destroyService(); 435 throw e; 436 } 438 } 439 440 448 protected void startService() throws Exception 449 { 450 ListIterator iter = containerOrdering.listIterator(); 452 while( iter.hasNext() ) 453 { 454 Container con = (Container) iter.next(); 455 if(con.getBeanMetaData().isEntity()) 456 { 457 ClassLoader oldCl = SecurityActions.getContextClassLoader(); 458 SecurityActions.setContextClassLoader(con.getClassLoader()); 459 460 try 461 { 462 ((EntityContainer)con).getPersistenceManager().start(); 463 } 464 finally 465 { 466 SecurityActions.setContextClassLoader(oldCl); 468 } 469 } 470 } 471 472 iter = containerOrdering.listIterator(); 473 while( iter.hasNext() ) 474 { 475 Container con = (Container) iter.next(); 476 log.debug("startService, starting container: " + con.getBeanMetaData().getEjbName()); 477 serviceController.start(con.getJmxName()); 478 } 479 } 480 481 484 protected void stopService() throws Exception 485 { 486 ListIterator iter = containerOrdering.listIterator(containerOrdering.size()); 487 while( iter.hasPrevious() ) 488 { 489 Container con = (Container) iter.previous(); 490 try 491 { 492 ObjectName jmxName = con.getJmxName(); 493 BeanMetaData metaData = con.getBeanMetaData(); 495 String ejbName = metaData != null ? metaData.getEjbName() : "Unknown"; 496 log.debug("stopService, stopping container: " + ejbName); 497 498 serviceController.stop(jmxName); 499 } 500 catch (Exception e) 501 { 502 log.error("unexpected exception stopping Container: " + con.getJmxName(), e); 503 } } 505 } 506 507 protected void destroyService() throws Exception 508 { 509 WebServiceMBean webServer = null; 510 if (webServiceName != null) 511 { 512 webServer = 513 (WebServiceMBean) MBeanProxyExt.create(WebServiceMBean.class, 514 webServiceName); 515 } 516 ListIterator iter = containerOrdering.listIterator(containerOrdering.size()); 517 String contextID = appMetaData.getJaccContextID(); 519 PolicyConfigurationFactory pcFactory = PolicyConfigurationFactory.getPolicyConfigurationFactory(); 520 PolicyConfiguration pc = pcFactory.getPolicyConfiguration(contextID, true); 521 pc.delete(); 522 String securityDomain = Util.unprefixSecurityDomain(appMetaData.getSecurityDomain()); 524 if(securityDomain != null) 525 { 526 AuthorizationManager authzmgr = Util.getAuthorizationManager(securityDomain); 527 if(authzmgr instanceof PolicyRegistration) 528 { 529 PolicyRegistration xam = (PolicyRegistration)authzmgr; 530 xam.deRegisterPolicy(contextID); 531 } 532 } 533 534 while ( iter.hasPrevious() ) 535 { 536 Container con = (Container) iter.previous(); 537 ObjectName jmxName = con.getJmxName(); 538 int conState = con.getState(); 539 boolean destroyContainer = true; 540 log.debug("Looking to destroy container: " + jmxName 541 + ", state: " + con.getStateString() + ", destroy: " + destroyContainer); 542 543 int jmxHash = jmxName.hashCode(); 545 Registry.unbind(new Integer (jmxHash)); 546 547 if (webServer != null) 551 { 552 ClassLoader wcl = con.getWebClassLoader(); 553 if (wcl != null) 554 { 555 try 556 { 557 webServer.removeClassLoader(wcl); 558 } 559 catch (Throwable e) 560 { 561 log.warn("Failed to unregister webClassLoader", e); 562 } 563 } 564 } 565 566 if( destroyContainer ) 568 { 569 try 570 { 571 serviceController.destroy(jmxName); 572 serviceController.remove(jmxName); 573 log.info("Undeployed " + con.getBeanMetaData().getEjbName()); 574 if( server.isRegistered(jmxName) ) 575 server.unregisterMBean(jmxName); 576 } 577 catch (Throwable e) 578 { 579 log.error("unexpected exception destroying Container: " + jmxName, e); 580 } } 582 583 584 con.setBeanMetaData(null); 586 con.setWebClassLoader(null); 587 con.setClassLoader(null); 588 con.setEjbModule(null); 589 con.setDeploymentInfo(null); 590 con.setTransactionManager(null); 591 con.setSecurityManager(null); 592 con.setRealmMapping(null); 593 con.setSecurityProxy(null); 594 con.setAuthorizationManager(null); 595 con.proxyFactories.clear(); 596 } 597 598 this.containers.clear(); 599 this.localHomes.clear(); 600 this.containerOrdering.clear(); 601 this.moduleData.clear(); 602 this.serviceController = null; 603 } 604 605 609 private Container createContainer(BeanMetaData bean, DeploymentUnit unit) 610 throws Exception 611 { 612 Container container = null; 613 if (bean.isMessageDriven()) 615 { 616 container = createMessageDrivenContainer(bean, unit); 617 } 618 else if (bean.isSession()) { 620 if (((SessionMetaData) bean).isStateless()) { 622 container = createStatelessSessionContainer((SessionMetaData) bean, unit); 623 } 624 else { 626 container = createStatefulSessionContainer((SessionMetaData) bean, unit); 627 } 628 } 629 else { 631 container = createEntityContainer(bean, unit); 632 } 633 634 container.setDeploymentUnit(unit); 635 636 return container; 637 } 638 639 private MessageDrivenContainer createMessageDrivenContainer(BeanMetaData bean, 640 DeploymentUnit unit) 641 throws Exception 642 { 643 ConfigurationMetaData conf = bean.getContainerConfiguration(); 646 MessageDrivenContainer container = new MessageDrivenContainer(); 649 int transType = bean.isContainerManagedTx() ? CMT : BMT; 650 651 initializeContainer(container, conf, bean, transType, unit); 652 createProxyFactories(bean, container); 653 container.setInstancePool(createInstancePool(conf, unit.getClassLoader())); 654 655 return container; 656 } 657 658 private StatelessSessionContainer createStatelessSessionContainer(SessionMetaData bean, 659 DeploymentUnit unit) 660 throws Exception 661 { 662 ConfigurationMetaData conf = bean.getContainerConfiguration(); 665 StatelessSessionContainer container = new StatelessSessionContainer(); 667 int transType = bean.isContainerManagedTx() ? CMT : BMT; 668 initializeContainer(container, conf, bean, transType, unit); 669 if (bean.getHome() != null || bean.getServiceEndpoint()!=null) 670 { 671 createProxyFactories(bean, container); 672 } 673 container.setInstancePool(createInstancePool(conf, unit.getClassLoader())); 674 675 return container; 676 } 677 678 private StatefulSessionContainer createStatefulSessionContainer(SessionMetaData bean, 679 DeploymentUnit unit) 680 throws Exception 681 { 682 ConfigurationMetaData conf = bean.getContainerConfiguration(); 685 StatefulSessionContainer container = new StatefulSessionContainer(); 687 int transType = bean.isContainerManagedTx() ? CMT : BMT; 688 initializeContainer(container, conf, bean, transType, unit); 689 if (bean.getHome() != null || bean.getServiceEndpoint()!=null) 690 { 691 createProxyFactories(bean, container); 692 } 693 694 ClassLoader cl = unit.getClassLoader(); 695 container.setInstanceCache(createInstanceCache(conf, cl)); 696 StatefulSessionInstancePool ip = new StatefulSessionInstancePool(); 698 ip.importXml(conf.getContainerPoolConf()); 699 container.setInstancePool(ip); 700 container.setPersistenceManager((StatefulSessionPersistenceManager) cl.loadClass(conf.getPersistenceManager()).newInstance()); 702 container.setLockManager(createBeanLockManager(container, false, conf.getLockClass(), cl)); 704 705 return container; 706 } 707 708 private EntityContainer createEntityContainer(BeanMetaData bean, 709 DeploymentUnit unit) 710 throws Exception 711 { 712 ConfigurationMetaData conf = bean.getContainerConfiguration(); 715 EntityContainer container = new EntityContainer(); 717 int transType = CMT; 718 initializeContainer(container, conf, bean, transType, unit); 719 if (bean.getHome() != null) 720 { 721 createProxyFactories(bean, container); 722 } 723 724 ClassLoader cl = unit.getClassLoader(); 725 container.setInstanceCache(createInstanceCache(conf, cl)); 726 container.setInstancePool(createInstancePool(conf, cl)); 727 boolean reentrant = ((EntityMetaData) bean).isReentrant(); 729 BeanLockManager lockMgr = createBeanLockManager(container, reentrant, conf.getLockClass(), cl); 730 container.setLockManager(lockMgr); 731 732 if (((EntityMetaData) bean).isBMP()) 734 { 735 Class pmClass = cl.loadClass(conf.getPersistenceManager()); 736 EntityPersistenceManager pm = (EntityPersistenceManager) pmClass.newInstance(); 737 container.setPersistenceManager(pm); 738 } 739 else 740 { 741 org.jboss.ejb.plugins.CMPPersistenceManager persistenceManager = 743 new org.jboss.ejb.plugins.CMPPersistenceManager(); 744 745 Class pmClass = cl.loadClass(conf.getPersistenceManager()); 747 EntityPersistenceStore pm = (EntityPersistenceStore) pmClass.newInstance(); 748 persistenceManager.setPersistenceStore(pm); 749 container.setPersistenceManager(persistenceManager); 751 } 752 753 return container; 754 } 755 756 760 763 private void initializeContainer(Container container, 764 ConfigurationMetaData conf, 765 BeanMetaData bean, 766 int transType, 767 DeploymentUnit unit) 768 throws NamingException , DeploymentException 769 { 770 container.setEjbModule(this); 776 container.setBeanMetaData(bean); 777 778 ClassLoader unitCl = unit.getClassLoader(); 779 String webClassLoaderName = getWebClassLoader(conf, bean); 782 log.debug("Creating WebClassLoader of class " + webClassLoaderName); 783 WebClassLoader wcl = null; 784 try 785 { 786 Class clazz = unitCl.loadClass(webClassLoaderName); 787 Constructor constructor = clazz.getConstructor( 788 new Class []{ObjectName .class, RepositoryClassLoader.class}); 789 wcl = (WebClassLoader) constructor.newInstance( 790 new Object []{container.getJmxName(), unitCl}); 791 } 792 catch (Exception e) 793 { 794 throw new DeploymentException( 795 "Failed to create WebClassLoader of class " 796 + webClassLoaderName + ": ", e); 797 } 798 799 if (webServiceName != null) 800 { 801 WebServiceMBean webServer = 802 (WebServiceMBean) MBeanProxyExt.create(WebServiceMBean.class, 803 webServiceName); 804 URL [] codebase = {webServer.addClassLoader(wcl)}; 805 806 807 wcl.setWebURLs(codebase); 808 } 810 container.setWebClassLoader(wcl); 811 container.setClassLoader(new DelegatingClassLoader(wcl)); 814 815 InitialContext iniCtx = new InitialContext (); 817 container.setTransactionManager(tmFactory.getTransactionManager()); 818 819 String securityDomain = bean.getApplicationMetaData().getSecurityDomain(); 821 String confSecurityDomain = conf.getSecurityDomain(); 822 if (confSecurityDomain == null) 824 confSecurityDomain = securityDomain; 825 826 if (confSecurityDomain != null && confSecurityDomain.length() == 0) 828 confSecurityDomain = null; 829 830 if (confSecurityDomain != null) 831 { try 833 { 834 log.debug("Setting security domain from: " + confSecurityDomain); 835 Object securityMgr = iniCtx.lookup(confSecurityDomain); 836 AuthenticationManager ejbS = (AuthenticationManager) securityMgr; 837 RealmMapping rM = (RealmMapping) securityMgr; 838 container.setSecurityManager(ejbS); 839 container.setRealmMapping(rM); 840 container.setAuthorizationManager(Util.getAuthorizationManager(confSecurityDomain)); 841 } 842 catch (NamingException e) 843 { 844 throw new DeploymentException("Could not find the security-domain, name=" + confSecurityDomain, e); 845 } 846 catch (Exception e) 847 { 848 throw new DeploymentException("Invalid security-domain specified, name=" + confSecurityDomain, e); 849 } 850 } 851 852 String securityProxyClassName = bean.getSecurityProxy(); 854 if (securityProxyClassName != null) 855 { 856 try 857 { 858 Class proxyClass = unitCl.loadClass(securityProxyClassName); 859 Object proxy = proxyClass.newInstance(); 860 container.setSecurityProxy(proxy); 861 log.debug("setSecurityProxy, " + proxy); 862 } 863 catch (Exception e) 864 { 865 throw new DeploymentException("Failed to create SecurityProxy of type: " + 866 securityProxyClassName, e); 867 } 868 } 869 870 addInterceptors(container, transType, conf.getContainerInterceptorsConf()); 872 } 873 874 877 private static String getWebClassLoader(ConfigurationMetaData conf, 878 BeanMetaData bmd) 879 throws DeploymentException 880 { 881 String webClassLoader = null; 882 Iterator it = bmd.getInvokerBindings(); 883 int count = 0; 884 while (it.hasNext()) 885 { 886 String invoker = (String ) it.next(); 887 ApplicationMetaData amd = bmd.getApplicationMetaData(); 888 InvokerProxyBindingMetaData imd = 889 amd.getInvokerProxyBindingMetaDataByName(invoker); 890 if (imd == null) 891 { 892 String msg = "Failed to find InvokerProxyBindingMetaData for: '" 893 + invoker + "'. Check the invoker-proxy-binding-name to " 894 + "invoker-proxy-binding/name mappings in jboss.xml"; 895 throw new DeploymentException(msg); 896 } 897 898 Element proxyFactoryConfig = imd.getProxyFactoryConfig(); 899 String webCL = MetaData.getOptionalChildContent(proxyFactoryConfig, 900 "web-class-loader"); 901 if (webCL != null) 902 { 903 log.debug("Invoker " + invoker 904 + " specified WebClassLoader class" + webCL); 905 webClassLoader = webCL; 906 count++; 907 } 908 } 909 if (count > 1) 910 { 911 log.warn(count + " invokers have WebClassLoader specifications."); 912 log.warn("Using the last specification seen (" 913 + webClassLoader + ")."); 914 } 915 else if (count == 0) 916 { 917 webClassLoader = conf.getWebClassLoader(); 918 } 919 return webClassLoader; 920 } 921 922 937 private void addInterceptors(Container container, 938 int transType, 939 Element element) 940 throws DeploymentException 941 { 942 Iterator interceptorElements = MetaData.getChildrenByTagName(element, "interceptor"); 944 String transTypeString = stringTransactionValue(transType); 945 ClassLoader loader = container.getClassLoader(); 946 949 ArrayList istack = new ArrayList (); 950 while (interceptorElements != null && interceptorElements.hasNext()) 951 { 952 Element ielement = (Element ) interceptorElements.next(); 953 958 String transAttr = ielement.getAttribute("transaction"); 959 if (transAttr == null || transAttr.length() == 0) 960 transAttr = ANY_VALUE; 961 if (transAttr.equalsIgnoreCase(ANY_VALUE) || transAttr.equalsIgnoreCase(transTypeString)) 962 { String metricsAttr = ielement.getAttribute("metricsEnabled"); 964 boolean metricsInterceptor = metricsAttr.equalsIgnoreCase("true"); 965 try 966 { 967 boolean metricsEnabled = ((Boolean ) server.getAttribute(EJBDeployerMBean.OBJECT_NAME, 968 "MetricsEnabled")).booleanValue(); 969 if (metricsEnabled == false && metricsInterceptor == true) 970 { 971 continue; 972 } 973 } 974 catch (Exception e) 975 { 976 log.debug("Couldn't get MetricsEnabled from EJBDeployer: " + e.getMessage()); 978 } 980 981 String className = null; 982 try 983 { 984 className = MetaData.getFirstElementContent(ielement, null); 985 Class clazz = loader.loadClass(className); 986 Interceptor interceptor = (Interceptor) clazz.newInstance(); 987 if (interceptor instanceof XmlLoadable) 988 { 989 ((XmlLoadable)interceptor).importXml(ielement); 990 } 991 istack.add(interceptor); 992 } 993 catch (ClassNotFoundException e) 994 { 995 log.warn("Could not load the " + className + " interceptor", e); 996 } 997 catch (Exception e) 998 { 999 log.warn("Could not load the " + className + " interceptor for this container", e); 1000 } 1001 } 1002 } 1003 1004 if (istack.size() == 0) 1005 log.warn("There are no interceptors configured. Check the standardjboss.xml file"); 1006 1007 for (int i = 0; i < istack.size(); i++) 1009 { 1010 Interceptor interceptor = (Interceptor) istack.get(i); 1011 container.addInterceptor(interceptor); 1012 } 1013 1014 1017 if (container.getSecurityProxy() != null) 1018 container.addInterceptor(new SecurityProxyInterceptor()); 1019 1020 container.addInterceptor(container.createContainerInterceptor()); 1022 } 1023 1024 private void createPermissions(BeanMetaData bean, PolicyConfiguration pc) 1025 throws PolicyContextException 1026 { 1027 Iterator iter = bean.getPermissionMethods(); 1029 while( iter.hasNext() ) 1030 { 1031 MethodMetaData mmd = (MethodMetaData) iter.next(); 1032 String [] params = null; 1033 if( mmd.isParamGiven() ) 1034 params = mmd.getMethodParams(); 1035 String methodName = mmd.getMethodName(); 1036 if( methodName != null && methodName.equals("*") ) 1037 methodName = null; 1038 EJBMethodPermission p = new EJBMethodPermission (mmd.getEjbName(), 1039 methodName, mmd.getInterfaceType(), params); 1040 if( mmd.isUnchecked() ) 1041 { 1042 pc.addToUncheckedPolicy(p); 1043 } 1044 else 1045 { 1046 Set roles = mmd.getRoles(); 1047 Iterator riter = roles.iterator(); 1048 while( riter.hasNext() ) 1049 { 1050 String role = (String ) riter.next(); 1051 pc.addToRole(role, p); 1052 } 1053 } 1054 } 1055 iter = bean.getExcludedMethods(); 1057 while( iter.hasNext() ) 1058 { 1059 MethodMetaData mmd = (MethodMetaData) iter.next(); 1060 String [] params = null; 1061 if( mmd.isParamGiven() ) 1062 params = mmd.getMethodParams(); 1063 EJBMethodPermission p = new EJBMethodPermission (mmd.getEjbName(), 1064 mmd.getMethodName(), mmd.getInterfaceType(), params); 1065 pc.addToExcludedPolicy(p); 1066 } 1067 iter = bean.getSecurityRoleReferences(); 1069 while( iter.hasNext() ) 1070 { 1071 SecurityRoleRefMetaData srrmd = (SecurityRoleRefMetaData) iter.next(); 1072 EJBRoleRefPermission p = new EJBRoleRefPermission (bean.getEjbName(), srrmd.getName()); 1073 pc.addToRole(srrmd.getLink(), p); 1074 } 1075 1079 if( bean instanceof SessionMetaData ) 1080 { 1081 SessionMetaData smd = (SessionMetaData) bean; 1082 if( smd.isStateful() ) 1083 { 1084 EJBMethodPermission p = new EJBMethodPermission (bean.getEjbName(), 1085 "getEJBObject", "Home", null); 1086 pc.addToUncheckedPolicy(p); 1087 } 1088 } 1089 } 1090 1091 1098 void createMissingPermissions(Container con, BeanMetaData bean) 1099 throws ClassNotFoundException , PolicyContextException 1100 { 1101 String contextID = con.getJaccContextID(); 1102 PolicyConfigurationFactory pcFactory = PolicyConfigurationFactory.getPolicyConfigurationFactory(); 1103 PolicyConfiguration pc = pcFactory.getPolicyConfiguration(contextID, false); 1104 Class clazz = con.getHomeClass(); 1105 boolean hasSecurityDomain = con.getSecurityManager() != null; 1107 boolean exclude = hasSecurityDomain ? bean.isExcludeMissingMethods() : false; 1108 1109 if( clazz != null ) 1110 { 1111 addMissingMethodPermissions(bean, exclude, clazz, InvocationType.HOME, pc); 1112 } 1113 clazz = con.getLocalHomeClass(); 1114 if( clazz != null ) 1115 { 1116 addMissingMethodPermissions(bean, exclude, clazz, InvocationType.LOCALHOME, pc); 1117 } 1118 clazz = con.getLocalClass(); 1119 if( clazz != null ) 1120 { 1121 addMissingMethodPermissions(bean, exclude, clazz, InvocationType.LOCAL, pc); 1122 } 1123 clazz = con.getRemoteClass(); 1124 if( clazz != null ) 1125 { 1126 addMissingMethodPermissions(bean, exclude, clazz, InvocationType.REMOTE, pc); 1127 } 1128 pc.commit(); 1129 } 1130 1131 private void getInterfaces(Class iface, HashSet tmp) 1132 { 1133 tmp.add(iface); 1134 Class [] ifaces = iface.getInterfaces(); 1135 for(int n = 0; n < ifaces.length; n ++) 1136 { 1137 Class iface2 = ifaces[n]; 1138 tmp.add(iface2); 1139 getInterfaces(iface2, tmp); 1140 } 1141 } 1142 private void addMissingMethodPermissions(BeanMetaData bean, boolean exclude, 1143 Class iface, InvocationType type, PolicyConfiguration pc) 1144 throws PolicyContextException 1145 { 1146 String ejbName = bean.getEjbName(); 1147 HashSet tmp = new HashSet (); 1148 getInterfaces(iface, tmp); 1149 Class [] ifaces = new Class [tmp.size()]; 1150 tmp.toArray(ifaces); 1151 for(int n = 0; n < ifaces.length; n ++) 1152 { 1153 Class c = ifaces[n]; 1154 Method [] methods = c.getDeclaredMethods(); 1155 for(int m = 0; m < methods.length; m ++) 1156 { 1157 String methodName = methods[m].getName(); 1158 Class [] params = methods[m].getParameterTypes(); 1159 if( bean.hasMethodPermission(methodName, params, type) ) 1161 continue; 1162 EJBMethodPermission p = new EJBMethodPermission (ejbName, 1164 type.toInterfaceString(), methods[m]); 1165 if( exclude ) 1166 pc.addToExcludedPolicy(p); 1167 else 1168 pc.addToUncheckedPolicy(p); 1169 } 1170 } 1171 } 1172 1173 private static String stringTransactionValue(int transType) 1174 { 1175 String transaction = ANY_VALUE; 1176 switch (transType) 1177 { 1178 case BMT: 1179 transaction = BMT_VALUE; 1180 break; 1181 case CMT: 1182 transaction = CMT_VALUE; 1183 break; 1184 } 1185 return transaction; 1186 } 1187 1188 1191 private static void createProxyFactories(BeanMetaData conf, Container container) 1192 throws Exception 1193 { 1194 ClassLoader cl = container.getClassLoader(); 1195 Iterator it = conf.getInvokerBindings(); 1196 boolean foundOne=false; 1197 while (it.hasNext()) 1198 { 1199 String invoker = (String ) it.next(); 1200 String jndiBinding = conf.getInvokerBinding(invoker); 1201 log.debug("creating binding for " + jndiBinding + ":" + invoker); 1202 InvokerProxyBindingMetaData imd = conf.getApplicationMetaData().getInvokerProxyBindingMetaDataByName(invoker); 1203 EJBProxyFactory ci = null; 1204 1205 try 1207 { 1208 ci = (EJBProxyFactory) cl.loadClass(imd.getProxyFactory()).newInstance(); 1209 ci.setContainer(container); 1210 ci.setInvokerMetaData(imd); 1211 ci.setInvokerBinding(jndiBinding); 1212 if (ci instanceof XmlLoadable) 1213 { 1214 ((XmlLoadable) ci).importXml(imd.getProxyFactoryConfig()); 1216 } 1217 container.addProxyFactory(invoker, ci); 1218 foundOne=true; 1219 } 1220 catch (Exception e) 1221 { 1222 log.warn("The Container Invoker "+invoker+" (in jboss.xml or standardjboss.xml) could not be created because of "+e+ 1223 " We will ignore this error, but you may miss a transport for this bean."); 1224 } 1225 } 1226 if(!foundOne) { 1227 throw new DeploymentException("Missing or invalid Container Invokers (in jboss.xml or standardjboss.xml)."); 1228 } 1229 } 1230 1231 1232 private static BeanLockManager createBeanLockManager(Container container, boolean reentrant, String beanLock, 1233 ClassLoader cl) 1234 throws Exception 1235 { 1236 BeanLockManager lockManager = new BeanLockManager(container); 1238 1239 Class lockClass = null; 1240 try 1241 { 1242 lockClass = cl.loadClass(beanLock); 1243 } 1244 catch (Exception e) 1245 { 1246 throw new DeploymentException("Missing or invalid lock class (in jboss.xml or standardjboss.xml): " + beanLock + " - " + e); 1247 } 1248 1249 lockManager.setLockCLass(lockClass); 1250 lockManager.setReentrant(reentrant); 1251 1252 return lockManager; 1253 } 1254 1255 private static InstancePool createInstancePool(ConfigurationMetaData conf, 1256 ClassLoader cl) 1257 throws Exception 1258 { 1259 InstancePool ip = null; 1261 1262 try 1263 { 1264 ip = (InstancePool) cl.loadClass(conf.getInstancePool()).newInstance(); 1265 } 1266 catch (Exception e) 1267 { 1268 throw new DeploymentException("Missing or invalid Instance Pool (in jboss.xml or standardjboss.xml)", e); 1269 } 1270 1271 if (ip instanceof XmlLoadable) 1272 ((XmlLoadable) ip).importXml(conf.getContainerPoolConf()); 1273 1274 return ip; 1275 } 1276 1277 private static InstanceCache createInstanceCache(ConfigurationMetaData conf, 1278 ClassLoader cl) 1279 throws Exception 1280 { 1281 InstanceCache ic = null; 1283 1284 try 1285 { 1286 ic = (InstanceCache) cl.loadClass(conf.getInstanceCache()).newInstance(); 1287 } 1288 catch (Exception e) 1289 { 1290 throw new DeploymentException("Missing or invalid Instance Cache (in jboss.xml or standardjboss.xml)", e); 1291 } 1292 1293 if (ic instanceof XmlLoadable) 1294 ((XmlLoadable) ic).importXml(conf.getContainerCacheConf()); 1295 1296 return ic; 1297 } 1298} 1299 1302 | Popular Tags |