| 1 25 26 package org.objectweb.jonas_ejb.deployment.api; 27 28 import java.lang.reflect.Modifier ; 29 import java.rmi.RemoteException ; 30 import java.util.ArrayList ; 31 import java.util.Arrays ; 32 import java.util.Comparator ; 33 import java.util.HashMap ; 34 import java.util.Iterator ; 35 import java.util.LinkedList ; 36 import java.util.List ; 37 import java.util.Properties ; 38 39 import org.omg.CSI.ITTAbsent; 40 import org.omg.CSI.ITTAnonymous; 41 import org.omg.CSI.ITTDistinguishedName; 42 import org.omg.CSI.ITTPrincipalName; 43 import org.omg.CSI.ITTX509CertChain; 44 import org.omg.CSIIOP.Confidentiality; 45 import org.omg.CSIIOP.EstablishTrustInClient; 46 import org.omg.CSIIOP.EstablishTrustInTarget; 47 import org.omg.CSIIOP.IdentityAssertion; 48 import org.omg.CSIIOP.Integrity; 49 50 import org.objectweb.carol.util.csiv2.SasComponent; 51 import org.objectweb.carol.util.csiv2.struct.AsStruct; 52 import org.objectweb.carol.util.csiv2.struct.SasStruct; 53 import org.objectweb.carol.util.csiv2.struct.TransportStruct; 54 55 import org.objectweb.jonas_ejb.container.BeanFactory; 56 import org.objectweb.jonas_ejb.container.TraceEjb; 57 import org.objectweb.jonas_ejb.deployment.xml.AsContextMapping; 58 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor; 59 import org.objectweb.jonas_ejb.deployment.xml.CommonEjb; 60 import org.objectweb.jonas_ejb.deployment.xml.ContainerTransaction; 61 import org.objectweb.jonas_ejb.deployment.xml.IorSecurityConfigMapping; 62 import org.objectweb.jonas_ejb.deployment.xml.JonasCommonEjb; 63 import org.objectweb.jonas_ejb.deployment.xml.Method; 64 import org.objectweb.jonas_ejb.deployment.xml.MethodPermission; 65 import org.objectweb.jonas_ejb.deployment.xml.SasContextMapping; 66 import org.objectweb.jonas_ejb.deployment.xml.TransportConfigMapping; 67 import org.objectweb.jonas_ejb.lib.BeanNaming; 68 import org.objectweb.jonas_ejb.lib.JavaType; 69 70 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException; 71 import org.objectweb.jonas_lib.deployment.api.EjbLocalRefDesc; 72 import org.objectweb.jonas_lib.deployment.api.EjbRefDesc; 73 import org.objectweb.jonas_lib.deployment.api.EnvEntryDesc; 74 import org.objectweb.jonas_lib.deployment.api.JndiEnvRefsGroupDesc; 75 import org.objectweb.jonas_lib.deployment.api.MessageDestinationRefDesc; 76 import org.objectweb.jonas_lib.deployment.api.ResourceEnvRefDesc; 77 import org.objectweb.jonas_lib.deployment.api.ResourceRefDesc; 78 import org.objectweb.jonas_lib.deployment.api.SecurityRoleRefDesc; 79 import org.objectweb.jonas_lib.deployment.xml.JLinkedList; 80 import org.objectweb.jonas_lib.deployment.xml.RunAs; 81 import org.objectweb.jonas_lib.deployment.xml.SecurityRole; 82 import org.objectweb.jonas_lib.deployment.xml.SecurityRoleRef; 83 84 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc; 85 86 import org.objectweb.util.monolog.api.BasicLevel; 87 import org.objectweb.util.monolog.api.Logger; 88 89 98 public abstract class BeanDesc extends JndiEnvRefsGroupDesc { 99 100 103 protected static final int BEAN_TRANSACTION_TYPE = 1; 104 105 108 protected static final int CONTAINER_TRANSACTION_TYPE = 2; 109 110 protected static final String [] TRANS = {null, "BEAN_TRANSACTION_TYPE", "CONTAINER_TRANSACTION_TYPE"}; 111 112 private static final String ejb10PropertiesPrefix = "ejb10-properties/"; 113 114 117 private static final String REMOTEDEFAULTSUFFIX = "Home"; 118 119 123 private static final String LOCALDEFAULTSUFFIX = "_L"; 124 125 128 public static final String GENERATED_PREFIX = "org.objectweb.jonas_gen."; 129 130 133 protected String ejbName = null; 134 135 138 protected String jndiName = null; 139 140 143 protected String jndiLocalName = null; 144 145 148 protected Class home = null; 149 150 153 protected Class remote = null; 154 155 158 protected Class localhome = null; 159 160 163 protected Class local = null; 164 165 168 protected Class ejbClass = null; 169 170 173 protected String beanIdentification = null; 174 175 178 protected Properties ejb10EnvProps = new Properties (); 179 180 183 protected Logger logger = null; 184 185 188 private ArrayList methodDesc = new ArrayList (); 189 190 193 private HashMap methodDescMap = new HashMap (); 194 195 198 protected List securityRoleRefDescList = null; 199 200 203 protected DeploymentDesc deploymentDesc = null; 204 205 208 private String fullWrpRemoteName = null; 209 210 213 private String wrpRemoteName = null; 214 215 218 private String fullWrpHomeName = null; 219 220 223 private String wrpHomeName = null; 224 225 228 private String fullWrpLocalName = null; 229 230 233 private String wrpLocalName = null; 234 235 238 private String fullWrpLocalHomeName = null; 239 240 243 private String wrpLocalHomeName = null; 244 245 248 private String fullWrpHandleName = null; 249 250 253 private String wrpHandleName = null; 254 255 258 protected String fullDerivedBeanName = null; 259 260 263 protected String derivedBeanName = null; 264 265 268 private String runAsRole = null; 269 270 273 private String runAsPrincipalName = null; 274 275 278 protected int poolMin = 0; 279 280 283 protected int cacheMax = 0; 284 285 288 private SasComponent sasComponent = null; 289 290 protected int timerTxAttribute = MethodDesc.TX_REQUIRES_NEW; 292 protected String ejbTimeoutSignature; 293 294 297 protected BeanFactory bf = null; 298 299 311 public BeanDesc(ClassLoader classLoader, CommonEjb ejb, JonasCommonEjb jonasEjb, AssemblyDescriptor asd, 312 JLinkedList jMDRList, String fileName) throws DeploymentDescException { 313 314 super(classLoader, ejb, jonasEjb, fileName); 315 securityRoleRefDescList = new LinkedList (); 316 if (ejb.getEjbName() != null) { 317 ejbName = ejb.getEjbName(); 318 } else { 319 ejbName = null; 320 } 321 322 if (jonasEjb.getJndiName() != null) { 324 jndiName = jonasEjb.getJndiName(); 325 } else { 326 jndiName = ejbName + REMOTEDEFAULTSUFFIX; 327 } 328 if (jonasEjb.getJndiLocalName() != null) { 331 jndiLocalName = jonasEjb.getJndiLocalName(); 332 } else { 333 jndiLocalName = jndiName + LOCALDEFAULTSUFFIX; 334 } 335 336 if (ejb.getHome() != null) { 339 try { 340 this.home = classLoader.loadClass(ejb.getHome()); 341 if (!javax.ejb.EJBHome .class.isAssignableFrom(this.home)) { 343 throw new DeploymentDescException("Home class '" + ejb.getHome() 344 + "' doesn't not extends javax.ejb.EJBHome"); 345 } 346 } catch (ClassNotFoundException e) { 347 throw new DeploymentDescException("Home class not found for bean " + ejbName, e); 348 } 349 } 350 351 if (ejb.getRemote() != null) { 352 try { 353 this.remote = classLoader.loadClass(ejb.getRemote()); 354 if (!javax.ejb.EJBObject .class.isAssignableFrom(this.remote)) { 356 throw new DeploymentDescException("Remote class '" + ejb.getRemote() 357 + "' doesn't not extends javax.ejb.EJBObject"); 358 } 359 } catch (ClassNotFoundException e) { 360 throw new DeploymentDescException("Remote class not found for bean " + ejbName, e); 361 } 362 } 363 364 String localhomename = ejb.getLocalHome(); 365 if (localhomename == null && this instanceof EntityCmp2Desc) { 367 localhomename = "javax.ejb.EJBLocalHome"; 368 } 369 if (localhomename != null) { 370 try { 371 this.localhome = classLoader.loadClass(localhomename); 372 if (!javax.ejb.EJBLocalHome .class.isAssignableFrom(this.localhome)) { 374 throw new DeploymentDescException("LocalHome class '" + localhomename 375 + "' doesn't not extends javax.ejb.EJBLocalHome"); 376 } 377 } catch (ClassNotFoundException e) { 378 throw new DeploymentDescException("LocalHome class not found for bean " + ejbName, e); 379 } 380 } 381 382 String localname = ejb.getLocal(); 383 if (localname == null && this instanceof EntityCmp2Desc) { 385 localname = "javax.ejb.EJBLocalObject"; 386 } 387 if (localname != null) { 388 try { 389 this.local = classLoader.loadClass(localname); 390 if (!javax.ejb.EJBLocalObject .class.isAssignableFrom(this.local)) { 392 throw new DeploymentDescException("Local class '" + localname 393 + "' doesn't not extends javax.ejb.EJBLocalObject"); 394 } 395 } catch (ClassNotFoundException e) { 396 throw new DeploymentDescException("Local class not found for bean " + ejbName, e); 397 } 398 } 399 400 loadExtraClasses(ejb, classLoader); 402 403 try { 404 this.ejbClass = classLoader.loadClass(ejb.getEjbClass()); 405 if (!javax.ejb.EnterpriseBean .class.isAssignableFrom(this.ejbClass)) { 407 throw new DeploymentDescException("Ejb class '" + ejb.getEjbClass() 408 + "' doesn't not extends javax.ejb.EnterpriseBean"); 409 } 410 } catch (ClassNotFoundException e) { 411 throw new DeploymentDescException("Ejb class not found for bean " + ejbName, e); 412 } 413 414 EnvEntryDesc[] envt = getEnvEntryDesc(); 416 for (int i = 0; i < envt.length; i++) { 417 if (envt[i].getName().startsWith(ejb10PropertiesPrefix)) { 418 String newName = envt[i].getName().substring(ejb10PropertiesPrefix.length()); 419 String value = new String (); 420 if (envt[i].hasValue()) { 421 value = envt[i].getValue().toString(); 422 } 423 ejb10EnvProps.put(newName, value); 424 } 425 } 426 427 if (ejb.getSecurityIdentity() != null) { 429 RunAs runAsElem = ejb.getSecurityIdentity().getRunAs(); 430 if (runAsElem != null) { 431 String roleName = runAsElem.getRoleName(); 432 if (roleName != null) { 433 runAsRole = roleName; 434 boolean runAsRoleFound = false; 435 for (Iterator j = asd.getSecurityRoleList().iterator(); j.hasNext();) { 436 SecurityRole securityRole = (SecurityRole) j.next(); 437 String r = securityRole.getRoleName(); 440 if (r.equals(runAsRole)) { 441 runAsRoleFound = true; 442 } 443 } 444 if (!runAsRoleFound) { 446 throw new DeploymentDescException("There is no security-role defined for the run-as role: " 447 + runAsRole); 448 } 449 } 450 runAsPrincipalName = jonasEjb.getRunAsPrincipalName(); 452 if (runAsPrincipalName == null) { 454 runAsPrincipalName = runAsRole; 455 } 456 } 457 } 458 459 try { 461 java.lang.reflect.Method [] m; 462 int beginIdx = methodDesc.size(); 463 int len = 0; 464 if ((this.home != null) && (this.remote != null)) { 465 m = this.home.getMethods(); 467 for (int i = 0; i < m.length; i++) { 468 if (!m[i].getDeclaringClass().equals(javax.ejb.EJBHome .class) 469 || m[i].getName().equals("remove")) { 470 addMethodDesc(m[i], this.home); 471 len++; 472 checkRemoteException(m[i], true); 474 481 } 482 } 483 484 m = this.remote.getMethods(); 485 for (int i = 0; i < m.length; i++) { 486 if (!m[i].getDeclaringClass().equals(javax.ejb.EJBObject .class) 487 || m[i].getName().equals("remove")) { 488 addMethodDesc(m[i], this.remote); 489 len++; 490 checkRemoteException(m[i], true); 492 498 } 499 } 500 } 501 if ((this.localhome != null) && (this.local != null)) { 502 m = this.localhome.getMethods(); 504 for (int i = 0; i < m.length; i++) { 505 if (!m[i].getDeclaringClass().equals(javax.ejb.EJBLocalHome .class) 506 || m[i].getName().equals("remove")) { 507 addMethodDesc(m[i], this.localhome); 508 len++; 509 checkRemoteException(m[i], false); 511 } 512 } 513 m = this.local.getMethods(); 514 for (int i = 0; i < m.length; i++) { 515 if (!m[i].getDeclaringClass().equals(javax.ejb.EJBLocalObject .class) 516 || m[i].getName().equals("remove")) { 517 addMethodDesc(m[i], this.local); 518 len++; 519 checkRemoteException(m[i], false); 521 } 522 } 523 } 524 if (this.home == null && this.localhome == null) { 525 526 if (ejb.getMessagingType() != null) { 527 String msgType = ejb.getMessagingType(); 529 try { 530 m = classLoader.loadClass(msgType).getMethods(); 531 for (int i = 0; i < m.length; i++) { 532 addMethodDesc(m[i], m[i].getDeclaringClass()); 533 len++; 534 } 535 } catch (Exception ex) { 536 throw new DeploymentDescException("Cannot load messaging type class (" + msgType + ") for " 537 + ejbName, ex); 538 } 539 } 540 } 542 543 if (javax.ejb.EntityBean .class.isAssignableFrom(this.ejbClass)) { 544 m = this.ejbClass.getMethods(); 546 for (int i = 0; i < m.length; i++) { 547 if (m[i].getName().startsWith("ejbSelect") && Modifier.isAbstract(m[i].getModifiers())) { 548 addMethodDesc(m[i], this.ejbClass); 549 len++; 550 } 551 } 552 } 553 554 if (javax.ejb.TimedObject .class.isAssignableFrom(this.ejbClass)) { 555 try { 556 java.lang.reflect.Method timeout = this.ejbClass.getMethod("ejbTimeout", 557 new Class []{javax.ejb.Timer .class}); 558 addMethodDesc(timeout, this.ejbClass); 559 len++; 560 } catch (NoSuchMethodException e) { 561 throw new DeploymentDescException("ejbTimeout not implemented in " + ejbName); 562 } 563 } 564 565 len = addEJBMethodDesc(len); 566 orderMethodDesc(methodDesc, beginIdx, len); 567 } catch (SecurityException e) { 568 throw new DeploymentDescException("Cannot use java reflection on " + ejbName, e); 569 } 570 571 if (ejb.getSecurityRoleRefList() != null) { 574 for (Iterator i = ejb.getSecurityRoleRefList().iterator(); i.hasNext();) { 575 SecurityRoleRef sRoleRef = (SecurityRoleRef) i.next(); 576 if (asd == null) { 578 throw new DeploymentDescException( 579 "No assembly-descriptor element (and security-role elements) whereas security-role-ref element(s) are defined"); 580 } else { 581 if (asd.getSecurityRoleList().isEmpty()) { 584 throw new DeploymentDescException( 585 "No security-role elements defined in the assembly-descriptor element whereas security-role-ref element(s) are defined"); 586 } 587 } 588 if (sRoleRef.getRoleLink() == null) { 591 throw new DeploymentDescException( 592 "No role-link element in a security-role-ref element with role-name element : " 593 + sRoleRef.getRoleName()); 594 } 595 String roleLink = sRoleRef.getRoleLink(); 596 String roleRefName = sRoleRef.getRoleName(); 598 boolean correspondingRoles = false; 600 for (Iterator j = asd.getSecurityRoleList().iterator(); j.hasNext();) { 601 SecurityRole securityRole = (SecurityRole) j.next(); 602 String roleName = securityRole.getRoleName(); 605 if (roleName.equals(roleLink)) { 606 securityRoleRefDescList.add(new SecurityRoleRefDesc(ejbName, sRoleRef, true)); 607 correspondingRoles = true; 608 } 609 } 610 if (!correspondingRoles) { 612 throw new DeploymentDescException( 613 "No corresponding role-name in a security-role element for role-link : " + roleLink); 614 } 615 } 616 } 617 618 if (asd != null) { 621 verifyRoleName(asd); 622 for (Iterator i = asd.getMethodPermissionList().iterator(); i.hasNext();) { 624 MethodPermission methodPermission = (MethodPermission) i.next(); 625 for (Iterator j = methodPermission.getMethodList().iterator(); j.hasNext();) { 626 Method m = ((Method) j.next()); 627 if (!m.getEjbName().equals(ejbName)) { 629 continue; 630 } 631 Class pClass = null; 633 if (m.getMethodIntf() != null) { 634 pClass = getParentClass(m.getMethodIntf()); 635 } 636 for (int k = 0; k < methodDesc.size(); k++) { 637 MethodDesc md = (MethodDesc) methodDesc.get(k); 638 int matchStatus = md.matchPattern(pClass, m.getMethodName(), m.getMethodParams()); 639 for (Iterator l = methodPermission.getRoleNameList().iterator(); l.hasNext();) { 640 String roleName = (String ) l.next(); 641 if (matchStatus > MethodDesc.APPLY_TO_NOTHING) { 643 md.addRoleName(roleName); 644 } 645 } 646 } 647 } 648 } 649 } 650 651 if (asd != null && asd.getExcludeList() != null) { 653 for (Iterator i = asd.getExcludeList().getMethodList().iterator(); i.hasNext();) { 655 Method m = (Method) i.next(); 656 if (!m.getEjbName().equals(ejbName)) { 658 continue; 659 } 660 Class pClass = null; 662 if (m.getMethodIntf() != null) { 663 pClass = getParentClass(m.getMethodIntf()); 664 } 665 for (int k = 0; k < methodDesc.size(); k++) { 667 MethodDesc md = (MethodDesc) methodDesc.get(k); 668 int matchStatus = md.matchPattern(pClass, m.getMethodName(), m.getMethodParams()); 669 if (matchStatus > MethodDesc.APPLY_TO_NOTHING) { 671 md.setExcluded(true); 672 } 673 } 674 } 675 } 676 677 if (asd != null) { 679 Iterator i = asd.getContainerTransactionList().iterator(); 681 while (i.hasNext()) { 682 ContainerTransaction cotr = (ContainerTransaction) i.next(); 683 Iterator j = cotr.getMethodList().iterator(); 685 while (j.hasNext()) { 686 Method m = (Method) j.next(); 687 if (!m.getEjbName().equals(ejbName)) { 689 continue; 690 } 691 692 |