Search in sources :

Example 1 with EjbBundleDescriptorImpl

use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project jersey by jersey.

the class EjbComponentProvider method registerEjbInterceptor.

private void registerEjbInterceptor() {
    try {
        final Object interceptor = new EjbComponentInterceptor(injectionManager);
        initialContext = getInitialContext();
        final EjbContainerUtil ejbUtil = EjbContainerUtilImpl.getInstance();
        final ApplicationInfo appInfo = getApplicationInfo(ejbUtil);
        final List<String> tempLibNames = new LinkedList<>();
        for (ModuleInfo moduleInfo : appInfo.getModuleInfos()) {
            final String jarName = moduleInfo.getName();
            if (jarName.endsWith(".jar") || jarName.endsWith(".war")) {
                final String moduleName = jarName.substring(0, jarName.length() - 4);
                tempLibNames.add(moduleName);
                final Object bundleDescriptor = moduleInfo.getMetaData(EjbBundleDescriptorImpl.class.getName());
                if (bundleDescriptor instanceof EjbBundleDescriptorImpl) {
                    final Collection<EjbDescriptor> ejbs = ((EjbBundleDescriptorImpl) bundleDescriptor).getEjbs();
                    for (final EjbDescriptor ejb : ejbs) {
                        final BaseContainer ejbContainer = EjbContainerUtilImpl.getInstance().getContainer(ejb.getUniqueId());
                        try {
                            AccessController.doPrivileged(new PrivilegedExceptionAction() {

                                @Override
                                public Object run() throws Exception {
                                    final Method registerInterceptorMethod = BaseContainer.class.getDeclaredMethod("registerSystemInterceptor", java.lang.Object.class);
                                    registerInterceptorMethod.setAccessible(true);
                                    registerInterceptorMethod.invoke(ejbContainer, interceptor);
                                    return null;
                                }
                            });
                        } catch (PrivilegedActionException pae) {
                            final Throwable cause = pae.getCause();
                            LOGGER.log(Level.WARNING, LocalizationMessages.EJB_INTERCEPTOR_BINDING_WARNING(ejb.getEjbClassName()), cause);
                        }
                    }
                }
            }
        }
        libNames.addAll(tempLibNames);
        final Object interceptorBinder = initialContext.lookup("java:org.glassfish.ejb.container.interceptor_binding_spi");
        // the name
        if (interceptorBinder == null) {
            throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_BIND_API_NOT_AVAILABLE());
        }
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction() {

                @Override
                public Object run() throws Exception {
                    Method interceptorBinderMethod = interceptorBinder.getClass().getMethod("registerInterceptor", java.lang.Object.class);
                    interceptorBinderMethod.invoke(interceptorBinder, interceptor);
                    EjbComponentProvider.this.ejbInterceptorRegistered = true;
                    LOGGER.log(Level.CONFIG, LocalizationMessages.EJB_INTERCEPTOR_BOUND());
                    return null;
                }
            });
        } catch (PrivilegedActionException pae) {
            throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_CONFIG_ERROR(), pae.getCause());
        }
    } catch (NamingException ex) {
        throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_BIND_API_NOT_AVAILABLE(), ex);
    } catch (LinkageError ex) {
        throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_CONFIG_LINKAGE_ERROR(), ex);
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) EjbContainerUtil(com.sun.ejb.containers.EjbContainerUtil) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) NamingException(javax.naming.NamingException) PrivilegedActionException(java.security.PrivilegedActionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BaseContainer(com.sun.ejb.containers.BaseContainer) ModuleInfo(org.glassfish.internal.data.ModuleInfo) NamingException(javax.naming.NamingException) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 2 with EjbBundleDescriptorImpl

use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.

the class CmrFields method runIndividualCmrTest.

/**
 * run an individual verifier test of a declated cmr field of the class
 *
 * @param entity the descriptor for the entity bean containing the cmp-field
 * @param info the descriptor for the declared cmr field
 * @param c the class owning the cmp field
 * @parma r the result object to use to put the test results in
 *
 * @return true if the test passed
 */
protected boolean runIndividualCmrTest(Descriptor descriptor, RelationRoleDescriptor role, Class c, Result result) {
    boolean foundIt = false;
    CMRFieldInfo info = null;
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    try {
        info = role.getCMRFieldInfo();
    } catch (Exception e) {
        addErrorDetails(result, compName);
        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: No Local interfaces defined for EJB [ {0} ]", new Object[] { descriptor.getName() }));
        return false;
    }
    if (role.getPartner().getIsMany()) {
        // must be one the collection interface
        if (info.type.getName().equals("java.util.Collection") || info.type.getName().equals("java.util.Set")) {
            foundIt = true;
        }
    } else {
        EjbBundleDescriptorImpl bundle = ((EjbDescriptor) descriptor).getEjbBundleDescriptor();
        if (((EjbDescriptor) descriptor).getLocalClassName() != null && !"".equals(((EjbDescriptor) descriptor).getLocalClassName())) {
            if (isValidInterface(info.type, bundle.getEjbs())) {
                foundIt = true;
            }
        } else {
            if ((role.getRelationshipDescriptor()).getIsBidirectional()) {
                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Invalid type assigned for container managed relationship [ {0} ] in bean [ {1} ]", new Object[] { info.name, descriptor.getName() }));
                return false;
            } else
                foundIt = true;
        }
    }
    if (foundIt) {
        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid type assigned for container managed relationship [ {0} ] in bean [ {1} ]", new Object[] { info.name, descriptor.getName() }));
    } else {
        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Invalid type assigned for container managed relationship [ {0} ] in bean [ {1} ]", new Object[] { info.name, descriptor.getName() }));
    }
    return foundIt;
}
Also used : CMRFieldInfo(org.glassfish.ejb.deployment.descriptor.CMRFieldInfo) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 3 with EjbBundleDescriptorImpl

use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.

the class DependentValueClassModifiers method runIndividualCmpFieldTest.

/**
 * run an individual verifier test of a declated cmp field of the class
 *
 * @param entity the descriptor for the entity bean containing the cmp-field
 * @param f the descriptor for the declared cmp field
 * @param c the class owning the cmp field
 * @parma r the result object to use to put the test results in
 *
 * @return true if the test passed
 */
protected boolean runIndividualCmpFieldTest(Descriptor entity, Descriptor persistentField, Class c, Result result) {
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    String fieldName = persistentField.getName();
    String getMethodName = "get" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
    Method getMethod = getMethod(c, getMethodName, null);
    if (getMethod != null) {
        Class returnType = getMethod.getReturnType();
        // check if this is a reference to a primitive or an array of primitive type
        if (returnType.isArray()) {
            returnType = returnType.getComponentType();
        }
        if (returnType.isPrimitive()) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.DependentValueClassModifiers.notApplicable", "Field [ {0} ] is not a dependent value class reference", new Object[] { fieldName }));
            return true;
        }
        if (returnType.isInterface()) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.DependentValueClassModifiers.notApplicable", "Field [ {0} ] is not a dependent value class reference", new Object[] { fieldName }));
            return true;
        }
        if (returnType.toString().startsWith("class java.")) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.DependentValueClassModifiers.notApplicable", "Field [ {0} ] is not a dependent value class reference", new Object[] { fieldName }));
            return true;
        }
        // it must be a reference to a bean's home or remote interface
        EjbBundleDescriptorImpl bundle = ((EjbDescriptor) entity).getEjbBundleDescriptor();
        if ((isValidInterface(returnType, bundle.getEjbs(), MethodDescriptor.EJB_REMOTE)) || (isValidInterface(returnType, bundle.getEjbs(), MethodDescriptor.EJB_LOCAL))) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.DependentValueClassModifiers.notApplicable", "Field [ {0} ] is not a dependent value class reference", new Object[] { fieldName }));
            return true;
        }
        // this is a reference to a dependent value class
        int modifiers = returnType.getModifiers();
        if (Modifier.isPublic(modifiers) && Modifier.isAbstract(modifiers) == false && EjbUtils.isValidSerializableType(returnType)) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.DependentValueClassModifiers.passed", "Dependent value class [ {0} ] reference by cmp field [ {1} ] is public, not abstract and serializable", new Object[] { returnType.getName(), fieldName }));
            return true;
        } else {
            result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addWarningDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.DependentValueClassModifiers.failed", "Verifier cannot find out if [ {0} ] is a Dependent value class (reference by cmp field [ {1} ]) ", new Object[] { returnType.getName(), fieldName }));
            return false;
        }
    } else {
        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.isAccessorDeclared.failed2", "Error : Cannot find accessor [ {0} ] method for [ {1} ] field ", new Object[] { getMethodName, fieldName }));
        return false;
    }
}
Also used : Method(java.lang.reflect.Method) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 4 with EjbBundleDescriptorImpl

use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.

the class ASEntBeanCmpResource method check.

public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    try {
        EjbBundleDescriptorImpl ejbBundleDesc = descriptor.getEjbBundleDescriptor();
        ResourceReferenceDescriptor cmpResource = ejbBundleDesc.getCMPResourceReference();
        if (cmpResource != null) {
            // String jndiName = cmpResource.getJndiName();
            String jndiName = getXPathValue("sun-ejb-jar/enterprise-beans/cmp-resource/jndi-name");
            if (jndiName == null || jndiName.length() == 0) {
                // 4698046
                oneFailed = true;
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-EJB cmp-resource] : jndi-name cannot be an empty string"));
            } else {
                if (jndiName.startsWith("jdbc/") || jndiName.startsWith("jdo/")) {
                    addGoodDetails(result, compName);
                    result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB cmp-resource] : jndi-name is {0}", new Object[] { jndiName }));
                } else {
                    // 4698046
                    oneWarning = true;
                    addWarningDetails(result, compName);
                    result.warning(smh.getLocalString(getClass().getName() + ".warning", "WARNING [AS-EJB cmp-resource] : The jndi-name  is {0}, the preferred jndi-name should start with  jdbc/ or jdo/", new Object[] { jndiName }));
                }
            }
            ResourcePrincipal defPrincipal = cmpResource.getResourcePrincipal();
            if (defPrincipal != null) {
                // String name = defPrincipal.getName();
                String name = getXPathValue("sun-ejb-jar/enterprise-beans/cmp-resource/default-resource-principal/name");
                if (name == null || name.length() == 0) {
                    // 4698046
                    oneFailed = true;
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-EJB default-resource-principal] :  name cannot be an empty string"));
                } else {
                    addGoodDetails(result, compName);
                    result.passed(smh.getLocalString(getClass().getName() + ".passed1", "PASSED [AS-EJB default-resource-principal] : name is {0}", new Object[] { name }));
                }
                // String password = defPrincipal.getPassword();
                char[] password = getXPathValueasCharArray("sun-ejb-jar/enterprise-beans/cmp-resource/default-resource-principal/password");
                if (password == null || password.length == 0) {
                    // 4698046
                    oneWarning = true;
                    addWarningDetails(result, compName);
                    result.warning(smh.getLocalString(getClass().getName() + ".warning1", "WARNING [AS-EJB default-resource-principal] : password is an empty string"));
                } else {
                    addGoodDetails(result, compName);
                    result.passed(smh.getLocalString(getClass().getName() + ".passed2", "PASSED [AS-EJB default-resource-principal] : password is  {0}", new Object[] { new String(password) }));
                }
                Arrays.fill(password, ' ');
            } else {
                addNaDetails(result, compName);
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-EJB cmp-resource] : default-resource-principal Element not defined"));
            }
            Float specVer = getRuntimeSpecVersion();
            if ((Float.compare(specVer.floatValue(), (new Float("2.1")).floatValue()) >= 0)) {
                // property
                result = testProperty("property", result, "sun-ejb-jar/enterprise-beans/cmp-resource/property", compName, descriptor);
                // schema-generator-properties
                result = testProperty("schema-generator-properties", result, "sun-ejb-jar/enterprise-beans/cmp-resource/schema-generator-properties/property", compName, descriptor);
            }
            if (// 4698046
            oneFailed)
                result.setStatus(Result.FAILED);
            else if (oneWarning)
                result.setStatus(Result.WARNING);
        } else {
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "NOT APPLICABLE [AS-EJB enterprise-beans] : cmp-resource element is not defined"));
        }
    } catch (Exception ex) {
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB cmp] Could not create descriptor Object."));
    }
    return result;
}
Also used : ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 5 with EjbBundleDescriptorImpl

use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.

the class LocalInterfaceExposed method check.

/**
 * Bean interface type test.
 * The bean provider must provide either Local or Remote or Both interfaces
 *
 * @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();
    if (!(descriptor instanceof EjbSessionDescriptor) && !(descriptor instanceof EjbEntityDescriptor)) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Test apply only to session or entity beans."));
        return result;
    }
    EjbBundleDescriptorImpl bundle = descriptor.getEjbBundleDescriptor();
    Iterator<EjbDescriptor> iterator = (bundle.getEjbs()).iterator();
    Set<String> localInterfaces = new HashSet<String>();
    while (iterator.hasNext()) {
        EjbDescriptor entity = iterator.next();
        if (entity.getLocalClassName() != null)
            localInterfaces.add(entity.getLocalClassName());
        localInterfaces.addAll(entity.getLocalBusinessClassNames());
    }
    ClassLoader jcl = getVerifierContext().getClassLoader();
    try {
        Set<String> remoteInterfaces = new HashSet<String>();
        if (descriptor.getRemoteClassName() != null)
            remoteInterfaces.add(descriptor.getRemoteClassName());
        remoteInterfaces.addAll(descriptor.getRemoteBusinessClassNames());
        for (String intf : remoteInterfaces) {
            Class c = Class.forName(intf, false, getVerifierContext().getClassLoader());
            Method[] methods = c.getDeclaredMethods();
            for (int i = 0; i < methods.length; i++) {
                // check all the local interfaces in the ejb bundle
                for (Iterator itr = localInterfaces.iterator(); itr.hasNext(); ) {
                    String localIntf = (String) itr.next();
                    Class returnType = methods[i].getReturnType();
                    if ((getBaseComponentType(returnType).getName()).equals(localIntf) || (contains(methods[i].getParameterTypes(), localIntf))) {
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error : Local Interface [ {0} ] has been " + "exposed in remote interface [ {1} ]", new Object[] { localIntf, c.getName() }));
                        return result;
                    }
                }
            }
        }
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Remote interface."));
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { descriptor.getRemoteClassName() }));
    }
    return result;
}
Also used : Method(java.lang.reflect.Method) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Iterator(java.util.Iterator) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl) HashSet(java.util.HashSet)

Aggregations

EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)37 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)19 Iterator (java.util.Iterator)12 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)11 Result (com.sun.enterprise.tools.verifier.Result)9 Method (java.lang.reflect.Method)7 Application (com.sun.enterprise.deployment.Application)6 Set (java.util.Set)6 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)5 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)4 DeploymentException (org.glassfish.deployment.common.DeploymentException)4 Constructor (java.lang.reflect.Constructor)3 Role (org.glassfish.security.common.Role)3 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)2 RoleReference (com.sun.enterprise.deployment.RoleReference)2 RunAsIdentityDescriptor (com.sun.enterprise.deployment.RunAsIdentityDescriptor)2 WebService (com.sun.enterprise.deployment.WebService)2 EjbBundleContext (com.sun.enterprise.deployment.annotation.context.EjbBundleContext)2 IASSecurityException (com.sun.enterprise.security.util.IASSecurityException)2 File (java.io.File)2