BeanDesc.java

00001 
00026 package org.objectweb.jonas_ejb.deployment.api;
00027 
00028 import java.lang.reflect.Modifier;
00029 import java.rmi.RemoteException;
00030 import java.util.ArrayList;
00031 import java.util.Arrays;
00032 import java.util.Comparator;
00033 import java.util.HashMap;
00034 import java.util.Iterator;
00035 import java.util.LinkedList;
00036 import java.util.List;
00037 import java.util.Properties;
00038 
00039 import org.omg.CSI.ITTAbsent;
00040 import org.omg.CSI.ITTAnonymous;
00041 import org.omg.CSI.ITTDistinguishedName;
00042 import org.omg.CSI.ITTPrincipalName;
00043 import org.omg.CSI.ITTX509CertChain;
00044 import org.omg.CSIIOP.Confidentiality;
00045 import org.omg.CSIIOP.EstablishTrustInClient;
00046 import org.omg.CSIIOP.EstablishTrustInTarget;
00047 import org.omg.CSIIOP.IdentityAssertion;
00048 import org.omg.CSIIOP.Integrity;
00049 
00050 import org.objectweb.carol.util.csiv2.SasComponent;
00051 import org.objectweb.carol.util.csiv2.struct.AsStruct;
00052 import org.objectweb.carol.util.csiv2.struct.SasStruct;
00053 import org.objectweb.carol.util.csiv2.struct.TransportStruct;
00054 
00055 import org.objectweb.jonas_ejb.container.BeanFactory;
00056 import org.objectweb.jonas_ejb.container.TraceEjb;
00057 import org.objectweb.jonas_ejb.deployment.xml.AsContextMapping;
00058 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
00059 import org.objectweb.jonas_ejb.deployment.xml.CommonEjb;
00060 import org.objectweb.jonas_ejb.deployment.xml.ContainerTransaction;
00061 import org.objectweb.jonas_ejb.deployment.xml.IorSecurityConfigMapping;
00062 import org.objectweb.jonas_ejb.deployment.xml.JonasCommonEjb;
00063 import org.objectweb.jonas_ejb.deployment.xml.Method;
00064 import org.objectweb.jonas_ejb.deployment.xml.MethodPermission;
00065 import org.objectweb.jonas_ejb.deployment.xml.SasContextMapping;
00066 import org.objectweb.jonas_ejb.deployment.xml.TransportConfigMapping;
00067 import org.objectweb.jonas_ejb.lib.BeanNaming;
00068 import org.objectweb.jonas_ejb.lib.JavaType;
00069 
00070 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
00071 import org.objectweb.jonas_lib.deployment.api.EjbLocalRefDesc;
00072 import org.objectweb.jonas_lib.deployment.api.EjbRefDesc;
00073 import org.objectweb.jonas_lib.deployment.api.EnvEntryDesc;
00074 import org.objectweb.jonas_lib.deployment.api.JndiEnvRefsGroupDesc;
00075 import org.objectweb.jonas_lib.deployment.api.MessageDestinationRefDesc;
00076 import org.objectweb.jonas_lib.deployment.api.ResourceEnvRefDesc;
00077 import org.objectweb.jonas_lib.deployment.api.ResourceRefDesc;
00078 import org.objectweb.jonas_lib.deployment.api.SecurityRoleRefDesc;
00079 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
00080 import org.objectweb.jonas_lib.deployment.xml.RunAs;
00081 import org.objectweb.jonas_lib.deployment.xml.SecurityRole;
00082 import org.objectweb.jonas_lib.deployment.xml.SecurityRoleRef;
00083 
00084 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
00085 
00086 import org.objectweb.util.monolog.api.BasicLevel;
00087 import org.objectweb.util.monolog.api.Logger;
00088 
00098 public abstract class BeanDesc extends JndiEnvRefsGroupDesc {
00099 
00103     protected static final int BEAN_TRANSACTION_TYPE = 1;
00104 
00108     protected static final int CONTAINER_TRANSACTION_TYPE = 2;
00109 
00110     protected static final String[] TRANS = {null, "BEAN_TRANSACTION_TYPE", "CONTAINER_TRANSACTION_TYPE"};
00111 
00112     private static final String ejb10PropertiesPrefix = "ejb10-properties/";
00113 
00117     private static final String REMOTEDEFAULTSUFFIX = "Home";
00118 
00123     private static final String LOCALDEFAULTSUFFIX = "_L";
00124 
00128     protected String ejbName = null;
00129 
00133     protected String jndiName = null;
00134 
00138     protected String jndiLocalName = null;
00139 
00143     protected Class home = null;
00144 
00148     protected Class remote = null;
00149 
00153     protected Class localhome = null;
00154 
00158     protected Class local = null;
00159 
00163     protected Class ejbClass = null;
00164 
00168     protected Properties ejb10EnvProps = new Properties();
00169 
00173     protected Logger logger = null;
00174 
00178     private ArrayList methodDesc = new ArrayList();
00179 
00183     private HashMap methodDescMap = new HashMap();
00184 
00188     protected List securityRoleRefDescList = null;
00189 
00193     protected DeploymentDesc deploymentDesc = null;
00194 
00198     private String fullWrpRemoteName = null;
00199 
00203     private String wrpRemoteName = null;
00204 
00208     private String fullWrpHomeName = null;
00209 
00213     private String wrpHomeName = null;
00214 
00218     private String fullWrpLocalName = null;
00219 
00223     private String wrpLocalName = null;
00224 
00228     private String fullWrpLocalHomeName = null;
00229 
00233     private String wrpLocalHomeName = null;
00234 
00238     private String fullWrpHandleName = null;
00239 
00243     private String wrpHandleName = null;
00244 
00248     protected String fullDerivedBeanName = null;
00249 
00253     protected String derivedBeanName = null;
00254 
00258     private String runAsRole = null;
00259 
00263     private String runAsPrincipalName = null;
00264 
00268     protected int poolMin = 0;
00269 
00273     protected int cacheMax = 0;
00274 
00278     private SasComponent sasComponent = null;
00279 
00280     protected int timerTxAttribute = MethodDesc.TX_REQUIRES_NEW; // default
00281 
00282     protected String ejbTimeoutSignature;
00283 
00287     protected BeanFactory bf = null;
00288 
00301     public BeanDesc(ClassLoader classLoader, CommonEjb ejb, JonasCommonEjb jonasEjb, AssemblyDescriptor asd,
00302             JLinkedList jMDRList, String fileName) throws DeploymentDescException {
00303 
00304         super(classLoader, ejb, jonasEjb, fileName);
00305         securityRoleRefDescList = new LinkedList();
00306         if (ejb.getEjbName() != null) {
00307             ejbName = ejb.getEjbName();
00308         } else {
00309             ejbName = null;
00310         }
00311 
00312         // If no value given specifically, we use ejbName+Home as JNDI name.
00313         if (jonasEjb.getJndiName() != null) {
00314             jndiName = jonasEjb.getJndiName();
00315         } else {
00316             jndiName = ejbName + REMOTEDEFAULTSUFFIX;
00317         }
00318         // If no value given specifically, we use jndiName+_L as JNDI local
00319         // name.
00320         if (jonasEjb.getJndiLocalName() != null) {
00321             jndiLocalName = jonasEjb.getJndiLocalName();
00322         } else {
00323             jndiLocalName = jndiName + LOCALDEFAULTSUFFIX;
00324         }
00325 
00326         // classes
00327         // --------------------------------------------------
00328         if (ejb.getHome() != null) {
00329             try {
00330                 this.home = classLoader.loadClass(ejb.getHome());
00331                 // check home extends javax.ejb.EJBHome
00332                 if (!javax.ejb.EJBHome.class.isAssignableFrom(this.home)) {
00333                     throw new DeploymentDescException("Home class '" + ejb.getHome()
00334                             + "' doesn't not extends javax.ejb.EJBHome");
00335                 }
00336             } catch (ClassNotFoundException e) {
00337                 throw new DeploymentDescException("Home class not found for bean " + ejbName, e);
00338             }
00339         }
00340 
00341         if (ejb.getRemote() != null) {
00342             try {
00343                 this.remote = classLoader.loadClass(ejb.getRemote());
00344                 // check remote extends javax.ejb.EJBObject
00345                 if (!javax.ejb.EJBObject.class.isAssignableFrom(this.remote)) {
00346                     throw new DeploymentDescException("Remote class '" + ejb.getRemote()
00347                             + "' doesn't not extends javax.ejb.EJBObject");
00348                 }
00349             } catch (ClassNotFoundException e) {
00350                 throw new DeploymentDescException("Remote class not found for bean " + ejbName, e);
00351             }
00352         }
00353 
00354         String localhomename = ejb.getLocalHome();
00355         // Note: Should do this only if bean is implied in a relation.
00356         if (localhomename == null && this instanceof EntityCmp2Desc) {
00357             localhomename = "javax.ejb.EJBLocalHome";
00358         }
00359         if (localhomename != null) {
00360             try {
00361                 this.localhome = classLoader.loadClass(localhomename);
00362                 // check localhome extends javax.ejb.EJBLocalHome
00363                 if (!javax.ejb.EJBLocalHome.class.isAssignableFrom(this.localhome)) {
00364                     throw new DeploymentDescException("LocalHome class '" + localhomename
00365                             + "' doesn't not extends javax.ejb.EJBLocalHome");
00366                 }
00367             } catch (ClassNotFoundException e) {
00368                 throw new DeploymentDescException("LocalHome class not found for bean " + ejbName, e);
00369             }
00370         }
00371 
00372         String localname = ejb.getLocal();
00373         // Note: Should do this only if bean is implied in a relation.
00374         if (localname == null && this instanceof EntityCmp2Desc) {
00375             localname = "javax.ejb.EJBLocalObject";
00376         }
00377         if (localname != null) {
00378             try {
00379                 this.local = classLoader.loadClass(localname);
00380                 // check local extends javax.ejb.EJBLocalObject
00381                 if (!javax.ejb.EJBLocalObject.class.isAssignableFrom(this.local)) {
00382                     throw new DeploymentDescException("Local class '" + localname
00383                             + "' doesn't not extends javax.ejb.EJBLocalObject");
00384                 }
00385             } catch (ClassNotFoundException e) {
00386                 throw new DeploymentDescException("Local class not found for bean " + ejbName, e);
00387             }
00388         }
00389 
00390         // permit to load service-endpoint class
00391         loadExtraClasses(ejb, classLoader);
00392 
00393         try {
00394             this.ejbClass = classLoader.loadClass(ejb.getEjbClass());
00395             // check ejb-class extends javax.ejb.EnterpriseBean
00396             if (!javax.ejb.EnterpriseBean.class.isAssignableFrom(this.ejbClass)) {
00397                 throw new DeploymentDescException("Ejb class '" + ejb.getEjbClass()
00398                         + "' doesn't not extends javax.ejb.EnterpriseBean");
00399             }
00400         } catch (ClassNotFoundException e) {
00401             throw new DeploymentDescException("Ejb class not found for bean " + ejbName, e);
00402         }
00403 
00404         // Set EJB 1.0 Environment properties from env entries
00405         EnvEntryDesc[] envt = getEnvEntryDesc();
00406         for (int i = 0; i < envt.length; i++) {
00407             if (envt[i].getName().startsWith(ejb10PropertiesPrefix)) {
00408                 String newName = envt[i].getName().substring(ejb10PropertiesPrefix.length());
00409                 String value = new String();
00410                 if (envt[i].hasValue()) {
00411                     value = envt[i].getValue().toString();
00412                 }
00413                 ejb10EnvProps.put(newName, value);
00414             }
00415         }
00416 
00417         // run-as
00418         if (ejb.getSecurityIdentity() != null) {
00419             RunAs runAsElem = ejb.getSecurityIdentity().getRunAs();
00420             if (runAsElem != null) {
00421                 String roleName = runAsElem.getRoleName();
00422                 if (roleName != null) {
00423                     runAsRole = roleName;
00424                     boolean runAsRoleFound = false;
00425                     for (Iterator j = asd.getSecurityRoleList().iterator(); j.hasNext();) {
00426                         SecurityRole securityRole = (SecurityRole) j.next();
00427                         // role name of a security-role element defined in the
00428                         // assembly descriptor
00429                         String r = securityRole.getRoleName();
00430                         if (r.equals(runAsRole)) {
00431                             runAsRoleFound = true;
00432                         }
00433                     }
00434                     //if there are no matching run-as and security-role
00435                     if (!runAsRoleFound) {
00436                         throw new DeploymentDescException("There is no security-role defined for the run-as role: "
00437                                 + runAsRole);
00438                     }
00439                 }
00440                 // Run-as principal name
00441                 runAsPrincipalName = jonasEjb.getRunAsPrincipalName();
00442                 // if no principal name set in JOnAS DD, set it to run-as role
00443                 if (runAsPrincipalName == null) {
00444                     runAsPrincipalName = runAsRole;
00445                 }
00446             }
00447         }
00448 
00449         // populate array with all methods
00450         try {
00451             java.lang.reflect.Method[] m;
00452             int beginIdx = methodDesc.size();
00453             int len = 0;
00454             if ((this.home != null) && (this.remote != null)) {
00455                 // session bean or entity bean with remote interface
00456                 m = this.home.getMethods();
00457                 for (int i = 0; i < m.length; i++) {
00458                     if (!m[i].getDeclaringClass().equals(javax.ejb.EJBHome.class)
00459                         || m[i].getName().equals("remove")) {
00460                         addMethodDesc(m[i]);
00461                         len++;
00462                         // check RemoteException is thrown
00463                         checkRemoteException(m[i], true);
00464                         /*
00465                          * // arguments and return types must be valid types for
00466                          * RMI if
00467                          * (!m[i].getDeclaringClass().equals(javax.ejb.EJBHome.class) &&
00468                          * !m[i].getName().equals("findByPrimaryKey")) {
00469                          * checkValidTypesForRmi(m[i]); }
00470                          */
00471                     }
00472                 }
00473 
00474                 m = this.remote.getMethods();
00475                 for (int i = 0; i < m.length; i++) {
00476                     if (!m[i].getDeclaringClass().equals(javax.ejb.EJBObject.class)
00477                         || m[i].getName().equals("remove")) {
00478                         addMethodDesc(m[i]);
00479                         len++;
00480                         // check RemoteException is thrown
00481                         checkRemoteException(m[i], true);
00482                         /*
00483                          * // arguments and return types must be valid for RMI
00484                          * if
00485                          * (!m[i].getDeclaringClass().equals(javax.ejb.EJBObject.class)) {
00486                          * checkValidTypesForRmi(m[i]); }
00487                          */
00488                     }
00489                 }
00490             }
00491             if ((this.localhome != null) && (this.local != null)) {
00492                 // session bean or entity bean with local interface
00493                 m = this.localhome.getMethods();
00494                 for (int i = 0; i < m.length; i++) {
00495                     if (!m[i].getDeclaringClass().equals(javax.ejb.EJBLocalHome.class)
00496                             || m[i].getName().equals("remove")) {
00497                         addMethodDesc(m[i]);
00498                         len++;
00499                         // check RemoteException is NOT thrown
00500                         checkRemoteException(m[i], false);
00501                     }
00502                 }
00503                 m = this.local.getMethods();
00504                 for (int i = 0; i < m.length; i++) {
00505                     if (!m[i].getDeclaringClass().equals(javax.ejb.EJBLocalObject.class)
00506                         || m[i].getName().equals("remove")) {
00507                         addMethodDesc(m[i]);
00508                         len++;
00509                         // check RemoteException is NOT thrown
00510                         checkRemoteException(m[i], false);
00511                     }
00512                 }
00513             }
00514             if (this.home == null && this.localhome == null) {
00515 
00516                 if (ejb.getMessagingType() != null) {
00517                     // message driven bean & endpoints
00518                     String msgType = ejb.getMessagingType();
00519                     try {
00520                         m = classLoader.loadClass(msgType).getMethods();
00521                         for (int i = 0; i < m.length; i++) {
00522                             addMethodDesc(m[i]);
00523                             len++;
00524                         }
00525                     } catch (Exception ex) {
00526                         throw new DeploymentDescException("Cannot load messaging type class (" + msgType + ") for "
00527                                 + ejbName);
00528                     }
00529                 }
00530                 // (web)service-endpoints may have no home or local-home too !!
00531             }
00532 
00533             if (javax.ejb.EntityBean.class.isAssignableFrom(this.ejbClass)) {
00534                 // ejbSelect methods
00535                 m = this.ejbClass.getMethods();
00536                 for (int i = 0; i < m.length; i++) {
00537                     if (m[i].getName().startsWith("ejbSelect") && Modifier.isAbstract(m[i].getModifiers())) {
00538                         addMethodDesc(m[i]);
00539                         len++;
00540                     }
00541                 }
00542             }
00543 
00544             if (javax.ejb.TimedObject.class.isAssignableFrom(this.ejbClass)) {
00545                 try {
00546                     java.lang.reflect.Method timeout = this.ejbClass.getMethod("ejbTimeout",
00547                             new Class[]{javax.ejb.Timer.class});
00548                     addMethodDesc(timeout);
00549                     len++;
00550                 } catch (NoSuchMethodException e) {
00551                     throw new DeploymentDescException("ejbTimeout not implemented in " + ejbName);
00552                 }
00553             }
00554 
00555             len = addEJBMethodDesc(len);
00556             orderMethodDesc(methodDesc, beginIdx, len);
00557         } catch (SecurityException e) {
00558             throw new DeploymentDescException("Cannot use java reflection on " + ejbName);
00559         }
00560 
00561         // populate HashMap with all security role references
00562         // for each security-role-ref of the bean
00563         if (ejb.getSecurityRoleRefList() != null) {
00564             for (Iterator i = ejb.getSecurityRoleRefList().iterator(); i.hasNext();) {
00565                 SecurityRoleRef sRoleRef = (SecurityRoleRef) i.next();
00566                 // test if the assembly-descriptor element exists
00567                 if (asd == null) {
00568                     throw new DeploymentDescException(
00569                             "No assembly-descriptor element (and security-role elements) whereas security-role-ref element(s) are defined");
00570                 } else {
00571                     // test if the assembly-descriptor element contains
00572                     // security-role elements
00573                     if (asd.getSecurityRoleList().isEmpty()) {
00574                         throw new DeploymentDescException(
00575                                 "No security-role elements defined in the assembly-descriptor element  whereas security-role-ref element(s) are defined");
00576                     }
00577                 }
00578                 // test if the role-link element of the security-role-ref
00579                 // element exists
00580                 if (sRoleRef.getRoleLink() == null) {
00581                     throw new DeploymentDescException(
00582                             "No role-link element in a security-role-ref element with role-name element : "
00583                                     + sRoleRef.getRoleName());
00584                 }
00585                 String roleLink = sRoleRef.getRoleLink();
00586                 // correspond to role-name element in security-role-ref element
00587                 String roleRefName = sRoleRef.getRoleName();
00588                 // to know if there are corresponding roleLink and roleRefName
00589                 boolean correspondingRoles = false;
00590                 for (Iterator j = asd.getSecurityRoleList().iterator(); j.hasNext();) {
00591                     SecurityRole securityRole = (SecurityRole) j.next();
00592                     // role name of a security-role element defined in the
00593                     // assembly descriptor
00594                     String roleName = securityRole.getRoleName();
00595                     if (roleName.equals(roleLink)) {
00596                         securityRoleRefDescList.add(new SecurityRoleRefDesc(ejbName, sRoleRef, true));
00597                         correspondingRoles = true;
00598                     }
00599                 }
00600                 //if there are no matching roleLink and roleName
00601                 if (!correspondingRoles) {
00602                     throw new DeploymentDescException(
00603                             "No corresponding role-name in a security-role element for role-link : " + roleLink);
00604                 }
00605             }
00606         }
00607 
00608         // check if there are corresponding role-name element in security-role
00609         // and method-permission element of the Assembly Descriptor
00610         if (asd != null) {
00611             verifyRoleName(asd);
00612             // set method descriptor values for method permissions
00613             for (Iterator i = asd.getMethodPermissionList().iterator(); i.hasNext();) {
00614                 MethodPermission methodPermission = (MethodPermission) i.next();
00615                 for (Iterator j = methodPermission.getMethodList().iterator(); j.hasNext();) {
00616                     Method m = ((Method) j.next());
00617                     // check method applies to current bean
00618                     if (!m.getEjbName().equals(ejbName)) {
00619                         continue;
00620                     }
00621                     // selection of interface home/remote
00622                     Class pClass = null;
00623                     if (m.getMethodIntf() != null) {
00624                         pClass = getParentClass(m.getMethodIntf());
00625                     }
00626                     for (int k = 0; k < methodDesc.size(); k++) {
00627                         MethodDesc md = (MethodDesc) methodDesc.get(k);
00628                         int matchStatus = md.matchPattern(pClass, m.getMethodName(), m.getMethodParams());
00629                         for (Iterator l = methodPermission.getRoleNameList().iterator(); l.hasNext();) {
00630                             String roleName = (String) l.next();
00631                             // Add only if it greater than APPLY_TO_NOTHING
00632                             if (matchStatus > MethodDesc.APPLY_TO_NOTHING) {
00633                                 md.addRoleName(roleName);
00634                             }
00635                         }
00636                     }
00637                 }
00638             }
00639         }
00640 
00641         // Set excluded method
00642         if (asd != null && asd.getExcludeList() != null) {
00643             // For each excluded method, find a methodDesc corresponding to this excluded method
00644             for (Iterator i = asd.getExcludeList().getMethodList().iterator(); i.hasNext();) {
00645                 Method m = (Method) i.next();
00646                 // check method applies to current bean
00647                 if (!m.getEjbName().equals(ejbName)) {
00648                     continue;
00649                 }
00650                 // selection of interface home/remote
00651                 Class pClass = null;
00652                 if (m.getMethodIntf() != null) {
00653                     pClass = getParentClass(m.getMethodIntf());
00654                 }
00655                 // Find methodDesc with matching pattern of excluded method
00656                 for (int k = 0; k < methodDesc.size(); k++) {
00657                     MethodDesc md = (MethodDesc) methodDesc.get(k);
00658                     int matchStatus = md.matchPattern(pClass, m.getMethodName(), m.getMethodParams());
00659                     // Add only if it greater than APPLY_TO_NOTHING
00660                     if (matchStatus > MethodDesc.APPLY_TO_NOTHING) {
00661                         md.setExcluded(true);
00662                     }
00663                 }
00664             }
00665         }
00666 
00667         // set method descriptor values for container transactions
00668         if (asd != null) {
00669             // Loop on ContainerTransaction list
00670             Iterator i = asd.getContainerTransactionList().iterator();
00671             while (i.hasNext()) {
00672                 ContainerTransaction cotr = (ContainerTransaction) i.next();
00673                 // Loop on Method list
00674                 Iterator j = cotr.getMethodList().iterator();
00675                 while (j.hasNext()) {
00676                     Method m = (Method) j.next();
00677                     // check method applies to current bean
00678                     if (!m.getEjbName().equals(ejbName)) {
00679                         continue;
00680                     }
00681 
00682                     // selection of interface home/remote
00683                     Class pClass = null;
00684                     if (m.getMethodIntf() != null) {
00685                         pClass = getParentClass(m.getMethodIntf());
00686                     }
00687 
00688                     // loop on methods in the array
00689                     boolean found = false;
00690                     for (int k = 0; k < methodDesc.size(); k++) {
00691                         MethodDesc md = (MethodDesc) methodDesc.get(k);
00692                         int matchStatus = md.matchPattern(pClass, m.getMethodName(), m.getMethodParams());
00693                         if (matchStatus != MethodDesc.APPLY_TO_NOTHING) {
00694                             found = true;
00695                         }
00696                         // set if proper level of assignation
00697                         String transAttribute = null;
00698                         if (cotr.getTransAttribute() != null) {
00699                             transAttribute = cotr.getTransAttribute();
00700                         }
00701                         md.overwriteTxAttribute(transAttribute, matchStatus);
00702                     }
00703                     if (!found) {
00704                         // The method defined via the <method> element is not a
00705                         // declared method
00706                         TraceEjb.dd.log(BasicLevel.WARN, "Invalid container-transaction: method '"
00707                                 + MethodDesc.methodElementToString(m) + "' not declared in bean " + ejbName);
00708                     }
00709                 }
00710             }
00711         }
00712 
00713         String packageName = "";
00714         String ejbIdentifier = getIdentifier();
00715 
00716         if (getRemoteClass() != null) {
00717             packageName = BeanNaming.getPackageName(getRemoteClass().getName());
00718             wrpRemoteName = new String("JOnAS" + ejbIdentifier + "Remote");
00719             wrpHandleName = new String("JOnAS" + ejbIdentifier + "Handle");
00720             fullWrpRemoteName = BeanNaming.getClassName(packageName, wrpRemoteName);
00721             fullWrpHandleName = BeanNaming.getClassName(packageName, wrpHandleName);
00722         }
00723 
00724         if (getLocalClass() != null) {
00725             packageName = BeanNaming.getPackageName(getLocalClass().getName());
00726             wrpLocalName = new String("JOnAS" + ejbIdentifier + "Local");
00727             fullWrpLocalName = BeanNaming.getClassName(packageName, wrpLocalName);
00728         }
00729 
00730         if (getHomeClass() != null) {
00731             packageName = BeanNaming.getPackageName(getHomeClass().getName());
00732             wrpHomeName = new String("JOnAS" + ejbIdentifier + "Home");
00733             fullWrpHomeName = BeanNaming.getClassName(packageName, wrpHomeName);
00734         }
00735 
00736         if (getLocalHomeClass() != null) {
00737             packageName = BeanNaming.getPackageName(getLocalHomeClass().getName());
00738             wrpLocalHomeName = new String("JOnAS" + ejbIdentifier + "LocalHome");
00739             fullWrpLocalHomeName = BeanNaming.getClassName(packageName, wrpLocalHomeName);
00740         }
00741 
00742         fullDerivedBeanName = getEjbClass().getName();
00743         derivedBeanName = BeanNaming.getBaseName(getEjbClass().getName());
00744 
00745         IorSecurityConfigMapping iorSecurityConfigMapping = jonasEjb.getIorSecurityConfig();
00746         if (iorSecurityConfigMapping != null) {
00747             processIorSecurityConfig(iorSecurityConfigMapping);
00748         }
00749 
00750     }
00751 
00761     protected void loadExtraClasses(CommonEjb ce, ClassLoader loader) throws DeploymentDescException {
00762         // do nothing by default
00763     }
00764 
00775     protected int addEJBMethodDesc(int len) throws DeploymentDescException {
00776         return len;
00777     }
00778 
00789     protected Class getParentClass(String intfType) throws DeploymentDescException {
00790         Class pClass = null;
00791         if (intfType.equals("Home")) {
00792             pClass = javax.ejb.EJBHome.class;
00793         } else if (intfType.equals("Remote")) {
00794             pClass = javax.ejb.EJBObject.class;
00795         } else if (intfType.equals("LocalHome")) {
00796             pClass = javax.ejb.EJBLocalHome.class;
00797         } else if (intfType.equals("Local")) {
00798             pClass = javax.ejb.EJBLocalObject.class;
00799         } else {
00800             throw new DeploymentDescException(intfType + " is invalid value for method-intf on bean " + ejbName);
00801         }
00802         return pClass;
00803     }
00804 
00810     protected String getHashCodeForIdentifier() {
00811         String hash = "";
00812         if (getJndiName() != null) {
00813             hash += getJndiName();
00814         }
00815         if (getJndiLocalName() != null) {
00816             hash += getJndiLocalName();
00817         }
00818         return Integer.toString(hash.hashCode());
00819     }
00820 
00825     protected String getIdentifier() {
00826 
00827         String identifier = getEjbName();
00828         identifier += getHashCodeForIdentifier();
00829 
00830         char[] tabChar = new char[identifier.length()];
00831         for (int i = 0; i < identifier.length(); i++) {
00832             if (!Character.isJavaIdentifierPart(identifier.charAt(i))) {
00833                 tabChar[i] = '_';
00834             } else {
00835                 tabChar[i] = identifier.charAt(i);
00836             }
00837         }
00838         return new String(tabChar);
00839     }
00840 
00850     public void checkRemoteException(java.lang.reflect.Method m, boolean shouldThrow) throws DeploymentDescException {
00851         Class[] excepts = m.getExceptionTypes();
00852         for (int j = 0; j < excepts.length; j++) {
00853             if (RemoteException.class.isAssignableFrom(excepts[j])) {
00854                 if (shouldThrow) {
00855                     return;
00856                 } else {
00857                     throw new DeploymentDescException("Method " + m.getName() + " of " + m.getDeclaringClass()
00858                             + " should NOT throw RemoteException");
00859                 }
00860             }
00861         }
00862         if (shouldThrow) {
00863             throw new DeploymentDescException("Method " + m.getName() + " of " + m.getDeclaringClass()
00864                     + " must throw RemoteException");
00865         } else {
00866             return;
00867         }
00868 
00869     }
00870 
00879     public void checkValidTypesForRmi(java.lang.reflect.Method m) {
00880         boolean isValid = true;
00881         Class[] paramTypes = m.getParameterTypes();
00882         for (int i = 0; i < paramTypes.length; i++) {
00883             if (!JavaType.isValidForRmi(paramTypes[i])) {
00884                 isValid = false;
00885             }
00886         }
00887         if (!JavaType.isValidForRmi(m.getReturnType()) && !JavaType.isVoid(m.getReturnType())
00888                 && !JavaType.isCollecOrEnum(m.getReturnType())) {
00889             // Allow Collection or Enumeration type (finder methods)
00890             isValid = false;
00891         }
00892         if (!isValid) {
00893             // TODO the trace of this warning uses a static variable into
00894             // TraceEjb class
00895             // because this.logger is not yet initialized
00896             TraceEjb.dd.log(BasicLevel.WARN, "Method " + m.getName() + " of " + m.getDeclaringClass()
00897                     + " may be have an invalid argument or return type for RMI");
00898         }
00899     }
00900 
00906     public void check() throws DeploymentDescException {
00907         // check business methods transaction attribute
00908         for (int i = 0; i < methodDesc.size(); i++) {
00909             checkTxAttribute(((MethodDesc) methodDesc.get(i)));
00910         }
00911         checkRunAsMapping();
00912     }
00913 
00918     public void checkRunAsMapping() throws DeploymentDescException {
00919         if (runAsPrincipalName != null) {
00920             // verify roles of run-as principal name
00921             String[] runAsPrincipalRoles = deploymentDesc.getRolesForRunAsPrincipal(runAsPrincipalName);
00922             // Check that the run-as role is included in principal roles
00923             if (runAsPrincipalRoles != null) {
00924                 boolean isIncluded = false;
00925                 for (int r = 0; r < runAsPrincipalRoles.length; r++) {
00926                     if (runAsPrincipalRoles[r].equals(runAsRole)) {
00927                         isIncluded = true;
00928                     }
00929                 }
00930                 if (!isIncluded) {
00931                     throw new DeploymentDescException("The run-as roles defined for the runas principal name '"
00932                             + runAsPrincipalName + "' does not contains the run-as role '"
00933                             + runAsRole + "' in bean '" + getEjbName() + ".");
00934                 }
00935             }
00936         }
00937     }
00938 
00946     protected abstract void checkTxAttribute(MethodDesc md) throws DeploymentDescException;
00947 
00956     protected void verifyRoleName(AssemblyDescriptor asd) throws DeploymentDescException {
00957         boolean verify;
00958         List methodPermission = asd.getMethodPermissionList();
00959         if (methodPermission != null) {
00960             for (Iterator i = methodPermission.iterator(); i.hasNext();) {
00961                 MethodPermission mPermission = (MethodPermission) i.next();
00962                 for (Iterator j = mPermission.getRoleNameList().iterator(); j.hasNext();) {
00963                     verify = false;
00964                     String mpRoleName = (String) j.next();
00965                     for (Iterator k = asd.getSecurityRoleList().iterator(); k.hasNext();) {
00966                         String srRoleName = ((SecurityRole) k.next()).getRoleName();
00967                         if (mpRoleName.equals(srRoleName)) {
00968                             verify = true;
00969                         }
00970                     }
00971                     if (!verify) {
00972                         throw new DeploymentDescException(
00973                                 "a method-permission element defined a role-name element \""
00974                                         + mpRoleName
00975                                         + "\" which doesn't correspond to any security-role element of the Deployment Descriptor");
00976                     }
00977                 }
00978             }
00979         }
00980     }
00981 
00987     public String getEjbName() {
00988         return ejbName;
00989     }
00990 
00998     public String getJndiName() {
00999         return jndiName;
01000     }
01001 
01008     public String getJndiLocalName() {
01009         return jndiLocalName;
01010     }
01011 
01018     public Class getHomeClass() {
01019         return home;
01020     }
01021 
01028     public Class getRemoteClass() {
01029         return remote;
01030     }
01031 
01038     public Class getLocalHomeClass() {
01039         return localhome;
01040     }
01041 
01048     public Class getLocalClass() {
01049         return local;
01050     }
01051 
01057     public Class getEjbClass() {
01058         return ejbClass;
01059     }
01060 
01066     public Properties getEjb10Environment() {
01067         Properties ret = new Properties(ejb10EnvProps);
01068         return ret;
01069     }
01070 
01077     public MethodDesc getMethodDesc(java.lang.reflect.Method method) {
01078 
01079         if (!methodDescMap.containsKey(method)) {
01080             throw new Error(method.getName() + " is not a method of home/remote interfaces for bean " + getEjbName());
01081         }
01082         return (MethodDesc) methodDescMap.get(method);
01083     }
01084 
01090     public Iterator getMethodDescIterator() {
01091         return methodDesc.iterator();
01092     }
01093 
01101     public MethodDesc getMethodDesc(int index) {
01102         return (MethodDesc) methodDesc.get(index);
01103     }
01104 
01111     public List getSecurityRoleRefDescList() {
01112         return securityRoleRefDescList;
01113     }
01114 
01118     public int getPoolMin() {
01119         return poolMin;
01120     }
01121 
01125     public int getCacheMax() {
01126         return cacheMax;
01127     }
01128 
01132     public String getRunAsRole() {
01133         return runAsRole;
01134     }
01135 
01139     public int getTimerTxAttribute() {
01140         return timerTxAttribute;
01141     }
01142 
01146     public String getEjbTimeoutSignature() {
01147         return ejbTimeoutSignature;
01148     }
01149 
01153     public BeanFactory getBeanFactory() {
01154         return bf;
01155     }
01156 
01161     public void setBeanFactory(BeanFactory factory) {
01162         bf = factory;
01163     }
01164 
01170     public String toString() {
01171         StringBuffer ret = new StringBuffer();
01172         ret.append("\ngetDisplayName()=" + getDisplayName());
01173         ret.append("\ngetEjbName()=" + getEjbName());
01174         if (jndiName != null) {
01175             ret.append("\ngetJndiName()=" + getJndiName());
01176         }
01177         if (home != null) {
01178             ret.append("\ngetHomeClass()=" + getHomeClass().toString());
01179         }
01180         if (remote != null) {
01181             ret.append("\ngetRemoteClass()=" + getRemoteClass().toString());
01182         }
01183         if (localhome != null) {
01184             ret.append("\ngetLocalHomeClass()=" + getLocalHomeClass().toString());
01185         }
01186         if (local != null) {
01187             ret.append("\ngetLocalClass()=" + getLocalClass().toString());
01188         }
01189         ret.append("\ngetEjbClass()=" + getEjbClass().toString());
01190         EnvEntryDesc[] envE = getEnvEntryDesc();
01191         for (int i = 0; i < envE.length; i++) {
01192             ret.append("\ngetEnvEntryDesc(" + i + ")=" + envE[i].toString());
01193         }
01194         ServiceRefDesc[] sr = getServiceRefDesc();
01195         for (int i = 0; i < sr.length; i++) {
01196             ret.append("\ngetServiceRefDesc(" + i + ")=" + sr[i].toString());
01197         }
01198         ResourceEnvRefDesc[] resEnvR = getResourceEnvRefDesc();
01199         for (int i = 0; i < resEnvR.length; i++) {
01200             ret.append("\ngetResourceEnvRefDesc(" + i + ")=" + resEnvR[i].toString());
01201         }
01202         ResourceRefDesc[] resR = getResourceRefDesc();
01203         for (int i = 0; i < resR.length; i++) {
01204             ret.append("\ngetResourceRefDesc(" + i + ")=" + resR[i].toString());
01205         }
01206         EjbRefDesc[] ejbR = getEjbRefDesc();
01207         for (int i = 0; i < ejbR.length; i++) {
01208             ret.append("\ngetEjbRefDesc(" + i + ")=" + ejbR[i].toString());
01209         }
01210         EjbLocalRefDesc[] ejbLR = getEjbLocalRefDesc();
01211         for (int i = 0; i < ejbLR.length; i++) {
01212             ret.append("\ngetEjbLocalRefDesc(" + i + ")=" + ejbLR[i].toString());
01213         }
01214         MessageDestinationRefDesc[] mdR = getMessageDestinationRefDesc();
01215         for (int i = 0; i < mdR.length; i++) {
01216             ret.append("\ngetMessageDestinationRefDesc(" + i + ")=" + mdR[i].toString());
01217         }
01218         for (int i = 0; i < methodDesc.size(); i++) {
01219             MethodDesc md = (MethodDesc) methodDesc.get(i);
01220             ret.append("\ngetMethodDesc(" + i + ")=" + md.getClass().getName());
01221             ret.append(md.toString());
01222         }
01223 
01224         if (securityRoleRefDescList != null) {
01225             for (Iterator i = securityRoleRefDescList.iterator(); i.hasNext();) {
01226                 SecurityRoleRefDesc sRoleRefDesc = (SecurityRoleRefDesc) i.next();
01227                 ret.append("\nsecurity-role-ref, role-name = '" + sRoleRefDesc.getRoleName() + "', role-link = '"
01228                         + sRoleRefDesc.getRoleLink() + "'");
01229             }
01230         }
01231         ret.append("\ngetFullWrpRemoteName() = " + getFullWrpRemoteName());
01232         ret.append("\ngetFullWrpHomeName() = " + getFullWrpHomeName());
01233         ret.append("\ngetFullWrpLocalName() = " + getFullWrpLocalName());
01234         ret.append("\ngetFullWrpLocalHomeName() = " + getFullWrpLocalHomeName());
01235         ret.append("\ngetFullWrpHandleName() = " + getFullWrpHandleName());
01236         ret.append("\ngetFullDerivedBeanName() = " + getFullDerivedBeanName());
01237         ret.append("\ngetRunAsRole() = " + getRunAsRole());
01238         return ret.toString();
01239     }
01240 
01249     protected MethodDesc newMethodDescInstance(java.lang.reflect.Method meth, int index) {
01250         return new MethodDesc(this, meth, index);
01251     }
01252 
01260     protected MethodDesc addMethodDesc(java.lang.reflect.Method meth) {
01261         MethodDesc md = newMethodDescInstance(meth, methodDesc.size());
01262         methodDesc.add(md);
01263         methodDescMap.put(meth, md);
01264         return md;
01265     }
01266 
01270     public String getFullWrpRemoteName() {
01271         return fullWrpRemoteName;
01272     }
01273 
01277     public String getFullWrpLocalName() {
01278         return fullWrpLocalName;
01279     }
01280 
01284     public String getWrpRemoteName() {
01285         return wrpRemoteName;
01286     }
01287 
01291     public String getWrpLocalName() {
01292         return wrpLocalName;
01293     }
01294 
01298     public String getFullWrpHandleName() {
01299         return fullWrpHandleName;
01300     }
01301 
01305     public String getWrpHandleName() {
01306         return wrpHandleName;
01307     }
01308 
01312     public String getFullWrpHomeName() {
01313         return fullWrpHomeName;
01314     }
01315 
01319     public String getFullWrpLocalHomeName() {
01320         return fullWrpLocalHomeName;
01321     }
01322 
01326     public String getWrpHomeName() {
01327         return wrpHomeName;
01328     }
01329 
01333     public String getWrpLocalHomeName() {
01334         return wrpLocalHomeName;
01335     }
01336 
01340     public String getFullDerivedBeanName() {
01341         return fullDerivedBeanName;
01342     }
01343 
01347     public String getDerivedBeanName() {
01348         return derivedBeanName;
01349     }
01350 
01354     public DeploymentDesc getDeploymentDesc() {
01355         return deploymentDesc;
01356     }
01357 
01363     public void setDeploymentDesc(DeploymentDesc deploymentDesc) {
01364         this.deploymentDesc = deploymentDesc;
01365         logger = deploymentDesc.getLogger();
01366     }
01367 
01375     private void orderMethodDesc(ArrayList al, int begin, int length) {
01376         MethodDesc[] mds = new MethodDesc[length];
01377         for (int i = 0; i < length; i++) {
01378             mds[i] = (MethodDesc) al.get(begin + i);
01379         }
01380         Arrays.sort(mds, 0, length, new MethodDescComparator());
01381         for (int i = 0; i < length; i++) {
01382             al.set(begin + i, mds[i]);
01383             mds[i].setIndex(begin + i);
01384         }
01385     }
01386 
01390     private class MethodDescComparator implements Comparator {
01391 
01400         public int compare(Object o1, Object o2) {
01401             MethodDesc md1 = (MethodDesc) o1;
01402             MethodDesc md2 = (MethodDesc) o2;
01403             int res = md1.getMethod().getDeclaringClass().getName().compareTo(
01404                     md2.getMethod().getDeclaringClass().getName());
01405             if (res == 0) {
01406                 res = md1.getMethod().getName().compareTo(md2.getMethod().getName());
01407                 if (res == 0) {
01408                     // Same method name => compare the parameter types
01409                     Class[] p1 = md1.getMethod().getParameterTypes();
01410                     Class[] p2 = md2.getMethod().getParameterTypes();
01411                     res = p1.length - p2.length;
01412                     if (res == 0) {
01413                         //Same parameter size
01414                         for (int i = 0; i < p1.length && (res = p1[i].getName().compareTo(p2[i].getName())) == 0; i++) {
01415                             // compare each method
01416                         }
01417                     }
01418                 }
01419             }
01420             return res;
01421         }
01422     }
01423 
01427     public String getRunAsPrincipalName() {
01428         return runAsPrincipalName;
01429     }
01430 
01434     public boolean hasDefinedLocalInterface() {
01435         if (localhome == null) {
01436             return false;
01437         } else {
01438             return (!"javax.ejb.EJBLocalHome".equals(localhome.getName()));
01439         }
01440     }
01441 
01446     private void processIorSecurityConfig(IorSecurityConfigMapping iorSecurityConfigMapping) {
01447 
01448         // Transport
01449         TransportStruct transportStruct = new TransportStruct();
01450         // As
01451         AsStruct asStruct = new AsStruct();
01452         // Sas
01453         SasStruct sasStruct = new SasStruct();
01454 
01455         // Now fill SasComponent with given ior values
01456         TransportConfigMapping transportConfigMapping = iorSecurityConfigMapping.getTransportConfig();
01457         AsContextMapping asContextMapping = iorSecurityConfigMapping.getAsContext();
01458         SasContextMapping sasContextMapping = iorSecurityConfigMapping.getSasContext();
01459 
01460         // target requires (if required)
01461         int targetRequires = 0;
01462         if (transportConfigMapping.getIntegrity().equals("required")) {
01463             targetRequires |=  Integrity.value;
01464         }
01465         if (transportConfigMapping.getConfidentiality().equals("required")) {
01466             targetRequires |=  Confidentiality.value;
01467         }
01468         if (transportConfigMapping.getEstablishTrustInClient().equals("required")) {
01469             targetRequires |=  EstablishTrustInClient.value;
01470         }
01471         if (transportConfigMapping.getEstablishTrustInTarget().equals("required")) {
01472             targetRequires |=  EstablishTrustInTarget.value;
01473         }
01474         transportStruct.setTargetRequires(targetRequires);
01475 
01476 
01477         // target supports (supported or required)
01478         int targetSupports = 0;
01479         if (transportConfigMapping.getIntegrity().equals("supported") || transportConfigMapping.getIntegrity().equals("required")) {
01480             targetSupports |=  Integrity.value;
01481         }
01482         if (transportConfigMapping.getConfidentiality().equals("supported") || transportConfigMapping.getConfidentiality().equals("required")) {
01483             targetSupports |=  Confidentiality.value;
01484         }
01485         if (transportConfigMapping.getEstablishTrustInClient().equals("supported") || transportConfigMapping.getEstablishTrustInClient().equals("required")) {
01486             targetSupports |=  EstablishTrustInClient.value;
01487         }
01488         if (transportConfigMapping.getEstablishTrustInTarget().equals("supported") || transportConfigMapping.getEstablishTrustInTarget().equals("required")) {
01489             targetSupports |=  EstablishTrustInTarget.value;
01490         }
01491         transportStruct.setTargetSupports(targetSupports);
01492 
01493 
01494         // As struct (if it is needed)
01495         if (!asContextMapping.getAuthMethod().equals("none")) {
01496             asStruct.setTargetName(asContextMapping.getRealm());
01497             asStruct.setTargetSupports(EstablishTrustInClient.value);
01498             if (asContextMapping.getRequired().equals("true")) {
01499                 asStruct.setTargetRequires(EstablishTrustInClient.value);
01500 
01501             }
01502         }
01503 
01504         // Sas struct (if supported)
01505         if (sasContextMapping.getCallerPropagation().equals("supported")) {
01506             sasStruct.enableGSSUPSupportedNamingMechanisms();
01507             sasStruct.setSupportedIdentityTypes(ITTAbsent.value | ITTAnonymous.value | ITTPrincipalName.value | ITTX509CertChain.value | ITTDistinguishedName.value);
01508             sasStruct.setTargetSupports(IdentityAssertion.value);
01509         }
01510 
01511         // and then, set our SAS component
01512         sasComponent = new SasComponent(transportStruct, asStruct, sasStruct);
01513 
01514 
01515     }
01516 
01520     public SasComponent getSasComponent() {
01521         return sasComponent;
01522     }
01526     public void setSasComponent(SasComponent sasComponent) {
01527         this.sasComponent = sasComponent;
01528     }
01529 }
01530 

Generated on Tue Feb 15 15:05:43 2005 for JOnAS by  doxygen 1.3.9.1