0001: /**
0002: * JOnAS: Java(TM) Open Application Server
0003: * Copyright (C) 1999-2006 Bull S.A.
0004: * Contact: jonas-team@objectweb.org
0005: *
0006: * This library is free software; you can redistribute it and/or
0007: * modify it under the terms of the GNU Lesser General Public
0008: * License as published by the Free Software Foundation; either
0009: * version 2.1 of the License, or any later version.
0010: *
0011: * This library is distributed in the hope that it will be useful,
0012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0014: * Lesser General Public License for more details.
0015: *
0016: * You should have received a copy of the GNU Lesser General Public
0017: * License along with this library; if not, write to the Free Software
0018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
0019: * USA
0020: *
0021: * --------------------------------------------------------------------------
0022: * $Id: BeanDesc.java 9540 2006-09-06 12:08:56Z benoitf $
0023: * --------------------------------------------------------------------------
0024: */package org.objectweb.jonas_ejb.deployment.api;
0025:
0026: import java.lang.reflect.Modifier;
0027: import java.rmi.RemoteException;
0028: import java.util.ArrayList;
0029: import java.util.Arrays;
0030: import java.util.Comparator;
0031: import java.util.HashMap;
0032: import java.util.Iterator;
0033: import java.util.LinkedList;
0034: import java.util.List;
0035: import java.util.Properties;
0036:
0037: import org.omg.CSI.ITTAbsent;
0038: import org.omg.CSI.ITTAnonymous;
0039: import org.omg.CSI.ITTDistinguishedName;
0040: import org.omg.CSI.ITTPrincipalName;
0041: import org.omg.CSI.ITTX509CertChain;
0042: import org.omg.CSIIOP.Confidentiality;
0043: import org.omg.CSIIOP.EstablishTrustInClient;
0044: import org.omg.CSIIOP.EstablishTrustInTarget;
0045: import org.omg.CSIIOP.IdentityAssertion;
0046: import org.omg.CSIIOP.Integrity;
0047:
0048: import org.objectweb.carol.util.csiv2.SasComponent;
0049: import org.objectweb.carol.util.csiv2.struct.AsStruct;
0050: import org.objectweb.carol.util.csiv2.struct.SasStruct;
0051: import org.objectweb.carol.util.csiv2.struct.TransportStruct;
0052:
0053: import org.objectweb.jonas_ejb.container.BeanFactory;
0054: import org.objectweb.jonas_ejb.container.TraceEjb;
0055: import org.objectweb.jonas_ejb.deployment.xml.AsContextMapping;
0056: import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
0057: import org.objectweb.jonas_ejb.deployment.xml.CommonEjb;
0058: import org.objectweb.jonas_ejb.deployment.xml.ContainerTransaction;
0059: import org.objectweb.jonas_ejb.deployment.xml.IorSecurityConfigMapping;
0060: import org.objectweb.jonas_ejb.deployment.xml.JonasCommonEjb;
0061: import org.objectweb.jonas_ejb.deployment.xml.Method;
0062: import org.objectweb.jonas_ejb.deployment.xml.MethodPermission;
0063: import org.objectweb.jonas_ejb.deployment.xml.SasContextMapping;
0064: import org.objectweb.jonas_ejb.deployment.xml.TransportConfigMapping;
0065: import org.objectweb.jonas_ejb.lib.BeanNaming;
0066: import org.objectweb.jonas_ejb.lib.JavaType;
0067:
0068: import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
0069: import org.objectweb.jonas_lib.deployment.api.EjbLocalRefDesc;
0070: import org.objectweb.jonas_lib.deployment.api.EjbRefDesc;
0071: import org.objectweb.jonas_lib.deployment.api.EnvEntryDesc;
0072: import org.objectweb.jonas_lib.deployment.api.JndiEnvRefsGroupDesc;
0073: import org.objectweb.jonas_lib.deployment.api.MessageDestinationRefDesc;
0074: import org.objectweb.jonas_lib.deployment.api.ResourceEnvRefDesc;
0075: import org.objectweb.jonas_lib.deployment.api.ResourceRefDesc;
0076: import org.objectweb.jonas_lib.deployment.api.SecurityRoleRefDesc;
0077: import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
0078: import org.objectweb.jonas_lib.deployment.xml.RunAs;
0079: import org.objectweb.jonas_lib.deployment.xml.SecurityRole;
0080: import org.objectweb.jonas_lib.deployment.xml.SecurityRoleRef;
0081:
0082: import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
0083:
0084: import org.objectweb.util.monolog.api.BasicLevel;
0085: import org.objectweb.util.monolog.api.Logger;
0086:
0087: /**
0088: * Class to hold meta-information related to any enterprise-beans
0089: *
0090: * @author Christophe Ney [cney@batisseurs.com] : Initial developer
0091: * @author Helene Joanin
0092: * @author Jeff Mesnil
0093: * @author Philippe Coq
0094: * @author Florent Benoit & Ludovic Bert : ejb_link
0095: */
0096: public abstract class BeanDesc extends JndiEnvRefsGroupDesc {
0097:
0098: /**
0099: * Bean transaction type
0100: */
0101: protected static final int BEAN_TRANSACTION_TYPE = 1;
0102:
0103: /**
0104: * Container transaction type
0105: */
0106: protected static final int CONTAINER_TRANSACTION_TYPE = 2;
0107:
0108: protected static final String[] TRANS = { null,
0109: "BEAN_TRANSACTION_TYPE", "CONTAINER_TRANSACTION_TYPE" };
0110:
0111: private static final String ejb10PropertiesPrefix = "ejb10-properties/";
0112:
0113: /**
0114: * When no jndi-name specified, jndi name is set to Ejb-Name + "Home"
0115: */
0116: private static final String REMOTEDEFAULTSUFFIX = "Home";
0117:
0118: /**
0119: * When no local-jndi-name specified, local jndi name is set to jndi-name +
0120: * "_L"
0121: */
0122: private static final String LOCALDEFAULTSUFFIX = "_L";
0123:
0124: /**
0125: * Package prefix for generated files
0126: */
0127: public static final String GENERATED_PREFIX = "org.objectweb.jonas_gen.";
0128:
0129: /**
0130: * name of the Bean
0131: */
0132: protected String ejbName = null;
0133:
0134: /**
0135: * JNDI name of the Bean
0136: */
0137: protected String jndiName = null;
0138:
0139: /**
0140: * JNDI local name of the Bean
0141: */
0142: protected String jndiLocalName = null;
0143:
0144: /**
0145: * Home Class
0146: */
0147: protected Class home = null;
0148:
0149: /**
0150: * Remote Class
0151: */
0152: protected Class remote = null;
0153:
0154: /**
0155: * LocalHome Class
0156: */
0157: protected Class localhome = null;
0158:
0159: /**
0160: * Local Class
0161: */
0162: protected Class local = null;
0163:
0164: /**
0165: * Bean Class
0166: */
0167: protected Class ejbClass = null;
0168:
0169: /**
0170: * bean identification string
0171: */
0172: protected String beanIdentification = null;
0173:
0174: /**
0175: * EJB 1.0 Environment as Properties
0176: */
0177: protected Properties ejb10EnvProps = new Properties();
0178:
0179: /**
0180: * logger
0181: */
0182: protected Logger logger = null;
0183:
0184: /**
0185: * array of methods meta-info
0186: */
0187: private ArrayList methodDesc = new ArrayList();
0188:
0189: /**
0190: * hash map of the methods
0191: */
0192: private HashMap methodDescMap = new HashMap();
0193:
0194: /**
0195: * List of SecurityRoleRefDesc for JACC
0196: */
0197: protected List securityRoleRefDescList = null;
0198:
0199: /**
0200: * DeploymentDesc parent of this BeanDesc
0201: */
0202: protected DeploymentDesc deploymentDesc = null;
0203:
0204: /**
0205: * JOnAS Remote Wrapper fully qualified classname
0206: */
0207: private String fullWrpRemoteName = null;
0208:
0209: /**
0210: * JOnAS Remote Wrapper Classname
0211: */
0212: private String wrpRemoteName = null;
0213:
0214: /**
0215: * JOnAS Home Wrapper fully qualified classname
0216: */
0217: private String fullWrpHomeName = null;
0218:
0219: /**
0220: * JOnAS Home Wrapper Classname
0221: */
0222: private String wrpHomeName = null;
0223:
0224: /**
0225: * JOnAS Local Wrapper fully qualified classname
0226: */
0227: private String fullWrpLocalName = null;
0228:
0229: /**
0230: * JOnAS Local Wrapper Classname
0231: */
0232: private String wrpLocalName = null;
0233:
0234: /**
0235: * JOnAS LocalHome Wrapper fully qualified classname
0236: */
0237: private String fullWrpLocalHomeName = null;
0238:
0239: /**
0240: * JOnAS LocalHome Wrapper Classname
0241: */
0242: private String wrpLocalHomeName = null;
0243:
0244: /**
0245: * JOnAS Handle Wrapper fully qualified classname
0246: */
0247: private String fullWrpHandleName = null;
0248:
0249: /**
0250: * JOnAS Handle Wrapper Classname
0251: */
0252: private String wrpHandleName = null;
0253:
0254: /**
0255: * Bean fully qualified classname
0256: */
0257: protected String fullDerivedBeanName = null;
0258:
0259: /**
0260: * Bean classname
0261: */
0262: protected String derivedBeanName = null;
0263:
0264: /**
0265: * Run-as role
0266: */
0267: private String runAsRole = null;
0268:
0269: /**
0270: * Run-as principal name
0271: */
0272: private String runAsPrincipalName = null;
0273:
0274: /**
0275: * Minimum Bean Pool size
0276: */
0277: protected int poolMin = 0;
0278:
0279: /**
0280: * Maximum Bean Cache size
0281: */
0282: protected int cacheMax = 0;
0283:
0284: /**
0285: * SasComponent (for CSIv2 over IIOP)
0286: */
0287: private SasComponent sasComponent = null;
0288:
0289: protected int timerTxAttribute = MethodDesc.TX_REQUIRES_NEW; // default
0290:
0291: protected String ejbTimeoutSignature;
0292:
0293: /**
0294: * BeanFactory when the bean has been loaded.
0295: */
0296: protected BeanFactory bf = null;
0297:
0298: /**
0299: * Cluster - velocity template of the CMI class for the Home interface
0300: */
0301: protected String clusterHomeDistributor = null;
0302:
0303: /**
0304: * Cluster - velocity template of the CMI class for the Remote interface
0305: */
0306: protected String clusterRemoteDistributor = null;
0307:
0308: /**
0309: * Cluster - true if the bean has to be replicated
0310: */
0311: protected boolean clusterReplicated = false;
0312:
0313: /**
0314: * Constructor to be used by parent node
0315: *
0316: * @param classLoader ClassLoader used to load Bean's classes
0317: * @param ejb XML Element from standard Deployment Descriptor
0318: * @param jonasEjb XML Element from jonas specific Deployment Descriptor
0319: * @param asd XML Element for the AssemblyDescriptor
0320: * @param fileName jar filename
0321: *
0322: * @throws DeploymentDescException when BeanDesc cannot be instanciated
0323: * (class loading problem, ...)
0324: */
0325: public BeanDesc(ClassLoader classLoader, CommonEjb ejb,
0326: JonasCommonEjb jonasEjb, AssemblyDescriptor asd,
0327: JLinkedList jMDRList, String fileName)
0328: throws DeploymentDescException {
0329:
0330: super (classLoader, ejb, jonasEjb, fileName);
0331: securityRoleRefDescList = new LinkedList();
0332: if (ejb.getEjbName() != null) {
0333: ejbName = ejb.getEjbName();
0334: } else {
0335: ejbName = null;
0336: }
0337:
0338: // If no value given specifically, we use ejbName+Home as JNDI name.
0339: if (jonasEjb.getJndiName() != null) {
0340: jndiName = jonasEjb.getJndiName();
0341: } else {
0342: jndiName = ejbName + REMOTEDEFAULTSUFFIX;
0343: }
0344: // If no value given specifically, we use jndiName+_L as JNDI local
0345: // name.
0346: if (jonasEjb.getJndiLocalName() != null) {
0347: jndiLocalName = jonasEjb.getJndiLocalName();
0348: } else {
0349: jndiLocalName = jndiName + LOCALDEFAULTSUFFIX;
0350: }
0351:
0352: // classes
0353: // --------------------------------------------------
0354: if (ejb.getHome() != null) {
0355: try {
0356: this .home = classLoader.loadClass(ejb.getHome());
0357: // check home extends javax.ejb.EJBHome
0358: if (!javax.ejb.EJBHome.class
0359: .isAssignableFrom(this .home)) {
0360: throw new DeploymentDescException("Home class '"
0361: + ejb.getHome()
0362: + "' does not extend javax.ejb.EJBHome");
0363: }
0364: } catch (ClassNotFoundException e) {
0365: throw new DeploymentDescException(
0366: "Home class not found for bean " + ejbName, e);
0367: }
0368: }
0369:
0370: if (ejb.getRemote() != null) {
0371: try {
0372: this .remote = classLoader.loadClass(ejb.getRemote());
0373: // check remote extends javax.ejb.EJBObject
0374: if (!javax.ejb.EJBObject.class
0375: .isAssignableFrom(this .remote)) {
0376: throw new DeploymentDescException("Remote class '"
0377: + ejb.getRemote()
0378: + "' does not extend javax.ejb.EJBObject");
0379: }
0380: } catch (ClassNotFoundException e) {
0381: throw new DeploymentDescException(
0382: "Remote class not found for bean " + ejbName, e);
0383: }
0384: }
0385:
0386: String localhomename = ejb.getLocalHome();
0387: // Note: Should do this only if bean is implied in a relation.
0388: if (localhomename == null && this instanceof EntityCmp2Desc) {
0389: localhomename = "javax.ejb.EJBLocalHome";
0390: }
0391: if (localhomename != null) {
0392: try {
0393: this .localhome = classLoader.loadClass(localhomename);
0394: // check localhome extends javax.ejb.EJBLocalHome
0395: if (!javax.ejb.EJBLocalHome.class
0396: .isAssignableFrom(this .localhome)) {
0397: throw new DeploymentDescException(
0398: "LocalHome class '"
0399: + localhomename
0400: + "' does not extend javax.ejb.EJBLocalHome");
0401: }
0402: } catch (ClassNotFoundException e) {
0403: throw new DeploymentDescException(
0404: "LocalHome class not found for bean " + ejbName,
0405: e);
0406: }
0407: }
0408:
0409: String localname = ejb.getLocal();
0410: // Note: Should do this only if bean is implied in a relation.
0411: if (localname == null && this instanceof EntityCmp2Desc) {
0412: localname = "javax.ejb.EJBLocalObject";
0413: }
0414: if (localname != null) {
0415: try {
0416: this .local = classLoader.loadClass(localname);
0417: // check local extends javax.ejb.EJBLocalObject
0418: if (!javax.ejb.EJBLocalObject.class
0419: .isAssignableFrom(this .local)) {
0420: throw new DeploymentDescException(
0421: "Local class '"
0422: + localname
0423: + "' does not extend javax.ejb.EJBLocalObject");
0424: }
0425: } catch (ClassNotFoundException e) {
0426: throw new DeploymentDescException(
0427: "Local class not found for bean " + ejbName, e);
0428: }
0429: }
0430:
0431: // permit to load service-endpoint class
0432: loadExtraClasses(ejb, classLoader);
0433:
0434: try {
0435: this .ejbClass = classLoader.loadClass(ejb.getEjbClass());
0436: // check ejb-class extends javax.ejb.EnterpriseBean
0437: if (!javax.ejb.EnterpriseBean.class
0438: .isAssignableFrom(this .ejbClass)) {
0439: throw new DeploymentDescException("Ejb class '"
0440: + ejb.getEjbClass()
0441: + "' does not extend javax.ejb.EnterpriseBean");
0442: }
0443: } catch (ClassNotFoundException e) {
0444: throw new DeploymentDescException(
0445: "Ejb class not found for bean " + ejbName, e);
0446: }
0447:
0448: // Set EJB 1.0 Environment properties from env entries
0449: EnvEntryDesc[] envt = getEnvEntryDesc();
0450: for (int i = 0; i < envt.length; i++) {
0451: if (envt[i].getName().startsWith(ejb10PropertiesPrefix)) {
0452: String newName = envt[i].getName().substring(
0453: ejb10PropertiesPrefix.length());
0454: String value = new String();
0455: if (envt[i].hasValue()) {
0456: value = envt[i].getValue().toString();
0457: }
0458: ejb10EnvProps.put(newName, value);
0459: }
0460: }
0461:
0462: // run-as
0463: if (ejb.getSecurityIdentity() != null) {
0464: RunAs runAsElem = ejb.getSecurityIdentity().getRunAs();
0465: if (runAsElem != null) {
0466: String roleName = runAsElem.getRoleName();
0467: if (roleName != null) {
0468: runAsRole = roleName;
0469: boolean runAsRoleFound = false;
0470: if (asd != null
0471: && asd.getSecurityRoleList() != null) {
0472: for (Iterator j = asd.getSecurityRoleList()
0473: .iterator(); j.hasNext();) {
0474: SecurityRole securityRole = (SecurityRole) j
0475: .next();
0476: // role name of a security-role element defined in the
0477: // assembly descriptor
0478: String r = securityRole.getRoleName();
0479: if (r.equals(runAsRole)) {
0480: runAsRoleFound = true;
0481: }
0482: }
0483: }
0484: //if there are no matching run-as and security-role
0485: if (!runAsRoleFound) {
0486: throw new DeploymentDescException(
0487: "There is no security-role defined for the run-as role: "
0488: + runAsRole);
0489: }
0490: }
0491: // Run-as principal name
0492: runAsPrincipalName = jonasEjb.getRunAsPrincipalName();
0493: // if no principal name set in JOnAS DD, set it to run-as role
0494: if (runAsPrincipalName == null) {
0495: runAsPrincipalName = runAsRole;
0496: }
0497: }
0498: }
0499:
0500: // populate array with all methods
0501: try {
0502: java.lang.reflect.Method[] m;
0503: int beginIdx = methodDesc.size();
0504: int len = 0;
0505: if ((this .home != null) && (this .remote != null)) {
0506: // session bean or entity bean with remote interface
0507: m = this .home.getMethods();
0508: for (int i = 0; i < m.length; i++) {
0509: if (!m[i].getDeclaringClass().equals(
0510: javax.ejb.EJBHome.class)
0511: || m[i].getName().equals("remove")) {
0512: addMethodDesc(m[i], this .home);
0513: len++;
0514: // check RemoteException is thrown
0515: checkRemoteException(m[i], true);
0516: /*
0517: * // arguments and return types must be valid types for
0518: * RMI if
0519: * (!m[i].getDeclaringClass().equals(javax.ejb.EJBHome.class) &&
0520: * !m[i].getName().equals("findByPrimaryKey")) {
0521: * checkValidTypesForRmi(m[i]); }
0522: */
0523: }
0524: }
0525:
0526: m = this .remote.getMethods();
0527: for (int i = 0; i < m.length; i++) {
0528: if (!m[i].getDeclaringClass().equals(
0529: javax.ejb.EJBObject.class)
0530: || m[i].getName().equals("remove")) {
0531: addMethodDesc(m[i], this .remote);
0532: len++;
0533: // check RemoteException is thrown
0534: checkRemoteException(m[i], true);
0535: /*
0536: * // arguments and return types must be valid for RMI
0537: * if
0538: * (!m[i].getDeclaringClass().equals(javax.ejb.EJBObject.class)) {
0539: * checkValidTypesForRmi(m[i]); }
0540: */
0541: }
0542: }
0543: }
0544: if ((this .localhome != null) && (this .local != null)) {
0545: // session bean or entity bean with local interface
0546: m = this .localhome.getMethods();
0547: for (int i = 0; i < m.length; i++) {
0548: if (!m[i].getDeclaringClass().equals(
0549: javax.ejb.EJBLocalHome.class)
0550: || m[i].getName().equals("remove")) {
0551: addMethodDesc(m[i], this .localhome);
0552: len++;
0553: // check RemoteException is NOT thrown
0554: checkRemoteException(m[i], false);
0555: }
0556: }
0557: m = this .local.getMethods();
0558: for (int i = 0; i < m.length; i++) {
0559: if (!m[i].getDeclaringClass().equals(
0560: javax.ejb.EJBLocalObject.class)
0561: || m[i].getName().equals("remove")) {
0562: addMethodDesc(m[i], this .local);
0563: len++;
0564: // check RemoteException is NOT thrown
0565: checkRemoteException(m[i], false);
0566: }
0567: }
0568: }
0569: if (this .home == null && this .localhome == null) {
0570:
0571: if (ejb.getMessagingType() != null) {
0572: // message driven bean & endpoints
0573: String msgType = ejb.getMessagingType();
0574: try {
0575: m = classLoader.loadClass(msgType).getMethods();
0576: for (int i = 0; i < m.length; i++) {
0577: addMethodDesc(m[i], m[i]
0578: .getDeclaringClass());
0579: len++;
0580: }
0581: } catch (Exception ex) {
0582: throw new DeploymentDescException(
0583: "Cannot load messaging type class ("
0584: + msgType + ") for " + ejbName,
0585: ex);
0586: }
0587: }
0588: // (web)service-endpoints may have no home or local-home too !!
0589: }
0590:
0591: if (javax.ejb.EntityBean.class
0592: .isAssignableFrom(this .ejbClass)) {
0593: // ejbSelect methods
0594: m = this .ejbClass.getMethods();
0595: for (int i = 0; i < m.length; i++) {
0596: if (m[i].getName().startsWith("ejbSelect")
0597: && Modifier.isAbstract(m[i].getModifiers())) {
0598: addMethodDesc(m[i], this .ejbClass);
0599: len++;
0600: }
0601: }
0602: }
0603:
0604: if (javax.ejb.TimedObject.class
0605: .isAssignableFrom(this .ejbClass)) {
0606: try {
0607: java.lang.reflect.Method timeout = this .ejbClass
0608: .getMethod(
0609: "ejbTimeout",
0610: new Class[] { javax.ejb.Timer.class });
0611: addMethodDesc(timeout, this .ejbClass);
0612: len++;
0613: } catch (NoSuchMethodException e) {
0614: throw new DeploymentDescException(
0615: "ejbTimeout not implemented in " + ejbName);
0616: }
0617: }
0618:
0619: len = addEJBMethodDesc(len);
0620: orderMethodDesc(methodDesc, beginIdx, len);
0621: } catch (SecurityException e) {
0622: throw new DeploymentDescException(
0623: "Cannot use java reflection on " + ejbName, e);
0624: }
0625:
0626: // populate HashMap with all security role references
0627: // for each security-role-ref of the bean
0628: if (ejb.getSecurityRoleRefList() != null) {
0629: for (Iterator i = ejb.getSecurityRoleRefList().iterator(); i
0630: .hasNext();) {
0631: SecurityRoleRef sRoleRef = (SecurityRoleRef) i.next();
0632: // test if the assembly-descriptor element exists
0633: if (asd == null) {
0634: throw new DeploymentDescException(
0635: "No assembly-descriptor element (and security-role elements) whereas security-role-ref element(s) are defined");
0636: } else {
0637: // test if the assembly-descriptor element contains
0638: // security-role elements
0639: if (asd.getSecurityRoleList().isEmpty()) {
0640: throw new DeploymentDescException(
0641: "No security-role elements defined in the assembly-descriptor element whereas security-role-ref element(s) are defined");
0642: }
0643: }
0644: // test if the role-link element of the security-role-ref
0645: // element exists
0646: if (sRoleRef.getRoleLink() == null) {
0647: throw new DeploymentDescException(
0648: "No role-link element in a security-role-ref element with role-name element : "
0649: + sRoleRef.getRoleName());
0650: }
0651: String roleLink = sRoleRef.getRoleLink();
0652: // correspond to role-name element in security-role-ref element
0653: String roleRefName = sRoleRef.getRoleName();
0654: // to know if there are corresponding roleLink and roleRefName
0655: boolean correspondingRoles = false;
0656: for (Iterator j = asd.getSecurityRoleList().iterator(); j
0657: .hasNext();) {
0658: SecurityRole securityRole = (SecurityRole) j.next();
0659: // role name of a security-role element defined in the
0660: // assembly descriptor
0661: String roleName = securityRole.getRoleName();
0662: if (roleName.equals(roleLink)) {
0663: securityRoleRefDescList
0664: .add(new SecurityRoleRefDesc(ejbName,
0665: sRoleRef, true));
0666: correspondingRoles = true;
0667: }
0668: }
0669: //if there are no matching roleLink and roleName
0670: if (!correspondingRoles) {
0671: throw new DeploymentDescException(
0672: "No corresponding role-name in a security-role element for role-link : "
0673: + roleLink);
0674: }
0675: }
0676: }
0677:
0678: // check if there are corresponding role-name element in security-role
0679: // and method-permission element of the Assembly Descriptor
0680: if (asd != null) {
0681: verifyRoleName(asd);
0682: // set method descriptor values for method permissions
0683: for (Iterator i = asd.getMethodPermissionList().iterator(); i
0684: .hasNext();) {
0685: MethodPermission methodPermission = (MethodPermission) i
0686: .next();
0687: for (Iterator j = methodPermission.getMethodList()
0688: .iterator(); j.hasNext();) {
0689: Method m = ((Method) j.next());
0690: // check method applies to current bean
0691: if (!m.getEjbName().equals(ejbName)) {
0692: continue;
0693: }
0694: // selection of interface home/remote
0695: Class pClass = null;
0696: if (m.getMethodIntf() != null) {
0697: pClass = getParentClass(m.getMethodIntf());
0698: }
0699: for (int k = 0; k < methodDesc.size(); k++) {
0700: MethodDesc md = (MethodDesc) methodDesc.get(k);
0701: int matchStatus = md.matchPattern(pClass, m
0702: .getMethodName(), m.getMethodParams());
0703: for (Iterator l = methodPermission
0704: .getRoleNameList().iterator(); l
0705: .hasNext();) {
0706: String roleName = (String) l.next();
0707: // Add only if it greater than APPLY_TO_NOTHING
0708: if (matchStatus > MethodDesc.APPLY_TO_NOTHING) {
0709: md.addRoleName(roleName);
0710: }
0711: }
0712: }
0713: }
0714: }
0715: }
0716:
0717: // Set excluded method
0718: if (asd != null && asd.getExcludeList() != null) {
0719: // For each excluded method, find a methodDesc corresponding to this excluded method
0720: for (Iterator i = asd.getExcludeList().getMethodList()
0721: .iterator(); i.hasNext();) {
0722: Method m = (Method) i.next();
0723: // check method applies to current bean
0724: if (!m.getEjbName().equals(ejbName)) {
0725: continue;
0726: }
0727: // selection of interface home/remote
0728: Class pClass = null;
0729: if (m.getMethodIntf() != null) {
0730: pClass = getParentClass(m.getMethodIntf());
0731: }
0732: // Find methodDesc with matching pattern of excluded method
0733: for (int k = 0; k < methodDesc.size(); k++) {
0734: MethodDesc md = (MethodDesc) methodDesc.get(k);
0735: int matchStatus = md.matchPattern(pClass, m
0736: .getMethodName(), m.getMethodParams());
0737: // Add only if it greater than APPLY_TO_NOTHING
0738: if (matchStatus > MethodDesc.APPLY_TO_NOTHING) {
0739: md.setExcluded(true);
0740: }
0741: }
0742: }
0743: }
0744:
0745: // set method descriptor values for container transactions
0746: if (asd != null) {
0747: // Loop on ContainerTransaction list
0748: Iterator i = asd.getContainerTransactionList().iterator();
0749: while (i.hasNext()) {
0750: ContainerTransaction cotr = (ContainerTransaction) i
0751: .next();
0752: // Loop on Method list
0753: Iterator j = cotr.getMethodList().iterator();
0754: while (j.hasNext()) {
0755: Method m = (Method) j.next();
0756: // check method applies to current bean
0757: if (!m.getEjbName().equals(ejbName)) {
0758: continue;
0759: }
0760:
0761: // selection of interface home/remote
0762: Class pClass = null;
0763: if (m.getMethodIntf() != null) {
0764: pClass = getParentClass(m.getMethodIntf());
0765: }
0766:
0767: // loop on methods in the array
0768: boolean found = false;
0769: for (int k = 0; k < methodDesc.size(); k++) {
0770: MethodDesc md = (MethodDesc) methodDesc.get(k);
0771: int matchStatus = md.matchPattern(pClass, m
0772: .getMethodName(), m.getMethodParams());
0773: if (matchStatus != MethodDesc.APPLY_TO_NOTHING) {
0774: found = true;
0775: }
0776: // set if proper level of assignation
0777: String transAttribute = null;
0778: if (cotr.getTransAttribute() != null) {
0779: transAttribute = cotr.getTransAttribute();
0780: }
0781: md.overwriteTxAttribute(transAttribute,
0782: matchStatus);
0783: }
0784: if (!found) {
0785: // The method defined via the <method> element is not a
0786: // declared method
0787: TraceEjb.dd
0788: .log(
0789: BasicLevel.WARN,
0790: "Invalid container-transaction: method '"
0791: + MethodDesc
0792: .methodElementToString(m)
0793: + "' not declared in bean "
0794: + ejbName);
0795: }
0796: }
0797: }
0798: }
0799:
0800: String packageName = "";
0801: String ejbIdentifier = getIdentifier();
0802:
0803: if (getRemoteClass() != null) {
0804: packageName = GENERATED_PREFIX
0805: + BeanNaming.getPackageName(getRemoteClass()
0806: .getName());
0807: wrpRemoteName = new String("JOnAS" + ejbIdentifier
0808: + "Remote");
0809: wrpHandleName = new String("JOnAS" + ejbIdentifier
0810: + "Handle");
0811: fullWrpRemoteName = BeanNaming.getClassName(packageName,
0812: wrpRemoteName);
0813: fullWrpHandleName = BeanNaming.getClassName(packageName,
0814: wrpHandleName);
0815: }
0816:
0817: if (getLocalClass() != null) {
0818: packageName = GENERATED_PREFIX
0819: + BeanNaming.getPackageName(getLocalClass()
0820: .getName());
0821: wrpLocalName = new String("JOnAS" + ejbIdentifier + "Local");
0822: fullWrpLocalName = BeanNaming.getClassName(packageName,
0823: wrpLocalName);
0824: }
0825:
0826: if (getHomeClass() != null) {
0827: packageName = GENERATED_PREFIX
0828: + BeanNaming.getPackageName(getHomeClass()
0829: .getName());
0830: wrpHomeName = new String("JOnAS" + ejbIdentifier + "Home");
0831: fullWrpHomeName = BeanNaming.getClassName(packageName,
0832: wrpHomeName);
0833: }
0834:
0835: if (getLocalHomeClass() != null) {
0836: packageName = GENERATED_PREFIX
0837: + BeanNaming.getPackageName(getLocalHomeClass()
0838: .getName());
0839: wrpLocalHomeName = new String("JOnAS" + ejbIdentifier
0840: + "LocalHome");
0841: fullWrpLocalHomeName = BeanNaming.getClassName(packageName,
0842: wrpLocalHomeName);
0843: }
0844:
0845: fullDerivedBeanName = getEjbClass().getName();
0846: derivedBeanName = BeanNaming.getBaseName(getEjbClass()
0847: .getName());
0848:
0849: IorSecurityConfigMapping iorSecurityConfigMapping = jonasEjb
0850: .getIorSecurityConfig();
0851: if (iorSecurityConfigMapping != null) {
0852: processIorSecurityConfig(iorSecurityConfigMapping);
0853: }
0854:
0855: // Cluster
0856: if (jonasEjb.getClusterHomeDistributor() != null
0857: && !jonasEjb.getClusterHomeDistributor().equals("")) {
0858: clusterHomeDistributor = jonasEjb
0859: .getClusterHomeDistributor();
0860: }
0861: if (jonasEjb.getClusterRemoteDistributor() != null
0862: && !jonasEjb.getClusterRemoteDistributor().equals("")) {
0863: clusterRemoteDistributor = jonasEjb
0864: .getClusterRemoteDistributor();
0865: }
0866: if (jonasEjb.getClusterReplicated() != null) {
0867: if (jonasEjb.getClusterReplicated()
0868: .equalsIgnoreCase("True")) {
0869: clusterReplicated = true;
0870: } else if (jonasEjb.getClusterReplicated()
0871: .equalsIgnoreCase("False")) {
0872: clusterReplicated = false;
0873: } else {
0874: throw new DeploymentDescException(
0875: "Invalid cluster-replicated value for bean "
0876: + this .ejbName);
0877: }
0878: }
0879:
0880: }
0881:
0882: /**
0883: * Permit classes loading from subtypes. (needed for Stateless Session Beans
0884: * with service-endpoints). Needs to be overridden in subtypes.
0885: *
0886: * @param ce XML Element representing EJB Descriptor
0887: * @param loader ClassLoader used to load classes
0888: *
0889: * @throws DeploymentDescException when a class cannot be loaded
0890: */
0891: protected void loadExtraClasses(CommonEjb ce, ClassLoader loader)
0892: throws DeploymentDescException {
0893: // do nothing by default
0894: }
0895:
0896: /**
0897: * Permit Methods addition from subtypes Protected method that need to be
0898: * overridden in subclasses
0899: *
0900: * @param len method array length
0901: * @return new len value
0902: *
0903: * @throws DeploymentDescException when java reflection cannot be used on
0904: * classes
0905: */
0906: protected int addEJBMethodDesc(int len)
0907: throws DeploymentDescException {
0908: return len;
0909: }
0910:
0911: /**
0912: * Returns the parent Class for a method given an interface type.
0913: *
0914: * @param intfType type of the interface (Home/Remote/LocalHome/Local or
0915: * ServiceEndpoint)
0916: *
0917: * @return the parent class for a method given an interface type
0918: *
0919: * @throws DeploymentDescException when intfType is unknown
0920: */
0921: protected Class getParentClass(String intfType)
0922: throws DeploymentDescException {
0923: Class pClass = null;
0924: if (intfType.equals("Home")) {
0925: pClass = javax.ejb.EJBHome.class;
0926: } else if (intfType.equals("Remote")) {
0927: pClass = javax.ejb.EJBObject.class;
0928: } else if (intfType.equals("LocalHome")) {
0929: pClass = javax.ejb.EJBLocalHome.class;
0930: } else if (intfType.equals("Local")) {
0931: pClass = javax.ejb.EJBLocalObject.class;
0932: } else {
0933: throw new DeploymentDescException(intfType
0934: + " is invalid value for method-intf on bean "
0935: + ejbName);
0936: }
0937: return pClass;
0938: }
0939:
0940: /**
0941: * Gets an hashcode for this bean
0942: * Return hashcode for jndiname + jndi localname
0943: * @return a string for hashcode for jndiname + jndi localname
0944: */
0945: protected String getHashCodeForIdentifier() {
0946: String hash = "";
0947: if (getJndiName() != null) {
0948: hash += getJndiName();
0949: }
0950: if (getJndiLocalName() != null) {
0951: hash += getJndiLocalName();
0952: }
0953: return Integer.toString(hash.hashCode());
0954: }
0955:
0956: /**
0957: * Build a valid java identifier for the bean.
0958: * @return Returns a valid java identifier from the bean.
0959: */
0960: public String getIdentifier() {
0961:
0962: if (beanIdentification == null) {
0963: String identifier = getEjbName();
0964: identifier += getHashCodeForIdentifier();
0965:
0966: char[] tabChar = new char[identifier.length()];
0967: for (int i = 0; i < identifier.length(); i++) {
0968: if (!Character.isJavaIdentifierPart(identifier
0969: .charAt(i))) {
0970: tabChar[i] = '_';
0971: } else {
0972: tabChar[i] = identifier.charAt(i);
0973: }
0974: }
0975: beanIdentification = new String(tabChar);
0976: }
0977: return beanIdentification;
0978: }
0979:
0980: /**
0981: * Check if method throws RemoteException (or not).
0982: *
0983: * @param m the method to examine
0984: * @param shouldThrow boolean value indicating if the method should or
0985: * shouldn't throw RemoteException
0986: *
0987: * @throws DeploymentDescException thrown for non-valid method
0988: */
0989: public void checkRemoteException(java.lang.reflect.Method m,
0990: boolean shouldThrow) throws DeploymentDescException {
0991: Class[] excepts = m.getExceptionTypes();
0992: for (int j = 0; j < excepts.length; j++) {
0993: if (RemoteException.class.isAssignableFrom(excepts[j])) {
0994: if (shouldThrow) {
0995: return;
0996: } else {
0997: throw new DeploymentDescException("Method "
0998: + m.getName() + " of "
0999: + m.getDeclaringClass()
1000: + " should NOT throw RemoteException");
1001: }
1002: }
1003: }
1004: if (shouldThrow) {
1005: throw new DeploymentDescException("Method " + m.getName()
1006: + " of " + m.getDeclaringClass()
1007: + " must throw RemoteException");
1008: } else {
1009: return;
1010: }
1011:
1012: }
1013:
1014: /**
1015: * Check if argument and return types are valid types for RMI-IIOP.
1016: * (Primitive types, remote objects, or non-remote objects that implement
1017: * the java.io.Serializable interface) Only a warning is logging if it's not
1018: * the case.
1019: *
1020: * @param m the methode to examine
1021: */
1022: public void checkValidTypesForRmi(java.lang.reflect.Method m) {
1023: boolean isValid = true;
1024: Class[] paramTypes = m.getParameterTypes();
1025: for (int i = 0; i < paramTypes.length; i++) {
1026: if (!JavaType.isValidForRmi(paramTypes[i])) {
1027: isValid = false;
1028: }
1029: }
1030: if (!JavaType.isValidForRmi(m.getReturnType())
1031: && !JavaType.isVoid(m.getReturnType())
1032: && !JavaType.isCollecOrEnum(m.getReturnType())) {
1033: // Allow Collection or Enumeration type (finder methods)
1034: isValid = false;
1035: }
1036: if (!isValid) {
1037: // TODO the trace of this warning uses a static variable into
1038: // TraceEjb class
1039: // because this.logger is not yet initialized
1040: TraceEjb.dd
1041: .log(
1042: BasicLevel.WARN,
1043: "Method "
1044: + m.getName()
1045: + " of "
1046: + m.getDeclaringClass()
1047: + " may be have an invalid argument or return type for RMI");
1048: }
1049: }
1050:
1051: /**
1052: * Check that the bean descriptor is valid
1053: *
1054: * @throws DeploymentDescException thrown for non-valid bean
1055: */
1056: public void check() throws DeploymentDescException {
1057: // check business methods transaction attribute
1058: for (int i = 0; i < methodDesc.size(); i++) {
1059: checkTxAttribute(((MethodDesc) methodDesc.get(i)));
1060: }
1061: checkRunAsMapping();
1062: }
1063:
1064: /**
1065: * Check that the runAs role mapping is correct
1066: * @throws DeploymentDescException if role mapping is incorrect
1067: */
1068: public void checkRunAsMapping() throws DeploymentDescException {
1069: if (runAsPrincipalName != null) {
1070: // verify roles of run-as principal name
1071: String[] runAsPrincipalRoles = deploymentDesc
1072: .getRolesForRunAsPrincipal(runAsPrincipalName);
1073: // Check that the run-as role is included in principal roles
1074: if (runAsPrincipalRoles != null) {
1075: boolean isIncluded = false;
1076: for (int r = 0; r < runAsPrincipalRoles.length; r++) {
1077: if (runAsPrincipalRoles[r].equals(runAsRole)) {
1078: isIncluded = true;
1079: }
1080: }
1081: if (!isIncluded) {
1082: throw new DeploymentDescException(
1083: "The run-as roles defined for the runas principal name '"
1084: + runAsPrincipalName
1085: + "' does not contains the run-as role '"
1086: + runAsRole + "' in bean '"
1087: + getEjbName() + ".");
1088: }
1089: }
1090: }
1091: }
1092:
1093: /**
1094: * Check that trans-attribute is valid for a bean's method.
1095: *
1096: * @param md MethodDesc to check
1097: *
1098: * @throws DeploymentDescException When MethodDesc is not valid
1099: */
1100: protected abstract void checkTxAttribute(MethodDesc md)
1101: throws DeploymentDescException;
1102:
1103: /**
1104: * Check that there are always corresponding role-name element in
1105: * security-role and method-permission elements.
1106: *
1107: * @param asd the AssemblyDescriptor used to check bean's role names
1108: *
1109: * @throws DeploymentDescException When verification fails
1110: */
1111: protected void verifyRoleName(AssemblyDescriptor asd)
1112: throws DeploymentDescException {
1113: boolean verify;
1114: List methodPermission = asd.getMethodPermissionList();
1115: if (methodPermission != null) {
1116: for (Iterator i = methodPermission.iterator(); i.hasNext();) {
1117: MethodPermission mPermission = (MethodPermission) i
1118: .next();
1119: for (Iterator j = mPermission.getRoleNameList()
1120: .iterator(); j.hasNext();) {
1121: verify = false;
1122: String mpRoleName = (String) j.next();
1123: for (Iterator k = asd.getSecurityRoleList()
1124: .iterator(); k.hasNext();) {
1125: String srRoleName = ((SecurityRole) k.next())
1126: .getRoleName();
1127: if (mpRoleName.equals(srRoleName)) {
1128: verify = true;
1129: }
1130: }
1131: if (!verify) {
1132: throw new DeploymentDescException(
1133: "a method-permission element defined a role-name element \""
1134: + mpRoleName
1135: + "\" which doesn't correspond to any security-role element of the Deployment Descriptor");
1136: }
1137: }
1138: }
1139: }
1140: }
1141:
1142: /**
1143: * Get the enterprise bean's name.
1144: *
1145: * @return Name of the bean
1146: */
1147: public String getEjbName() {
1148: return ejbName;
1149: }
1150:
1151: /**
1152: * Get the name to associate with the enterprise Bean in the JNDI name
1153: * space. Invoking this method is disallowed for message driven bean. (This
1154: * information is JOnAS specific). Used by Server
1155: *
1156: * @return Jndi name of the bean
1157: */
1158: public String getJndiName() {
1159: return jndiName;
1160: }
1161:
1162: /**
1163: * Get the name to associate with the enterprise Bean in the JNDI name space
1164: * for local access (inside the same JOnAS Server)
1165: *
1166: * @return Jndi local name of the bean
1167: */
1168: public String getJndiLocalName() {
1169: return jndiLocalName;
1170: }
1171:
1172: /**
1173: * Get bean's home interface. Invoking this method is disallowed for message
1174: * driven bean. Used by GenIC and Server
1175: *
1176: * @return Class for the home interface or null
1177: */
1178: public Class getHomeClass() {
1179: return home;
1180: }
1181:
1182: /**
1183: * Get bean's remote interface. Invoking this method is disallowed for
1184: * message driven bean. Used by GenIC and Server
1185: *
1186: * @return Class for the remote interface or null
1187: */
1188: public Class getRemoteClass() {
1189: return remote;
1190: }
1191:
1192: /**
1193: * Get bean's local home interface. Invoking this method is disallowed for
1194: * message driven bean. Used by GenIC and Server
1195: *
1196: * @return Class for the home interface or null
1197: */
1198: public Class getLocalHomeClass() {
1199: return localhome;
1200: }
1201:
1202: /**
1203: * Get bean's local interface. Invoking this method is disallowed for
1204: * message driven bean. Used by GenIC and Server
1205: *
1206: * @return Class for the Local interface or null
1207: */
1208: public Class getLocalClass() {
1209: return local;
1210: }
1211:
1212: /**
1213: * Get bean's class. Used by GenIC and Server
1214: *
1215: * @return Class for the bean
1216: */
1217: public Class getEjbClass() {
1218: return ejbClass;
1219: }
1220:
1221: /**
1222: * Get bean's EJB 1.0 environment properties.
1223: *
1224: * @return Returns the bean's EJB 1.0 environment properties
1225: */
1226: public Properties getEjb10Environment() {
1227: Properties ret = new Properties(ejb10EnvProps);
1228: return ret;
1229: }
1230:
1231: /**
1232: * Get descriptor attached to a given method. Used by GenIC and JMdbEndpointFactory
1233: *
1234: * @param method Method from the Home/Remote/MessageListener interface
1235: * @return The method descriptor (never returns null)
1236: */
1237: public MethodDesc getMethodDesc(java.lang.reflect.Method method) {
1238:
1239: if (!methodDescMap.containsKey(method)) {
1240: throw new Error(
1241: method.getName()
1242: + " is not a method of home/remote interfaces for bean "
1243: + getEjbName());
1244: }
1245: return (MethodDesc) methodDescMap.get(method);
1246: }
1247:
1248: /**
1249: * get an iterator for all MethodDesc of the bean.
1250: *
1251: * @return Returns an iterator for all MethodDesc of the bean
1252: */
1253: public Iterator getMethodDescIterator() {
1254: return methodDesc.iterator();
1255: }
1256:
1257: /**
1258: * get a MethodDesc from its index.
1259: *
1260: * @param index MethodDesc index
1261: *
1262: * @return Returns a MethodDesc from its index
1263: */
1264: public MethodDesc getMethodDesc(int index) {
1265: return (MethodDesc) methodDesc.get(index);
1266: }
1267:
1268: /**
1269: * Gets the security-role-ref of the beans can access to the
1270: * EJBRoleRefPermission and role-link.
1271: *
1272: * @return the security-role-ref of the beans
1273: */
1274: public List getSecurityRoleRefDescList() {
1275: return securityRoleRefDescList;
1276: }
1277:
1278: /**
1279: * @return min size of the pool
1280: */
1281: public int getPoolMin() {
1282: return poolMin;
1283: }
1284:
1285: /**
1286: * @return max size of the cache
1287: */
1288: public int getCacheMax() {
1289: return cacheMax;
1290: }
1291:
1292: /**
1293: * @return the run-as role name
1294: */
1295: public String getRunAsRole() {
1296: return runAsRole;
1297: }
1298:
1299: /**
1300: * @return the transaction attribute for the ejbTimeout method
1301: */
1302: public int getTimerTxAttribute() {
1303: return timerTxAttribute;
1304: }
1305:
1306: /**
1307: * @return the security signature for the ejbTimeout method
1308: */
1309: public String getEjbTimeoutSignature() {
1310: return ejbTimeoutSignature;
1311: }
1312:
1313: /**
1314: * @return the BeanFactory, if the bean has been loaded.
1315: */
1316: public BeanFactory getBeanFactory() {
1317: return bf;
1318: }
1319:
1320: /**
1321: * Set the BeanFactory, when the bean is loaded in container.
1322: * @param factory The bean factory
1323: */
1324: public void setBeanFactory(BeanFactory factory) {
1325: bf = factory;
1326: }
1327:
1328: /**
1329: * String representation of the object for test purpose
1330: *
1331: * @return String representation of this object
1332: */
1333: public String toString() {
1334: StringBuffer ret = new StringBuffer();
1335: ret.append("\ngetDisplayName()=" + getDisplayName());
1336: ret.append("\ngetEjbName()=" + getEjbName());
1337: if (jndiName != null) {
1338: ret.append("\ngetJndiName()=" + getJndiName());
1339: }
1340: if (home != null) {
1341: ret.append("\ngetHomeClass()=" + getHomeClass().toString());
1342: }
1343: if (remote != null) {
1344: ret.append("\ngetRemoteClass()="
1345: + getRemoteClass().toString());
1346: }
1347: if (localhome != null) {
1348: ret.append("\ngetLocalHomeClass()="
1349: + getLocalHomeClass().toString());
1350: }
1351: if (local != null) {
1352: ret.append("\ngetLocalClass()="
1353: + getLocalClass().toString());
1354: }
1355: ret.append("\ngetEjbClass()=" + getEjbClass().toString());
1356: EnvEntryDesc[] envE = getEnvEntryDesc();
1357: for (int i = 0; i < envE.length; i++) {
1358: ret.append("\ngetEnvEntryDesc(" + i + ")="
1359: + envE[i].toString());
1360: }
1361: ServiceRefDesc[] sr = getServiceRefDesc();
1362: for (int i = 0; i < sr.length; i++) {
1363: ret.append("\ngetServiceRefDesc(" + i + ")="
1364: + sr[i].toString());
1365: }
1366: ResourceEnvRefDesc[] resEnvR = getResourceEnvRefDesc();
1367: for (int i = 0; i < resEnvR.length; i++) {
1368: ret.append("\ngetResourceEnvRefDesc(" + i + ")="
1369: + resEnvR[i].toString());
1370: }
1371: ResourceRefDesc[] resR = getResourceRefDesc();
1372: for (int i = 0; i < resR.length; i++) {
1373: ret.append("\ngetResourceRefDesc(" + i + ")="
1374: + resR[i].toString());
1375: }
1376: EjbRefDesc[] ejbR = getEjbRefDesc();
1377: for (int i = 0; i < ejbR.length; i++) {
1378: ret.append("\ngetEjbRefDesc(" + i + ")="
1379: + ejbR[i].toString());
1380: }
1381: EjbLocalRefDesc[] ejbLR = getEjbLocalRefDesc();
1382: for (int i = 0; i < ejbLR.length; i++) {
1383: ret.append("\ngetEjbLocalRefDesc(" + i + ")="
1384: + ejbLR[i].toString());
1385: }
1386: MessageDestinationRefDesc[] mdR = getMessageDestinationRefDesc();
1387: for (int i = 0; i < mdR.length; i++) {
1388: ret.append("\ngetMessageDestinationRefDesc(" + i + ")="
1389: + mdR[i].toString());
1390: }
1391: for (int i = 0; i < methodDesc.size(); i++) {
1392: MethodDesc md = (MethodDesc) methodDesc.get(i);
1393: ret.append("\ngetMethodDesc(" + i + ")="
1394: + md.getClass().getName());
1395: ret.append(md.toString());
1396: }
1397:
1398: if (securityRoleRefDescList != null) {
1399: for (Iterator i = securityRoleRefDescList.iterator(); i
1400: .hasNext();) {
1401: SecurityRoleRefDesc sRoleRefDesc = (SecurityRoleRefDesc) i
1402: .next();
1403: ret.append("\nsecurity-role-ref, role-name = '"
1404: + sRoleRefDesc.getRoleName()
1405: + "', role-link = '"
1406: + sRoleRefDesc.getRoleLink() + "'");
1407: }
1408: }
1409: ret.append("\ngetFullWrpRemoteName() = "
1410: + getFullWrpRemoteName());
1411: ret.append("\ngetFullWrpHomeName() = " + getFullWrpHomeName());
1412: ret
1413: .append("\ngetFullWrpLocalName() = "
1414: + getFullWrpLocalName());
1415: ret.append("\ngetFullWrpLocalHomeName() = "
1416: + getFullWrpLocalHomeName());
1417: ret.append("\ngetFullWrpHandleName() = "
1418: + getFullWrpHandleName());
1419: ret.append("\ngetFullDerivedBeanName() = "
1420: + getFullDerivedBeanName());
1421: ret.append("\ngetRunAsRole() = " + getRunAsRole());
1422: return ret.toString();
1423: }
1424:
1425: /**
1426: * MethodDesc constructor factory method to ovewrite
1427: *
1428: * @param meth the method to be wrapped into a MethodDesc instance
1429: * @param index index of the method inside the MethodDesc List
1430: *
1431: * @return Returns a new MethodDesc (or subclass)
1432: */
1433: protected MethodDesc newMethodDescInstance(
1434: java.lang.reflect.Method meth, Class classDef, int index) {
1435: return new MethodDesc(this , meth, classDef, index);
1436: }
1437:
1438: /**
1439: * Add a new method descriptor to the bean
1440: *
1441: * @param meth method to add inside MethodDescs list
1442: *
1443: * @return the constructed MethodDesc
1444: */
1445: protected MethodDesc addMethodDesc(java.lang.reflect.Method meth,
1446: Class classDef) {
1447: MethodDesc md = newMethodDescInstance(meth, classDef,
1448: methodDesc.size());
1449: methodDesc.add(md);
1450: methodDescMap.put(meth, md);
1451: return md;
1452: }
1453:
1454: /**
1455: * @return Returns the full name of the wrapper class for the bean
1456: */
1457: public String getFullWrpRemoteName() {
1458: return fullWrpRemoteName;
1459: }
1460:
1461: /**
1462: * @return Returns the full name of the wrapper class for the bean
1463: */
1464: public String getFullWrpLocalName() {
1465: return fullWrpLocalName;
1466: }
1467:
1468: /**
1469: * @return Returns the name of the wrapper class for the bean
1470: */
1471: public String getWrpRemoteName() {
1472: return wrpRemoteName;
1473: }
1474:
1475: /**
1476: * @return Returns the name of the wrapper class for the bean
1477: */
1478: public String getWrpLocalName() {
1479: return wrpLocalName;
1480: }
1481:
1482: /**
1483: * @return Returns the full name of the Handle class for the bean
1484: */
1485: public String getFullWrpHandleName() {
1486: return fullWrpHandleName;
1487: }
1488:
1489: /**
1490: * @return Returns the name of the Handle class for the bean
1491: */
1492: public String getWrpHandleName() {
1493: return wrpHandleName;
1494: }
1495:
1496: /**
1497: * @return Returns the full name of the wrapper home class for the bean
1498: */
1499: public String getFullWrpHomeName() {
1500: return fullWrpHomeName;
1501: }
1502:
1503: /**
1504: * @return Returns the full name of the wrapper local home class for the bean
1505: */
1506: public String getFullWrpLocalHomeName() {
1507: return fullWrpLocalHomeName;
1508: }
1509:
1510: /**
1511: * @return Returns the name of the wrapper home class for the bean
1512: */
1513: public String getWrpHomeName() {
1514: return wrpHomeName;
1515: }
1516:
1517: /**
1518: * @return Returns the name of the wrapper local home class for the bean
1519: */
1520: public String getWrpLocalHomeName() {
1521: return wrpLocalHomeName;
1522: }
1523:
1524: /**
1525: * @return Returns the full name of the derived class of the bean
1526: */
1527: public String getFullDerivedBeanName() {
1528: return fullDerivedBeanName;
1529: }
1530:
1531: /**
1532: * @return Returns the name of the derived class of the bean
1533: */
1534: public String getDerivedBeanName() {
1535: return derivedBeanName;
1536: }
1537:
1538: /**
1539: * @return Returns the parent deployment descriptor
1540: */
1541: public DeploymentDesc getDeploymentDesc() {
1542: return deploymentDesc;
1543: }
1544:
1545: /**
1546: * Set the parent deployment descriptor
1547: *
1548: * @param deploymentDesc parent DeploymentDesc
1549: */
1550: public void setDeploymentDesc(DeploymentDesc deploymentDesc) {
1551: this .deploymentDesc = deploymentDesc;
1552: logger = deploymentDesc.getLogger();
1553: }
1554:
1555: /**
1556: * Sort the MethodDesc list.
1557: *
1558: * @param al ArrayList to be sorted
1559: * @param begin begin index
1560: * @param length size of the list
1561: */
1562: private void orderMethodDesc(ArrayList al, int begin, int length) {
1563: MethodDesc[] mds = new MethodDesc[length];
1564: for (int i = 0; i < length; i++) {
1565: mds[i] = (MethodDesc) al.get(begin + i);
1566: }
1567: Arrays.sort(mds, 0, length, new MethodDescComparator());
1568: for (int i = 0; i < length; i++) {
1569: al.set(begin + i, mds[i]);
1570: mds[i].setIndex(begin + i);
1571: }
1572: }
1573:
1574: /**
1575: * Compare 2 MethodDesc.
1576: */
1577: private class MethodDescComparator implements Comparator {
1578:
1579: /**
1580: * Compare 2 Object.
1581: *
1582: * @param o1 instance 1
1583: * @param o2 instance 2 to be compared to instance 1
1584: *
1585: * @return integer difference between the 2 instance
1586: */
1587: public int compare(Object o1, Object o2) {
1588: MethodDesc md1 = (MethodDesc) o1;
1589: MethodDesc md2 = (MethodDesc) o2;
1590: int res = md1.getMethod().getDeclaringClass().getName()
1591: .compareTo(
1592: md2.getMethod().getDeclaringClass()
1593: .getName());
1594: if (res == 0) {
1595: res = md1.getMethod().getName().compareTo(
1596: md2.getMethod().getName());
1597: if (res == 0) {
1598: // Same method name => compare the parameter types
1599: Class[] p1 = md1.getMethod().getParameterTypes();
1600: Class[] p2 = md2.getMethod().getParameterTypes();
1601: res = p1.length - p2.length;
1602: if (res == 0) {
1603: //Same parameter size
1604: for (int i = 0; i < p1.length
1605: && (res = p1[i].getName().compareTo(
1606: p2[i].getName())) == 0; i++) {
1607: // compare each method
1608: }
1609: }
1610: }
1611: }
1612: return res;
1613: }
1614: }
1615:
1616: /**
1617: * @return the runAs principal name.
1618: */
1619: public String getRunAsPrincipalName() {
1620: return runAsPrincipalName;
1621: }
1622:
1623: /**
1624: * @return true if local interface has been defined in the DD
1625: */
1626: public boolean hasDefinedLocalInterface() {
1627: if (localhome == null) {
1628: return false;
1629: } else {
1630: return (!"javax.ejb.EJBLocalHome".equals(localhome
1631: .getName()));
1632: }
1633: }
1634:
1635: /**
1636: * Build sas component used for CSIv2 interop
1637: * @param iorSecurityConfigMapping CsiV2 ior configuration
1638: */
1639: private void processIorSecurityConfig(
1640: IorSecurityConfigMapping iorSecurityConfigMapping) {
1641:
1642: // Transport
1643: TransportStruct transportStruct = new TransportStruct();
1644: // As
1645: AsStruct asStruct = new AsStruct();
1646: // Sas
1647: SasStruct sasStruct = new SasStruct();
1648:
1649: // Now fill SasComponent with given ior values
1650: TransportConfigMapping transportConfigMapping = iorSecurityConfigMapping
1651: .getTransportConfig();
1652: AsContextMapping asContextMapping = iorSecurityConfigMapping
1653: .getAsContext();
1654: SasContextMapping sasContextMapping = iorSecurityConfigMapping
1655: .getSasContext();
1656:
1657: // target requires (if required)
1658: int targetRequires = 0;
1659: if (transportConfigMapping.getIntegrity().equals("required")) {
1660: targetRequires |= Integrity.value;
1661: }
1662: if (transportConfigMapping.getConfidentiality().equals(
1663: "required")) {
1664: targetRequires |= Confidentiality.value;
1665: }
1666: if (transportConfigMapping.getEstablishTrustInClient().equals(
1667: "required")) {
1668: targetRequires |= EstablishTrustInClient.value;
1669: }
1670: if (transportConfigMapping.getEstablishTrustInTarget().equals(
1671: "required")) {
1672: targetRequires |= EstablishTrustInTarget.value;
1673: }
1674: transportStruct.setTargetRequires(targetRequires);
1675:
1676: // target supports (supported or required)
1677: int targetSupports = 0;
1678: if (transportConfigMapping.getIntegrity().equals("supported")
1679: || transportConfigMapping.getIntegrity().equals(
1680: "required")) {
1681: targetSupports |= Integrity.value;
1682: }
1683: if (transportConfigMapping.getConfidentiality().equals(
1684: "supported")
1685: || transportConfigMapping.getConfidentiality().equals(
1686: "required")) {
1687: targetSupports |= Confidentiality.value;
1688: }
1689: if (transportConfigMapping.getEstablishTrustInClient().equals(
1690: "supported")
1691: || transportConfigMapping.getEstablishTrustInClient()
1692: .equals("required")) {
1693: targetSupports |= EstablishTrustInClient.value;
1694: }
1695: if (transportConfigMapping.getEstablishTrustInTarget().equals(
1696: "supported")
1697: || transportConfigMapping.getEstablishTrustInTarget()
1698: .equals("required")) {
1699: targetSupports |= EstablishTrustInTarget.value;
1700: }
1701: transportStruct.setTargetSupports(targetSupports);
1702:
1703: // As struct (if it is needed)
1704: if (!asContextMapping.getAuthMethod().equals("none")) {
1705: asStruct.setTargetName(asContextMapping.getRealm());
1706: asStruct.setTargetSupports(EstablishTrustInClient.value);
1707: if (asContextMapping.getRequired().equals("true")) {
1708: asStruct
1709: .setTargetRequires(EstablishTrustInClient.value);
1710:
1711: }
1712: }
1713:
1714: // Sas struct (if supported)
1715: if (sasContextMapping.getCallerPropagation()
1716: .equals("supported")) {
1717: sasStruct.enableGSSUPSupportedNamingMechanisms();
1718: sasStruct.setSupportedIdentityTypes(ITTAbsent.value
1719: | ITTAnonymous.value | ITTPrincipalName.value
1720: | ITTX509CertChain.value
1721: | ITTDistinguishedName.value);
1722: sasStruct.setTargetSupports(IdentityAssertion.value);
1723: }
1724:
1725: // and then, set our SAS component
1726: sasComponent = new SasComponent(transportStruct, asStruct,
1727: sasStruct);
1728:
1729: }
1730:
1731: /**
1732: * @return the sasComponent.
1733: */
1734: public SasComponent getSasComponent() {
1735: return sasComponent;
1736: }
1737:
1738: /**
1739: * @param sasComponent The sasComponent to set.
1740: */
1741: public void setSasComponent(SasComponent sasComponent) {
1742: this .sasComponent = sasComponent;
1743: }
1744:
1745: /**
1746: * @return the velocity template of the cluster Distributor class for the home interface
1747: */
1748: public String getClusterHomeDistributor() {
1749: return clusterHomeDistributor;
1750: }
1751:
1752: /**
1753: * @return the velocity template of the cluster Distributor class for the remote interface
1754: */
1755: public String getClusterRemoteDistributor() {
1756: return clusterRemoteDistributor;
1757: }
1758:
1759: /**
1760: * @return true if the bean has to be replicated over the cluster
1761: */
1762: public boolean isClusterReplicated() {
1763: return clusterReplicated;
1764: }
1765:
1766: /**
1767: * Set the cluster replicated attribute
1768: * @param replicated true if the replicated mode is enabled
1769: */
1770: public void setClusterReplicated(boolean replicated) {
1771: this.clusterReplicated = replicated;
1772: }
1773: }
|