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 Class pClass = null; 694 if (m.getMethodIntf() != null) { 695 pClass = getParentClass(m.getMethodIntf()); 696 } 697 698 boolean found = false; 700 for (int k = 0; k < methodDesc.size(); k++) { 701 MethodDesc md = (MethodDesc) methodDesc.get(k); 702 int matchStatus = md.matchPattern(pClass, m.getMethodName(), m.getMethodParams()); 703 if (matchStatus != MethodDesc.APPLY_TO_NOTHING) { 704 found = true; 705 } 706 String transAttribute = null; 708 if (cotr.getTransAttribute() != null) { 709 transAttribute = cotr.getTransAttribute(); 710 } 711 md.overwriteTxAttribute(transAttribute, matchStatus); 712 } 713 if (!found) { 714 TraceEjb.dd.log(BasicLevel.WARN, "Invalid container-transaction: method '" 717 + MethodDesc.methodElementToString(m) + "' not declared in bean " + ejbName); 718 } 719 } 720 } 721 } 722 723 String packageName = ""; 724 String ejbIdentifier = getIdentifier(); 725 726 if (getRemoteClass() != null) { 727 packageName = GENERATED_PREFIX + BeanNaming.getPackageName(getRemoteClass().getName()); 728 wrpRemoteName = new String ("JOnAS" + ejbIdentifier + "Remote"); 729 wrpHandleName = new String ("JOnAS" + ejbIdentifier + "Handle"); 730 fullWrpRemoteName = BeanNaming.getClassName(packageName, wrpRemoteName); 731 fullWrpHandleName = BeanNaming.getClassName(packageName, wrpHandleName); 732 } 733 734 if (getLocalClass() != null) { 735 packageName = GENERATED_PREFIX + BeanNaming.getPackageName(getLocalClass().getName()); 736 wrpLocalName = new String ("JOnAS" + ejbIdentifier + "Local"); 737 fullWrpLocalName = BeanNaming.getClassName(packageName, wrpLocalName); 738 } 739 740 if (getHomeClass() != null) { 741 packageName = GENERATED_PREFIX + BeanNaming.getPackageName(getHomeClass().getName()); 742 wrpHomeName = new String ("JOnAS" + ejbIdentifier + "Home"); 743 fullWrpHomeName = BeanNaming.getClassName(packageName, wrpHomeName); 744 } 745 746 if (getLocalHomeClass() != null) { 747 packageName = GENERATED_PREFIX + BeanNaming.getPackageName(getLocalHomeClass().getName()); 748 wrpLocalHomeName = new String ("JOnAS" + ejbIdentifier + "LocalHome"); 749 fullWrpLocalHomeName = BeanNaming.getClassName(packageName, wrpLocalHomeName); 750 } 751 752 fullDerivedBeanName = getEjbClass().getName(); 753 derivedBeanName = BeanNaming.getBaseName(getEjbClass().getName()); 754 755 IorSecurityConfigMapping iorSecurityConfigMapping = jonasEjb.getIorSecurityConfig(); 756 if (iorSecurityConfigMapping != null) { 757 processIorSecurityConfig(iorSecurityConfigMapping); 758 } 759 760 } 761 762 771 protected void loadExtraClasses(CommonEjb ce, ClassLoader loader) throws DeploymentDescException { 772 } 774 775 785 protected int addEJBMethodDesc(int len) throws DeploymentDescException { 786 return len; 787 } 788 789 799 protected Class getParentClass(String intfType) throws DeploymentDescException { 800 Class pClass = null; 801 if (intfType.equals("Home")) { 802 pClass = javax.ejb.EJBHome .class; 803 } else if (intfType.equals("Remote")) { 804 pClass = javax.ejb.EJBObject .class; 805 } else if (intfType.equals("LocalHome")) { 806 pClass = javax.ejb.EJBLocalHome .class; 807 } else if (intfType.equals("Local")) { 808 pClass = javax.ejb.EJBLocalObject .class; 809 } else { 810 throw new DeploymentDescException(intfType + " is invalid value for method-intf on bean " + ejbName); 811 } 812 return pClass; 813 } 814 815 820 protected String getHashCodeForIdentifier() { 821 String hash = ""; 822 if (getJndiName() != null) { 823 hash += getJndiName(); 824 } 825 if (getJndiLocalName() != null) { 826 hash += getJndiLocalName(); 827 } 828 return Integer.toString(hash.hashCode()); 829 } 830 831 835 public String getIdentifier() { 836 837 if (beanIdentification == null) { 838 String identifier = getEjbName(); 839 identifier += getHashCodeForIdentifier(); 840 841 char[] tabChar = new char[identifier.length()]; 842 for (int i = 0; i < identifier.length(); i++) { 843 if (!Character.isJavaIdentifierPart(identifier.charAt(i))) { 844 tabChar[i] = '_'; 845 } else { 846 tabChar[i] = identifier.charAt(i); 847 } 848 } 849 beanIdentification = new String (tabChar); 850 } 851 return beanIdentification; 852 } 853 854 863 public void checkRemoteException(java.lang.reflect.Method m, boolean shouldThrow) throws DeploymentDescException { 864 Class [] excepts = m.getExceptionTypes(); 865 for (int j = 0; j < excepts.length; j++) { 866 if (RemoteException .class.isAssignableFrom(excepts[j])) { 867 if (shouldThrow) { 868 return; 869 } else { 870 throw new DeploymentDescException("Method " + m.getName() + " of " + m.getDeclaringClass() 871 + " should NOT throw RemoteException"); 872 } 873 } 874 } 875 if (shouldThrow) { 876 throw new DeploymentDescException("Method " + m.getName() + " of " + m.getDeclaringClass() 877 + " must throw RemoteException"); 878 } else { 879 return; 880 } 881 882 } 883 884 892 public void checkValidTypesForRmi(java.lang.reflect.Method m) { 893 boolean isValid = true; 894 Class [] paramTypes = m.getParameterTypes(); 895 for (int i = 0; i < paramTypes.length; i++) { 896 if (!JavaType.isValidForRmi(paramTypes[i])) { 897 isValid = false; 898 } 899 } 900 if (!JavaType.isValidForRmi(m.getReturnType()) && !JavaType.isVoid(m.getReturnType()) 901 && !JavaType.isCollecOrEnum(m.getReturnType())) { 902 isValid = false; 904 } 905 if (!isValid) { 906 TraceEjb.dd.log(BasicLevel.WARN, "Method " + m.getName() + " of " + m.getDeclaringClass() 910 + " may be have an invalid argument or return type for RMI"); 911 } 912 } 913 914 919 public void check() throws DeploymentDescException { 920 for (int i = 0; i < methodDesc.size(); i++) { 922 checkTxAttribute(((MethodDesc) methodDesc.get(i))); 923 } 924 checkRunAsMapping(); 925 } 926 927 931 public void checkRunAsMapping() throws DeploymentDescException { 932 if (runAsPrincipalName != null) { 933 String [] runAsPrincipalRoles = deploymentDesc.getRolesForRunAsPrincipal(runAsPrincipalName); 935 if (runAsPrincipalRoles != null) { 937 boolean isIncluded = false; 938 for (int r = 0; r < runAsPrincipalRoles.length; r++) { 939 if (runAsPrincipalRoles[r].equals(runAsRole)) { 940 isIncluded = true; 941 } 942 } 943 if (!isIncluded) { 944 throw new DeploymentDescException("The run-as roles defined for the runas principal name '" 945 + runAsPrincipalName + "' does not contains the run-as role '" 946 + runAsRole + "' in bean '" + getEjbName() + "."); 947 } 948 } 949 } 950 } 951 952 959 protected abstract void checkTxAttribute(MethodDesc md) throws DeploymentDescException; 960 961 969 protected void verifyRoleName(AssemblyDescriptor asd) throws DeploymentDescException { 970 boolean verify; 971 List methodPermission = asd.getMethodPermissionList(); 972 if (methodPermission != null) { 973 for (Iterator i = methodPermission.iterator(); i.hasNext();) { 974 MethodPermission mPermission = (MethodPermission) i.next(); 975 for (Iterator j = mPermission.getRoleNameList().iterator(); j.hasNext();) { 976 verify = false; 977 String mpRoleName = (String ) j.next(); 978 for (Iterator k = asd.getSecurityRoleList().iterator(); k.hasNext();) { 979 String srRoleName = ((SecurityRole) k.next()).getRoleName(); 980 if (mpRoleName.equals(srRoleName)) { 981 verify = true; 982 } 983 } 984 if (!verify) { 985 throw new DeploymentDescException( 986 "a method-permission element defined a role-name element \"" 987 + mpRoleName 988 + "\" which doesn't correspond to any security-role element of the Deployment Descriptor"); 989 } 990 } 991 } 992 } 993 } 994 995 1000 public String getEjbName() { 1001 return ejbName; 1002 } 1003 1004 1011 public String getJndiName() { 1012 return jndiName; 1013 } 1014 1015 1021 public String getJndiLocalName() { 1022 return jndiLocalName; 1023 } 1024 1025 1031 public Class getHomeClass() { 1032 return home; 1033 } 1034 1035 1041 public Class getRemoteClass() { 1042 return remote; 1043 } 1044 1045 1051 public Class getLocalHomeClass() { 1052 return localhome; 1053 } 1054 1055 1061 public Class getLocalClass() { 1062 return local; 1063 } 1064 1065 1070 public Class getEjbClass() { 1071 return ejbClass; 1072 } 1073 1074 1079 public Properties getEjb10Environment() { 1080 Properties ret = new Properties (ejb10EnvProps); 1081 return ret; 1082 } 1083 1084 1090 public MethodDesc getMethodDesc(java.lang.reflect.Method method) { 1091 1092 if (!methodDescMap.containsKey(method)) { 1093 throw new Error (method.getName() + " is not a method of home/remote interfaces for bean " + getEjbName()); 1094 } 1095 return (MethodDesc) methodDescMap.get(method); 1096 } 1097 1098 1103 public Iterator getMethodDescIterator() { 1104 return methodDesc.iterator(); 1105 } 1106 1107 1114 public MethodDesc getMethodDesc(int index) { 1115 return (MethodDesc) methodDesc.get(index); 1116 } 1117 1118 1124 public List getSecurityRoleRefDescList() { 1125 return securityRoleRefDescList; 1126 } 1127 1128 1131 public int getPoolMin() { 1132 return poolMin; 1133 } 1134 1135 1138 public int getCacheMax() { 1139 return cacheMax; 1140 } 1141 1142 1145 public String getRunAsRole() { 1146 return runAsRole; 1147 } 1148 1149 1152 public int getTimerTxAttribute() { 1153 return timerTxAttribute; 1154 } 1155 1156 1159 public String getEjbTimeoutSignature() { 1160 return ejbTimeoutSignature; 1161 } 1162 1163 1166 public BeanFactory getBeanFactory() { 1167 return bf; 1168 } 1169 1170 1174 public void setBeanFactory(BeanFactory factory) { 1175 bf = factory; 1176 } 1177 1178 1183 public String toString() { 1184 StringBuffer ret = new StringBuffer (); 1185 ret.append("\ngetDisplayName()=" + getDisplayName()); 1186 ret.append("\ngetEjbName()=" + getEjbName()); 1187 if (jndiName != null) { 1188 ret.append("\ngetJndiName()=" + getJndiName()); 1189 } 1190 if (home != null) { 1191 ret.append("\ngetHomeClass()=" + getHomeClass().toString()); 1192 } 1193 if (remote != null) { 1194 ret.append("\ngetRemoteClass()=" + getRemoteClass().toString()); 1195 } 1196 if (localhome != null) { 1197 ret.append("\ngetLocalHomeClass()=" + getLocalHomeClass().toString()); 1198 } 1199 if (local != null) { 1200 ret.append("\ngetLocalClass()=" + getLocalClass().toString()); 1201 } 1202 ret.append("\ngetEjbClass()=" + getEjbClass().toString()); 1203 EnvEntryDesc[] envE = getEnvEntryDesc(); 1204 for (int i = 0; i < envE.length; i++) { 1205 ret.append("\ngetEnvEntryDesc(" + i + ")=" + envE[i].toString()); 1206 } 1207 ServiceRefDesc[] sr = getServiceRefDesc(); 1208 for (int i = 0; i < sr.length; i++) { 1209 ret.append("\ngetServiceRefDesc(" + i + ")=" + sr[i].toString()); 1210 } 1211 ResourceEnvRefDesc[] resEnvR = getResourceEnvRefDesc(); 1212 for (int i = 0; i < resEnvR.length; i++) { 1213 ret.append("\ngetResourceEnvRefDesc(" + i + ")=" + resEnvR[i].toString()); 1214 } 1215 ResourceRefDesc[] resR = getResourceRefDesc(); 1216 for (int i = 0; i < resR.length; i++) { 1217 ret.append("\ngetResourceRefDesc(" + i + ")=" + resR[i].toString()); 1218 } 1219 EjbRefDesc[] ejbR = getEjbRefDesc(); 1220 for (int i = 0; i < ejbR.length; i++) { 1221 ret.append("\ngetEjbRefDesc(" + i + ")=" + ejbR[i].toString()); 1222 } 1223 EjbLocalRefDesc[] ejbLR = getEjbLocalRefDesc(); 1224 for (int i = 0; i < ejbLR.length; i++) { 1225 ret.append("\ngetEjbLocalRefDesc(" + i + ")=" + ejbLR[i].toString()); 1226 } 1227 MessageDestinationRefDesc[] mdR = getMessageDestinationRefDesc(); 1228 for (int i = 0; i < mdR.length; i++) { 1229 ret.append("\ngetMessageDestinationRefDesc(" + i + ")=" + mdR[i].toString()); 1230 } 1231 for (int i = 0; i < methodDesc.size(); i++) { 1232 MethodDesc md = (MethodDesc) methodDesc.get(i); 1233 ret.append("\ngetMethodDesc(" + i + ")=" + md.getClass().getName()); 1234 ret.append(md.toString()); 1235 } 1236 1237 if (securityRoleRefDescList != null) { 1238 for (Iterator i = securityRoleRefDescList.iterator(); i.hasNext();) { 1239 SecurityRoleRefDesc sRoleRefDesc = (SecurityRoleRefDesc) i.next(); 1240 ret.append("\nsecurity-role-ref, role-name = '" + sRoleRefDesc.getRoleName() + "', role-link = '" 1241 + sRoleRefDesc.getRoleLink() + "'"); 1242 } 1243 } 1244 ret.append("\ngetFullWrpRemoteName() = " + getFullWrpRemoteName()); 1245 ret.append("\ngetFullWrpHomeName() = " + getFullWrpHomeName()); 1246 ret.append("\ngetFullWrpLocalName() = " + getFullWrpLocalName()); 1247 ret.append("\ngetFullWrpLocalHomeName() = " + getFullWrpLocalHomeName()); 1248 ret.append("\ngetFullWrpHandleName() = " + getFullWrpHandleName()); 1249 ret.append("\ngetFullDerivedBeanName() = " + getFullDerivedBeanName()); 1250 ret.append("\ngetRunAsRole() = " + getRunAsRole()); 1251 return ret.toString(); 1252 } 1253 1254 1262 protected MethodDesc newMethodDescInstance(java.lang.reflect.Method meth, Class classDef, int index) { 1263 return new MethodDesc(this, meth, classDef, index); 1264 } 1265 1266 1273 protected MethodDesc addMethodDesc(java.lang.reflect.Method meth, Class classDef) { 1274 MethodDesc md = newMethodDescInstance(meth, classDef, methodDesc.size()); 1275 methodDesc.add(md); 1276 methodDescMap.put(meth, md); 1277 return md; 1278 } 1279 1280 1283 public String getFullWrpRemoteName() { 1284 return fullWrpRemoteName; 1285 } 1286 1287 1290 public String getFullWrpLocalName() { 1291 return fullWrpLocalName; 1292 } 1293 1294 1297 public String getWrpRemoteName() { 1298 return wrpRemoteName; 1299 } 1300 1301 1304 public String getWrpLocalName() { 1305 return wrpLocalName; 1306 } 1307 1308 1311 public String getFullWrpHandleName() { 1312 return fullWrpHandleName; 1313 } 1314 1315 1318 public String getWrpHandleName() { 1319 return wrpHandleName; 1320 } 1321 1322 1325 public String getFullWrpHomeName() { 1326 return fullWrpHomeName; 1327 } 1328 1329 1332 public String getFullWrpLocalHomeName() { 1333 return fullWrpLocalHomeName; 1334 } 1335 1336 1339 public String getWrpHomeName() { 1340 return wrpHomeName; 1341 } 1342 1343 1346 public String getWrpLocalHomeName() { 1347 return wrpLocalHomeName; 1348 } 1349 1350 1353 public String getFullDerivedBeanName() { 1354 return fullDerivedBeanName; 1355 } 1356 1357 1360 public String getDerivedBeanName() { 1361 return derivedBeanName; 1362 } 1363 1364 1367 public DeploymentDesc getDeploymentDesc() { 1368 return deploymentDesc; 1369 } 1370 1371 1376 public void setDeploymentDesc(DeploymentDesc deploymentDesc) { 1377 this.deploymentDesc = deploymentDesc; 1378 logger = deploymentDesc.getLogger(); 1379 } 1380 1381 1388 private void orderMethodDesc(ArrayList al, int begin, int length) { 1389 MethodDesc[] mds = new MethodDesc[length]; 1390 for (int i = 0; i < length; i++) { 1391 mds[i] = (MethodDesc) al.get(begin + i); 1392 } 1393 Arrays.sort(mds, 0, length, new MethodDescComparator()); 1394 for (int i = 0; i < length; i++) { 1395 al.set(begin + i, mds[i]); 1396 mds[i].setIndex(begin + i); 1397 } 1398 } 1399 1400 1403 private class MethodDescComparator implements Comparator { 1404 1405 1413 public int compare(Object o1, Object o2) { 1414 MethodDesc md1 = (MethodDesc) o1; 1415 MethodDesc md2 = (MethodDesc) o2; 1416 int res = md1.getMethod().getDeclaringClass().getName().compareTo( 1417 md2.getMethod().getDeclaringClass().getName()); 1418 if (res == 0) { 1419 res = md1.getMethod().getName().compareTo(md2.getMethod().getName()); 1420 if (res == 0) { 1421 Class [] p1 = md1.getMethod().getParameterTypes(); 1423 Class [] p2 = md2.getMethod().getParameterTypes(); 1424 res = p1.length - p2.length; 1425 if (res == 0) { 1426 for (int i = 0; i < p1.length && (res = p1[i].getName().compareTo(p2[i].getName())) == 0; i++) { 1428 } 1430 } 1431 } 1432 } 1433 return res; 1434 } 1435 } 1436 1437 1440 public String getRunAsPrincipalName() { 1441 return runAsPrincipalName; 1442 } 1443 1444 1447 public boolean hasDefinedLocalInterface() { 1448 if (localhome == null) { 1449 return false; 1450 } else { 1451 return (!"javax.ejb.EJBLocalHome".equals(localhome.getName())); 1452 } 1453 } 1454 1455 1459 private void processIorSecurityConfig(IorSecurityConfigMapping iorSecurityConfigMapping) { 1460 1461 TransportStruct transportStruct = new TransportStruct(); 1463 AsStruct asStruct = new AsStruct(); 1465 SasStruct sasStruct = new SasStruct(); 1467 1468 TransportConfigMapping transportConfigMapping = iorSecurityConfigMapping.getTransportConfig(); 1470 AsContextMapping asContextMapping = iorSecurityConfigMapping.getAsContext(); 1471 SasContextMapping sasContextMapping = iorSecurityConfigMapping.getSasContext(); 1472 1473 int targetRequires = 0; 1475 if (transportConfigMapping.getIntegrity().equals("required")) { 1476 targetRequires |= Integrity.value; 1477 } 1478 if (transportConfigMapping.getConfidentiality().equals("required")) { 1479 targetRequires |= Confidentiality.value; 1480 } 1481 if (transportConfigMapping.getEstablishTrustInClient().equals("required")) { 1482 targetRequires |= EstablishTrustInClient.value; 1483 } 1484 if (transportConfigMapping.getEstablishTrustInTarget().equals("required")) { 1485 targetRequires |= EstablishTrustInTarget.value; 1486 } 1487 transportStruct.setTargetRequires(targetRequires); 1488 1489 1490 int targetSupports = 0; 1492 if (transportConfigMapping.getIntegrity().equals("supported") || transportConfigMapping.getIntegrity().equals("required")) { 1493 targetSupports |= Integrity.value; 1494 } 1495 if (transportConfigMapping.getConfidentiality().equals("supported") || transportConfigMapping.getConfidentiality().equals("required")) { 1496 targetSupports |= Confidentiality.value; 1497 } 1498 if (transportConfigMapping.getEstablishTrustInClient().equals("supported") || transportConfigMapping.getEstablishTrustInClient().equals("required")) { 1499 targetSupports |= EstablishTrustInClient.value; 1500 } 1501 if (transportConfigMapping.getEstablishTrustInTarget().equals("supported") || transportConfigMapping.getEstablishTrustInTarget().equals("required")) { 1502 targetSupports |= EstablishTrustInTarget.value; 1503 } 1504 transportStruct.setTargetSupports(targetSupports); 1505 1506 1507 if (!asContextMapping.getAuthMethod().equals("none")) { 1509 asStruct.setTargetName(asContextMapping.getRealm()); 1510 asStruct.setTargetSupports(EstablishTrustInClient.value); 1511 if (asContextMapping.getRequired().equals("true")) { 1512 asStruct.setTargetRequires(EstablishTrustInClient.value); 1513 1514 } 1515 } 1516 1517 if (sasContextMapping.getCallerPropagation().equals("supported")) { 1519 sasStruct.enableGSSUPSupportedNamingMechanisms(); 1520 sasStruct.setSupportedIdentityTypes(ITTAbsent.value | ITTAnonymous.value | ITTPrincipalName.value | ITTX509CertChain.value | ITTDistinguishedName.value); 1521 sasStruct.setTargetSupports(IdentityAssertion.value); 1522 } 1523 1524 sasComponent = new SasComponent(transportStruct, asStruct, sasStruct); 1526 1527 1528 } 1529 1530 1533 public SasComponent getSasComponent() { 1534 return sasComponent; 1535 } 1536 1539 public void setSasComponent(SasComponent sasComponent) { 1540 this.sasComponent = sasComponent; 1541 } 1542} 1543 1544 | Popular Tags |