Search in sources :

Example 81 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.

the class TransactionDemarcationComponentInterface method commonToBothInterfaces.

/**
 * This method is responsible for the logic of the test. It is called for both local and component interfaces.
 * @param descriptor the Enterprise Java Bean deployment descriptor
 * @param component for the Remote/Local interface of the Ejb.
 * @return boolean the results for this assertion i.e if a test has failed or not
 */
private boolean commonToBothInterfaces(String component, EjbSessionDescriptor descriptor, String methodIntf) {
    boolean oneFailed = false;
    try {
        Arrays.sort(EJBObjectMethods);
        // retrieve the component interface methods
        VerifierTestContext context = getVerifierContext();
        ClassLoader jcl = context.getClassLoader();
        Class componentInterfaceClass = Class.forName(component, false, getVerifierContext().getClassLoader());
        Method[] componentInterfaceMethods = componentInterfaceClass.getMethods();
        boolean lookForIt = false;
        for (int i = 0; i < componentInterfaceMethods.length; i++) {
            if (Arrays.binarySearch(EJBObjectMethods, componentInterfaceMethods[i].getName()) < 0) {
                try {
                    ContainerTransaction containerTransaction = null;
                    boolean resolved = false;
                    if (!descriptor.getMethodContainerTransactions().isEmpty()) {
                        for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
                            lookForIt = false;
                            MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
                            // style 1)
                            if (methodDescriptor.getName().equals(MethodDescriptor.ALL_METHODS)) {
                                // if Remote - PASS
                                if (methodDescriptor.getEjbClassSymbol() == null) {
                                    lookForIt = true;
                                } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE) || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) {
                                    lookForIt = true;
                                // if empty String PASS
                                } else if (methodDescriptor.getEjbClassSymbol().equals("")) {
                                    lookForIt = true;
                                } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME) || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) {
                                    lookForIt = false;
                                // else (Bogus)
                                } else {
                                    // carry on & don't look for
                                    // container transaction
                                    lookForIt = false;
                                }
                            } else if (methodDescriptor.getParameterClassNames() == null) {
                                // if (getEjbClassSybol() is Remote or is the empty String AND if componentInterfaceMethods[i].getName().equals(methodDescriptor.getName())
                                if (((methodDescriptor.getEjbClassSymbol() == null) || methodDescriptor.getEjbClassSymbol().equals("") || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE) || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) && (componentInterfaceMethods[i].getName().equals(methodDescriptor.getName()))) {
                                    // PASS
                                    lookForIt = true;
                                } else {
                                    // carry on
                                    lookForIt = false;
                                }
                            } else {
                                if (((methodDescriptor.getEjbClassSymbol() == null) || methodDescriptor.getEjbClassSymbol().equals("") || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE) || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) && (componentInterfaceMethods[i].getName().equals(methodDescriptor.getName())) && (MethodUtils.stringArrayEquals(methodDescriptor.getParameterClassNames(), (new MethodDescriptor(componentInterfaceMethods[i], methodIntf)).getParameterClassNames()))) {
                                    // PASS
                                    lookForIt = true;
                                } else {
                                    // CARRY ON
                                    lookForIt = false;
                                }
                            }
                            if (lookForIt) {
                                containerTransaction = (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor);
                                if (containerTransaction != null) {
                                    String transactionAttribute = containerTransaction.getTransactionAttribute();
                                    // don't need this check here
                                    if (ContainerTransaction.NOT_SUPPORTED.equals(transactionAttribute) || ContainerTransaction.SUPPORTS.equals(transactionAttribute) || ContainerTransaction.REQUIRED.equals(transactionAttribute) || ContainerTransaction.REQUIRES_NEW.equals(transactionAttribute) || ContainerTransaction.MANDATORY.equals(transactionAttribute) || ContainerTransaction.NEVER.equals(transactionAttribute) || (!transactionAttribute.equals(""))) {
                                        addGoodDetails(result, compName);
                                        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid: TransactionAttribute [ {0} ] for method [ {1} ] is defined for component interface [ {2} ]", new Object[] { transactionAttribute, componentInterfaceMethods[i].getName(), component }));
                                        resolved = true;
                                    } else {
                                        oneFailed = true;
                                        addErrorDetails(result, compName);
                                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: TransactionAttribute [ {0} ] for method [ {1} ] is not valid.   Transaction attributes must be defined for all methods of component interface [ {2} ].", new Object[] { transactionAttribute, componentInterfaceMethods[i].getName(), component }));
                                    }
                                } else {
                                    oneFailed = true;
                                    addErrorDetails(result, compName);
                                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failedException", "Error: TransactionAttribute is null for method [ {0} ]", new Object[] { methodDescriptor.getName() }));
                                }
                            }
                        }
                        // did you resolve the last one okay?
                        if (!resolved) {
                            /*
                                // This if-stmt code is a workaround introduced by Harminder
                                // because currently methodDescriptor.getEjbClassSymbol() is
                                // returning NULL
                                //if (allMethods){
                                if (!wildCardWasPresent) {
*/
                            oneFailed = true;
                            addErrorDetails(result, compName);
                            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: Transaction attributes must be specified for the methods defined in the component interface [ {0} ].  Method [ {1} ] has no transaction attribute defined within this bean [ {2} ].", new Object[] { component, componentInterfaceMethods[i].getName(), descriptor.getName() }));
                        /*
                                }
                                else {
                                             result.addGoodDetails(smh.getLocalString
                                                                   ("tests.componentNameConstructor",
                                                                    "For [ {0} ]",
                                                                    new Object[] {compName.toString()}));
					    result.addGoodDetails(smh.getLocalString
								  (getClass().getName() + ".passed",
								   "Valid: TransactionAttribute [ {0} ] for method [ {1} ] is defined for component interface [ {2} ]", new Object[] {"*", "*",component}));
                              }
                              // End of workaround code. Note : this else also has to be removed once
                              // the original bug of methodDesc.getEjbClassSymbol() is fixed

*/
                        }
                    } else {
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed2", "Error: There are no transaction attributes within this bean [ {0} ].  Transaction attributes must be specified for the methods defined in the component interface [ {1} ].  Method [ {2} ] has no transaction attribute defined.", new Object[] { descriptor.getName(), component, componentInterfaceMethods[i].getName() }));
                    }
                    if (oneFailed == true)
                        return oneFailed;
                } catch (Exception e) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: Component interface [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { component, e.getMessage(), descriptor.getName() }));
                    return oneFailed;
                }
            } else // if you found a business method
            {
                // bug 6383704
                if (componentInterfaceMethods[i].getName().equals("remove")) {
                    for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
                        MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
                        if (methodDescriptor.getName().equals("remove")) {
                            oneFailed = true;
                            addErrorDetails(result, compName);
                            result.failed(smh.getLocalString(getClass().getName() + ".failedExcep", "Error: Method [ {0} ] should not be assigned a transaction attribute.", new Object[] { methodDescriptor.getName() }));
                            break;
                        }
                    }
                }
            }
        }
        // for all component interface methods
        return oneFailed;
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: Component interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", new Object[] { component, descriptor.getName() }));
        return oneFailed;
    }
}
Also used : Enumeration(java.util.Enumeration) VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction)

Example 82 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.

the class TransactionDemarcationSessionSynchronizationInterface method check.

/**
 * Optionally implemented SessionSynchronization interface transaction
 * demarcation test.
 * If an enterprise bean implements the javax.ejb.SessionSynchronization
 * interface, the Application Assembler can specify only the following values
 * for the transaction attributes of the bean's methods:
 *   Required
 *   RequiresNew
 *   Mandatory
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean oneFound = false;
    if (descriptor instanceof EjbSessionDescriptor) {
        try {
            VerifierTestContext context = getVerifierContext();
            ClassLoader jcl = context.getClassLoader();
            Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
            // walk up the class tree
            do {
                Class[] interfaces = c.getInterfaces();
                for (int i = 0; i < interfaces.length; i++) {
                    if (interfaces[i].getName().equals("javax.ejb.SessionSynchronization")) {
                        oneFound = true;
                        break;
                    }
                }
            } while ((c = c.getSuperclass()) != null);
        } catch (ClassNotFoundException e) {
            Verifier.debug(e);
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: [ {0} ] class not found.", new Object[] { descriptor.getEjbClassName() }));
            return result;
        }
        // Required, RequiresNew, Mandatory
        if (oneFound) {
            String transactionAttribute = "";
            ContainerTransaction containerTransaction = null;
            boolean oneFailed = false;
            if (!descriptor.getMethodContainerTransactions().isEmpty()) {
                for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
                    MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
                    containerTransaction = (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor);
                    if (!(containerTransaction != null && properAttribDefined(containerTransaction))) {
                        transactionAttribute = containerTransaction.getTransactionAttribute();
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: TransactionAttribute [ {0} ] for method [ {1} ] is not valid.", new Object[] { transactionAttribute, methodDescriptor.getName() }));
                    }
                }
            }
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "TransactionAttributes are defined properly for the bean"));
    }
    return result;
}
Also used : Enumeration(java.util.Enumeration) VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) Result(com.sun.enterprise.tools.verifier.Result) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 83 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.

the class EJBSecurityManager method convertEJBMethodPermissions.

/**
 * This method converts the dd in two phases.
 * Phase 1:
 * gets a map representing the methodPermission elements exactly as they
 * occured for the ejb in the dd. The map is keyed by method-permission
 * element and each method-permission is mapped to a list of method
 * elements representing the method elements of the method permision
 * element. Each method element is converted to a corresponding
 * EJBMethodPermission and added, based on its associated method-permission,
 * to the policy configuration object.
 * phase 2:
 * configures additional EJBMethodPermission policy statements
 * for the purpose of optimizing Permissions.implies matching by the
 * policy provider. This phase also configures unchecked policy
 * statements for any uncovered methods. This method gets the list
 * of method descriptors for the ejb from the EjbDescriptor object.
 * For each method descriptor, it will get a list of MethodPermission
 * objects that signify the method permissions for the Method and
 * convert each to a corresponding EJBMethodPermission to be added
 * to the policy configuration object.
 *
 * @param eDescriptor the ejb descriptor for this EJB.
 * @param pcid,       the policy context identifier.
 */
private static void convertEJBMethodPermissions(EjbDescriptor eDescriptor, String pcid) throws PolicyContextException {
    PolicyConfiguration pc = getPolicyFactory().getPolicyConfiguration(pcid, false);
    // of PolicyConfigurationFactory
    assert pc != null;
    String eName = eDescriptor.getName();
    Permissions uncheckedPermissions = null;
    Permissions excludedPermissions = null;
    HashMap rolePermissionsTable = null;
    EJBMethodPermission ejbmp = null;
    // phase 1
    Map mpMap = eDescriptor.getMethodPermissionsFromDD();
    if (mpMap != null) {
        Iterator mpIt = mpMap.entrySet().iterator();
        while (mpIt.hasNext()) {
            Map.Entry entry = (Map.Entry) mpIt.next();
            MethodPermission mp = (MethodPermission) entry.getKey();
            Iterator mdIt = ((ArrayList) entry.getValue()).iterator();
            while (mdIt.hasNext()) {
                MethodDescriptor md = (MethodDescriptor) mdIt.next();
                String mthdName = md.getName();
                String mthdIntf = md.getEjbClassSymbol();
                String[] mthdParams = md.getStyle() == 3 ? md.getParameterClassNames() : null;
                ejbmp = new EJBMethodPermission(eName, mthdName.equals("*") ? null : mthdName, mthdIntf, mthdParams);
                rolePermissionsTable = addToRolePermissionsTable(rolePermissionsTable, mp, ejbmp);
                uncheckedPermissions = addToUncheckedPermissions(uncheckedPermissions, mp, ejbmp);
                excludedPermissions = addToExcludedPermissions(excludedPermissions, mp, ejbmp);
            }
        }
    }
    // phase 2 - configures additional perms:
    // . to optimize performance of Permissions.implies
    // . to cause any uncovered methods to be unchecked
    Iterator mdIt = eDescriptor.getMethodDescriptors().iterator();
    while (mdIt.hasNext()) {
        MethodDescriptor md = (MethodDescriptor) mdIt.next();
        Method mthd = md.getMethod(eDescriptor);
        String mthdIntf = md.getEjbClassSymbol();
        if (mthd == null) {
            continue;
        }
        if (mthdIntf == null || mthdIntf.equals("")) {
            _logger.log(Level.SEVERE, "method_descriptor_not_defined", new Object[] { eName, md.getName(), md.getParameterClassNames() });
            continue;
        }
        ejbmp = new EJBMethodPermission(eName, mthdIntf, mthd);
        Iterator mpIt = eDescriptor.getMethodPermissionsFor(md).iterator();
        while (mpIt.hasNext()) {
            MethodPermission mp = (MethodPermission) mpIt.next();
            rolePermissionsTable = addToRolePermissionsTable(rolePermissionsTable, mp, ejbmp);
            uncheckedPermissions = addToUncheckedPermissions(uncheckedPermissions, mp, ejbmp);
            excludedPermissions = addToExcludedPermissions(excludedPermissions, mp, ejbmp);
        }
    }
    if (uncheckedPermissions != null) {
        pc.addToUncheckedPolicy(uncheckedPermissions);
    }
    if (excludedPermissions != null) {
        pc.addToExcludedPolicy(excludedPermissions);
    }
    if (rolePermissionsTable != null) {
        Iterator roleIt = rolePermissionsTable.entrySet().iterator();
        while (roleIt.hasNext()) {
            Map.Entry entry = (Map.Entry) roleIt.next();
            pc.addToRole((String) entry.getKey(), (Permissions) entry.getValue());
        }
    }
}
Also used : HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) EJBMethodPermission(javax.security.jacc.EJBMethodPermission) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EJBMethodPermission(javax.security.jacc.EJBMethodPermission) MethodPermission(com.sun.enterprise.deployment.MethodPermission) Permissions(java.security.Permissions) Iterator(java.util.Iterator) PolicyConfiguration(javax.security.jacc.PolicyConfiguration) Map(java.util.Map) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap)

Example 84 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.

the class PersistentEJBTimerService method createSchedulesOnServer.

/**
 * Called in a clustered environment to eagerly create automatic persistent timers
 * on the specific server instance.
 */
public void createSchedulesOnServer(EjbDescriptor ejbDescriptor, String server_name) {
    Map<MethodDescriptor, List<ScheduledTimerDescriptor>> schedules = new HashMap<MethodDescriptor, List<ScheduledTimerDescriptor>>();
    for (ScheduledTimerDescriptor schd : ejbDescriptor.getScheduledTimerDescriptors()) {
        MethodDescriptor method = schd.getTimeoutMethod();
        if (method != null && schd.getPersistent()) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "... processing " + method);
            }
            List<ScheduledTimerDescriptor> list = schedules.get(method);
            if (list == null) {
                list = new ArrayList<ScheduledTimerDescriptor>();
                schedules.put(method, list);
            }
            list.add(schd);
        }
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "EJBTimerService - creating schedules for " + ejbDescriptor.getUniqueId());
    }
    createSchedules(ejbDescriptor.getUniqueId(), ejbDescriptor.getApplication().getUniqueId(), schedules, server_name);
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "EJBTimerService - finished processing schedules for BEAN ID: " + ejbDescriptor.getUniqueId());
    }
}
Also used : HashMap(java.util.HashMap) ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) List(java.util.List) ArrayList(java.util.ArrayList) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 85 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.

the class HazelcastTimerStore method createSchedulesOnServer.

@Override
public void createSchedulesOnServer(EjbDescriptor ejbDescriptor, String server_name) {
    Map<MethodDescriptor, List<ScheduledTimerDescriptor>> schedules = new HashMap<MethodDescriptor, List<ScheduledTimerDescriptor>>();
    for (ScheduledTimerDescriptor schd : ejbDescriptor.getScheduledTimerDescriptors()) {
        MethodDescriptor method = schd.getTimeoutMethod();
        if (method != null && schd.getPersistent()) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "... processing " + method);
            }
            List<ScheduledTimerDescriptor> list = schedules.get(method);
            if (list == null) {
                list = new ArrayList<ScheduledTimerDescriptor>();
                schedules.put(method, list);
            }
            list.add(schd);
        }
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "EJBTimerService - creating schedules for " + ejbDescriptor.getUniqueId());
    }
    createSchedules(ejbDescriptor.getUniqueId(), ejbDescriptor.getApplication().getUniqueId(), schedules, server_name);
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "EJBTimerService - finished processing schedules for BEAN ID: " + ejbDescriptor.getUniqueId());
    }
}
Also used : HashMap(java.util.HashMap) ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Aggregations

MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)97 Method (java.lang.reflect.Method)37 Iterator (java.util.Iterator)25 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)23 Set (java.util.Set)18 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)17 Enumeration (java.util.Enumeration)16 ArrayList (java.util.ArrayList)12 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)11 MethodPermission (com.sun.enterprise.deployment.MethodPermission)10 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)10 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)10 Result (com.sun.enterprise.tools.verifier.Result)9 HashSet (java.util.HashSet)9 Vector (java.util.Vector)7 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)7 MethodNode (com.sun.enterprise.deployment.node.MethodNode)6 Collection (java.util.Collection)6 HashMap (java.util.HashMap)6 ScheduledTimerDescriptor (org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor)6