Search in sources :

Example 11 with MethodDescriptor

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

the class EjbMethodIntfElement method check.

/**
 * The method-intf element must be one of the following "Remote" or "Home" or "LocalHome" or "Local".
 *
 * @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();
    // method-intf don't make sense for messagedriven bean
    if (descriptor instanceof EjbMessageBeanDescriptor) {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no <method-intf> elements within this bean [ {0} ]", new Object[] { descriptor.getName() }));
        return result;
    }
    // <ejb-class>verifier.ejb.hello.BogusEJB...
    try {
        boolean na = false;
        boolean na1 = false;
        boolean oneFailed = false;
        if (!descriptor.getMethodContainerTransactions().isEmpty()) {
            for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
                MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
                String methodIntf = methodDescriptor.getEjbClassSymbol();
                if (methodIntf == null) {
                    // || methodIntf.equals("")
                    continue;
                }
                // Home Remote LocalHome Local ServiceEndpoint
                if (!((methodIntf.equals(MethodDescriptor.EJB_REMOTE)) || (methodIntf.equals(MethodDescriptor.EJB_HOME)) || (methodIntf.equals(MethodDescriptor.EJB_LOCALHOME)) || (methodIntf.equals(MethodDescriptor.EJB_LOCAL)) || (methodIntf.equals(MethodDescriptor.EJB_WEB_SERVICE)) || (methodIntf.length() == 0))) {
                    // The method-intf element must be one of the following "Remote" or "Home"
                    // if (!((methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE))  ||
                    // (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) ||
                    // (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) ||
                    // (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) ||
                    // (methodDescriptor.getEjbClassSymbol().length()==0))) {
                    oneFailed = true;
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Container transaction method [ {0} ] method-intf element [ {1} ] must be one of the following: [ {2} ] or [ {3} ] or [ {4} ] or [ {5} ]  within bean [ {6} ]", new Object[] { methodDescriptor.getName(), methodDescriptor.getEjbClassSymbol(), MethodDescriptor.EJB_REMOTE.toString(), MethodDescriptor.EJB_HOME, MethodDescriptor.EJB_LOCAL, MethodDescriptor.EJB_LOCALHOME, descriptor.getName() }));
                } else {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Container Transaction method [ {0} ] method-intf element [ {1} ] is one of the following:  [ {2} ] or [ {3} ] or [ {4} ] or [ {5} ]  within bean [ {6} ]", new Object[] { methodDescriptor.getName(), methodDescriptor.getEjbClassSymbol(), MethodDescriptor.EJB_REMOTE, MethodDescriptor.EJB_HOME, MethodDescriptor.EJB_LOCAL, MethodDescriptor.EJB_LOCALHOME, descriptor.getName() }));
                }
            }
        } else {
            na = true;
        }
        Map permissionedMethods = descriptor.getPermissionedMethodsByPermission();
        if (permissionedMethods.size() > 0) {
            for (Iterator e = permissionedMethods.keySet().iterator(); e.hasNext(); ) {
                MethodPermission nextPermission = (MethodPermission) e.next();
                Set permissionedMethodsForRole = (HashSet) permissionedMethods.get(nextPermission);
                if (permissionedMethodsForRole != null) {
                    Set convertedPermissionedMethods = new HashSet();
                    for (Iterator itr = permissionedMethodsForRole.iterator(); itr.hasNext(); ) {
                        MethodDescriptor methodDescriptor = (MethodDescriptor) itr.next();
                        String methodIntf = methodDescriptor.getEjbClassSymbol();
                        if (methodIntf == null) {
                            // || methodIntf.equals("")
                            continue;
                        }
                        // Home Remote LocalHome Local ServiceEndpoint
                        if (!((methodIntf.equals(MethodDescriptor.EJB_REMOTE)) || (methodIntf.equals(MethodDescriptor.EJB_HOME)) || (methodIntf.equals(MethodDescriptor.EJB_LOCALHOME)) || (methodIntf.equals(MethodDescriptor.EJB_LOCAL)) || (methodIntf.equals(MethodDescriptor.EJB_WEB_SERVICE)) || (methodIntf.length() == 0))) {
                            // The method-intf element must be one of the following "Remote" or "Home"
                            // if (!((methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE))  ||
                            // (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) ||
                            // (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) ||
                            // (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) ||
                            // (methodDescriptor.getEjbClassSymbol().length()==0))) {
                            oneFailed = true;
                            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: Method permissions method [ {0} ] method-intf element [ {1} ] must be one of the interfaces of the bean [ {2} ]", new Object[] { methodDescriptor.getName(), methodDescriptor.getEjbClassSymbol(), descriptor.getName() }));
                        } else {
                            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed1", "Method permissions method [ {0} ] method-intf element [ {1} ] is one of the interfaces of the  bean [ {2} ]", new Object[] { methodDescriptor.getName(), methodDescriptor.getEjbClassSymbol(), descriptor.getName() }));
                        }
                    }
                }
            }
        } else {
            na1 = true;
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (na && na1) {
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no <method-intf> elements within this bean [ {0} ]", new Object[] { descriptor.getName() }));
        } else {
            result.setStatus(Result.PASSED);
        }
        return result;
    } catch (Throwable t) {
        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { descriptor.getName(), t.getMessage(), descriptor.getName() }));
        return result;
    }
}
Also used : Enumeration(java.util.Enumeration) Set(java.util.Set) HashSet(java.util.HashSet) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) MethodPermission(com.sun.enterprise.deployment.MethodPermission) Result(com.sun.enterprise.tools.verifier.Result) EjbMessageBeanDescriptor(org.glassfish.ejb.deployment.descriptor.EjbMessageBeanDescriptor) Iterator(java.util.Iterator) Map(java.util.Map) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) HashSet(java.util.HashSet)

Example 12 with MethodDescriptor

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

the class ContainerTransactionStyle1 method check.

/**
 * Each container transaction element consists of a list of one or more
 * method elements, and the trans-attribute element. The container transaction
 * element specifies that all the listed methods are assigned the specified
 * transaction attribute value.
 *
 * Style 1:
 *    <method>
 *      <ejb-name> EJBNAME</ejb-name>
 *      <method-name>*</method-name>
 *    </method>
 * This style is used to specify a default value of the transaction attribute
 * for the methods for which there is no Style 2 or Style 3 element specified.
 * There must be at most one container transaction element that uses the Style 1
 * method element for a given enterprise bean.
 *
 * @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();
    // <ejb-class>verifier.ejb.hello.BogusEJB...
    try {
        boolean oneFailed = false;
        boolean na = false;
        int foundWildCard = 0;
        if (!descriptor.getMethodContainerTransactions().isEmpty()) {
            for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
                MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
                if (methodDescriptor.getName().equals(MethodDescriptor.ALL_METHODS)) {
                    foundWildCard++;
                }
            }
            // DOL only saves one container tx with "*", so can't fail...
            if (foundWildCard == 1) {
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.passed(smh.getLocalString(getClass().getName() + ".passed", "Container Transaction method name [ {0} ] defined only once in [ {1} ] bean.", new Object[] { MethodDescriptor.ALL_METHODS, descriptor.getName() }));
            } else if (foundWildCard > 1) {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Container Transaction method name [ {0} ] is defined [ {1} ] times in [ {2} ] bean.  Method name container transaction style [ {3} ] is allowed only once per bean.", new Object[] { MethodDescriptor.ALL_METHODS, new Integer(foundWildCard), descriptor.getName(), MethodDescriptor.ALL_METHODS }));
            } else {
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Container Transaction method name [ {0} ] not defined in [ {1} ] bean.", new Object[] { MethodDescriptor.ALL_METHODS, descriptor.getName() }));
            }
        } else {
            // if (methodDescriptorsIterator.hasNext())
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no method permissions within this bean [ {0} ]", new Object[] { descriptor.getName() }));
        }
        return result;
    } catch (Throwable t) {
        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { descriptor.getName(), t.getMessage(), descriptor.getName() }));
        return result;
    }
}
Also used : Enumeration(java.util.Enumeration) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 13 with MethodDescriptor

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

the class BaseAuthConfig method getContextForMethod.

/* When method argument is null, returns the default AC
     * if there is one, or the onePolicy shared by all methods
     * if there is one, or throws an error.
     * method is called with null argument when the method
     * cannot be determined (e.g. when the message is encrypted)
     */
private Object getContextForMethod(Method m) {
    Object rvalue = null;
    synchronized (contextLock) {
        if (defaultContext_ != null) {
            rvalue = defaultContext_;
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "WSS: ForMethod returning default_context: {0}", rvalue);
            }
            return rvalue;
        }
    }
    if (m != null) {
        int match = -1;
        MethodDescriptor targetMD = new MethodDescriptor(m);
        for (int i = 0; i < messageSecurityDescriptors_.size(); i++) {
            if (isMatchingMSD(targetMD, (MessageSecurityDescriptor) messageSecurityDescriptors_.get(i))) {
                if (match < 0) {
                    match = i;
                } else if (!policiesAreEqual((MessageSecurityDescriptor) messageSecurityDescriptors_.get(match), (MessageSecurityDescriptor) messageSecurityDescriptors_.get(i))) {
                    // set to unprotected because of conflicting policies
                    rvalue = explicitNull;
                    match = -1;
                    if (logger.isLoggable(Level.FINE)) {
                        logger.log(Level.FINE, "WSS: ForMethod detected conflicting policies: {0}.{1}", new Object[] { match, i });
                    }
                    break;
                }
            }
        }
        if (match >= 0) {
            rvalue = contexts_.get(match);
            if (rvalue == null) {
                rvalue = explicitNull;
            }
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "WSS: ForMethod returning matched context: {0}", rvalue);
            }
        }
    } else if (onePolicy_ && contexts_.size() > 0) {
        // ISSUE: since the method is undefined we will not be
        // able to tell if the defined policy covers this method.
        // We will be optimistic and try the policy, because
        // the server will reject the call if the method is not
        // covered by the policy.
        // If the policy is not null, there remains a problem at the
        // client on the response side, as it is possible that the
        // client will enforce the wrong policy on the response.
        // For this reason, messages in sun-application-client.xml
        // should be keyed by operation-name.
        rvalue = contexts_.get(0);
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, "WSS: ForMethod resorting to first context: {0}", rvalue);
        }
    } else {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("WSS: Unable to select policy for SOAP Message");
        }
        throw new RuntimeException("Unable to select policy for Message");
    }
    return rvalue;
}
Also used : MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 14 with MethodDescriptor

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

the class BaseAuthConfig method isMatchingMSD.

private static boolean isMatchingMSD(MethodDescriptor targetMD, MessageSecurityDescriptor mSD) {
    ArrayList messageDescriptors = mSD.getMessageDescriptors();
    if (messageDescriptors.isEmpty()) {
        // element, and the deployment will be allowed to succeed.
        return true;
    }
    for (int i = 0; i < messageDescriptors.size(); i++) {
        MessageDescriptor nextMD = (MessageDescriptor) messageDescriptors.get(i);
        MethodDescriptor mD = nextMD.getMethodDescriptor();
        String opName = nextMD.getOperationName();
        if (opName == null && (mD == null || mD.implies(targetMD))) {
            return true;
        }
    }
    return false;
}
Also used : MessageDescriptor(com.sun.enterprise.deployment.runtime.common.MessageDescriptor) ArrayList(java.util.ArrayList) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 15 with MethodDescriptor

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

the class AbstractAuthAnnotationHandler method postProcessAnnotation.

/**
 * This method is for processing security annotation associated to ejb.
 * Dervied class call this method may like to override
 *
 * protected void processEjbMethodSecurity(Annotation authAnnotation,
 *         MethodDescriptor md, EjbDescriptor ejbDesc)
 */
@Override
public void postProcessAnnotation(AnnotationInfo ainfo, AnnotatedElementHandler aeHandler) throws AnnotationProcessorException {
    EjbContext ejbContext = (EjbContext) aeHandler;
    EjbDescriptor ejbDesc = ejbContext.getDescriptor();
    Annotation authAnnotation = ainfo.getAnnotation();
    if (!ejbContext.isInherited() && (ejbDesc.getMethodPermissionsFromDD() == null || ejbDesc.getMethodPermissionsFromDD().size() == 0)) {
        for (MethodDescriptor md : getMethodAllDescriptors(ejbDesc)) {
            processEjbMethodSecurity(authAnnotation, md, ejbDesc);
        }
    } else {
        Class classAn = (Class) ainfo.getAnnotatedElement();
        for (Object next : ejbDesc.getSecurityBusinessMethodDescriptors()) {
            MethodDescriptor md = (MethodDescriptor) next;
            // override by existing info
            if (classAn.equals(ejbContext.getDeclaringClass(md)) && !hasMethodPermissionsFromDD(md, ejbDesc)) {
                processEjbMethodSecurity(authAnnotation, md, ejbDesc);
            }
        }
    }
}
Also used : MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) Annotation(java.lang.annotation.Annotation)

Aggregations

MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)108 Method (java.lang.reflect.Method)42 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)26 Iterator (java.util.Iterator)21 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)17 Enumeration (java.util.Enumeration)14 Set (java.util.Set)14 ArrayList (java.util.ArrayList)13 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)11 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)11 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)10 Result (com.sun.enterprise.tools.verifier.Result)9 MethodPermission (com.sun.enterprise.deployment.MethodPermission)8 MethodNode (com.sun.enterprise.deployment.node.MethodNode)7 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)7 Node (org.w3c.dom.Node)7 List (java.util.List)6 ScheduledTimerDescriptor (org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor)6 DeploymentDescriptorNode (com.sun.enterprise.deployment.node.DeploymentDescriptorNode)5 HashMap (java.util.HashMap)5