Search in sources :

Example 1 with MethodPermission

use of com.sun.enterprise.deployment.MethodPermission 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 2 with MethodPermission

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

the class EjbBundleNode method addDescriptor.

@Override
public void addDescriptor(Object newDescriptor) {
    if (newDescriptor instanceof EjbDescriptor) {
        descriptor.addEjb((EjbDescriptor) newDescriptor);
    } else if (newDescriptor instanceof RelationshipDescriptor) {
        descriptor.addRelationship((RelationshipDescriptor) newDescriptor);
    } else if (newDescriptor instanceof MethodPermissionDescriptor) {
        MethodPermissionDescriptor nd = (MethodPermissionDescriptor) newDescriptor;
        MethodDescriptor[] array = nd.getMethods();
        for (int i = 0; i < array.length; i++) {
            EjbDescriptor target = descriptor.getEjbByName(array[i].getEjbName());
            MethodPermission[] mps = nd.getMethodPermissions();
            for (int j = 0; j < mps.length; j++) {
                DOLUtils.getDefaultLogger().fine("Adding mp " + mps[j] + " to " + array[i] + " for ejb " + array[i].getEjbName());
                target.addPermissionedMethod(mps[j], array[i]);
            }
        }
    } else
        super.addDescriptor(newDescriptor);
}
Also used : MethodPermissionDescriptor(com.sun.enterprise.deployment.MethodPermissionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) MethodPermission(com.sun.enterprise.deployment.MethodPermission)

Example 3 with MethodPermission

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

the class EjbBundleNode method addMethodPermissions.

private void addMethodPermissions(EjbDescriptor ejb, Map mpToMethods, Vector excludedMethods, MethodPermissionNode mpNode, Node assemblyNode) {
    if (mpToMethods == null || mpToMethods.size() == 0) {
        return;
    }
    for (Object o : mpToMethods.entrySet()) {
        Map.Entry entry = (Map.Entry) o;
        MethodPermission mp = (MethodPermission) entry.getKey();
        if (mp.isExcluded()) {
            // we need to be sure the method descriptors knows who owns them
            Set methods = (Set) entry.getValue();
            excludedMethods.addAll(methods);
        } else {
            MethodPermissionDescriptor mpd = new MethodPermissionDescriptor();
            mpd.addMethodPermission(mp);
            mpd.addMethods((Set) mpToMethods.get(mp));
            mpNode.writeDescriptor(assemblyNode, EjbTagNames.METHOD_PERMISSION, mpd, ejb);
        }
    }
}
Also used : MethodPermissionDescriptor(com.sun.enterprise.deployment.MethodPermissionDescriptor) MethodPermission(com.sun.enterprise.deployment.MethodPermission)

Example 4 with MethodPermission

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

the class MethodPermissionNode method writeDescriptorInNode.

/**
 * Write the descriptor in a DOM tree which root element is provided
 *
 * @param subNode the root element for the DOM fragment
 * @param descriptor the method permisison descriptor
 * @param ejb the ejb descriptor the above method permission belongs to
 */
public Node writeDescriptorInNode(Node subNode, MethodPermissionDescriptor descriptor, EjbDescriptor ejb) {
    writeLocalizedDescriptions(subNode, descriptor);
    MethodPermission[] mps = descriptor.getMethodPermissions();
    if (mps.length == 0)
        return null;
    if (!mps[0].isExcluded()) {
        if (mps[0].isUnchecked()) {
            appendChild(subNode, EjbTagNames.UNCHECKED);
        } else {
            for (int i = 0; i < mps.length; i++) {
                appendTextChild(subNode, TagNames.ROLE_NAME, mps[i].getRole().getName());
            }
        }
    }
    MethodDescriptor[] methods = descriptor.getMethods();
    MethodNode mn = new MethodNode();
    for (int i = 0; i < methods.length; i++) {
        String ejbName = ejb.getName();
        mn.writeDescriptor(subNode, EjbTagNames.METHOD, methods[i], ejbName);
    }
    return subNode;
}
Also used : MethodNode(com.sun.enterprise.deployment.node.MethodNode) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) MethodPermission(com.sun.enterprise.deployment.MethodPermission)

Example 5 with MethodPermission

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

the class MethodPermissionNode method setElementValue.

/**
 * receives notification of the value for a particular tag
 *
 * @param element the xml element
 * @param value it's associated value
 */
@Override
public void setElementValue(XMLElement element, String value) {
    if (TagNames.ROLE_NAME.equals(element.getQName())) {
        Role role = new Role(value);
        descriptor.addMethodPermission(new MethodPermission(role));
    } else {
        super.setElementValue(element, value);
    }
}
Also used : Role(org.glassfish.security.common.Role) MethodPermission(com.sun.enterprise.deployment.MethodPermission)

Aggregations

MethodPermission (com.sun.enterprise.deployment.MethodPermission)19 Iterator (java.util.Iterator)11 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)10 Set (java.util.Set)8 HashSet (java.util.HashSet)7 OrderedSet (com.sun.enterprise.deployment.OrderedSet)6 Map (java.util.Map)4 Role (org.glassfish.security.common.Role)4 MethodPermissionDescriptor (com.sun.enterprise.deployment.MethodPermissionDescriptor)2 RoleReference (com.sun.enterprise.deployment.RoleReference)2 Result (com.sun.enterprise.tools.verifier.Result)2 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)2 Enumeration (java.util.Enumeration)2 HashMap (java.util.HashMap)2 RolesAllowed (javax.annotation.security.RolesAllowed)2 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 EjbIORConfigurationDescriptor (com.sun.enterprise.deployment.EjbIORConfigurationDescriptor)1 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)1 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)1