Search in sources :

Example 6 with InterfaceType

use of org.apache.openejb.InterfaceType in project tomee by apache.

the class ServerSideResolver method resolve.

@Override
public Object resolve(final EJBHomeHandler handler) {
    try {
        final EJBMetaDataImpl ejb = handler.getEjb();
        final InterfaceType interfaceType = (ejb.getRemoteInterfaceClass() == null) ? InterfaceType.BUSINESS_REMOTE_HOME : InterfaceType.EJB_HOME;
        final ArrayList<Class> interfaces = new ArrayList<Class>();
        if (interfaceType.isBusiness()) {
            interfaces.addAll(ejb.getBusinessClasses());
        } else {
            interfaces.add(ejb.getRemoteInterfaceClass());
        }
        final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
        final BeanContext beanContext = containerSystem.getBeanContext(ejb.getDeploymentID());
        return EjbHomeProxyHandler.createHomeProxy(beanContext, interfaceType, interfaces, ejb.getMainInterface());
    } catch (Exception e) {
        Logger.getInstance(LogCategory.OPENEJB_SERVER_REMOTE, "org.apache.openejb.server.util.resources").error("ServerSideResolver.resolve() failed, falling back to ClientSideResolver: " + e.getClass().getName() + ": " + e.getMessage(), e);
        return new EJBHomeProxyHandle.ClientSideResovler().resolve(handler);
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) BeanContext(org.apache.openejb.BeanContext) EJBMetaDataImpl(org.apache.openejb.client.EJBMetaDataImpl) InterfaceType(org.apache.openejb.InterfaceType) ArrayList(java.util.ArrayList)

Example 7 with InterfaceType

use of org.apache.openejb.InterfaceType in project tomee by apache.

the class ServerSideResolver method resolve.

@Override
public Object resolve(final EJBObjectHandler handler) {
    try {
        final EJBMetaDataImpl ejb = handler.getEjb();
        final InterfaceType interfaceType = (ejb.getRemoteInterfaceClass() == null) ? InterfaceType.BUSINESS_REMOTE_HOME : InterfaceType.EJB_HOME;
        final ArrayList<Class> interfaces = new ArrayList<Class>();
        if (interfaceType.isBusiness()) {
            interfaces.addAll(ejb.getBusinessClasses());
        } else {
            interfaces.add(ejb.getRemoteInterfaceClass());
        }
        final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
        final BeanContext beanContext = containerSystem.getBeanContext(ejb.getDeploymentID());
        return EjbObjectProxyHandler.createProxy(beanContext, handler.getPrimaryKey(), interfaceType, interfaces, ejb.getMainInterface());
    } catch (Exception e) {
        Logger.getInstance(LogCategory.OPENEJB_SERVER_REMOTE, "org.apache.openejb.server.util.resources").error("ServerSideResolver.resolve() failed, falling back to ClientSideResolver: " + e.getClass().getName() + ": " + e.getMessage(), e);
        return new EJBObjectProxyHandle.ClientSideResovler().resolve(handler);
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) BeanContext(org.apache.openejb.BeanContext) EJBMetaDataImpl(org.apache.openejb.client.EJBMetaDataImpl) InterfaceType(org.apache.openejb.InterfaceType) ArrayList(java.util.ArrayList)

Example 8 with InterfaceType

use of org.apache.openejb.InterfaceType in project tomee by apache.

the class JaccPermissionsBuilder method build.

public PolicyContext build(final EjbJarInfo ejbJar, final HashMap<String, BeanContext> deployments) throws OpenEJBException {
    final List<MethodPermissionInfo> normalized = new ArrayList<MethodPermissionInfo>();
    List<MethodPermissionInfo> perms = ejbJar.methodPermissions;
    for (final MethodInfo info : ejbJar.excludeList) {
        final MethodPermissionInfo perm = new MethodPermissionInfo();
        perm.excluded = true;
        perm.methods.add(info);
        perms.add(perm);
    }
    perms = MethodInfoUtil.normalizeMethodPermissionInfos(perms);
    for (final BeanContext beanContext : deployments.values()) {
        final Map<Method, MethodAttributeInfo> attributes = resolveAttributes(perms, beanContext);
        if (log.isDebugEnabled()) {
            for (final Map.Entry<Method, MethodAttributeInfo> entry : attributes.entrySet()) {
                final Method method = entry.getKey();
                final MethodPermissionInfo value = (MethodPermissionInfo) entry.getValue();
                log.debug("Security Attribute: " + method + " -- " + MethodInfoUtil.toString(value));
            }
        }
        for (final Map.Entry<Method, MethodAttributeInfo> entry : attributes.entrySet()) {
            final Method method = entry.getKey();
            final MethodPermissionInfo a = (MethodPermissionInfo) entry.getValue();
            final MethodPermissionInfo b = new MethodPermissionInfo();
            b.excluded = a.excluded;
            b.unchecked = a.unchecked;
            b.roleNames.addAll(a.roleNames);
            final MethodInfo am = a.methods.get(0);
            final MethodInfo bm = new MethodInfo();
            bm.ejbName = beanContext.getEjbName();
            bm.ejbDeploymentId = String.valueOf(beanContext.getDeploymentID());
            bm.methodIntf = am.methodIntf;
            bm.className = method.getDeclaringClass().getName();
            bm.methodName = method.getName();
            bm.methodParams = new ArrayList<String>();
            for (final Class<?> type : method.getParameterTypes()) {
                bm.methodParams.add(type.getName());
            }
            b.methods.add(bm);
            normalized.add(b);
        }
    }
    ejbJar.methodPermissions.clear();
    ejbJar.methodPermissions.addAll(normalized);
    ejbJar.excludeList.clear();
    final PolicyContext policyContext = new PolicyContext(ejbJar.moduleUri.toString());
    for (final EnterpriseBeanInfo enterpriseBean : ejbJar.enterpriseBeans) {
        final BeanContext beanContext = deployments.get(enterpriseBean.ejbDeploymentId);
        final PermissionCollection permissions = DelegatePermissionCollection.getPermissionCollection();
        final String ejbName = enterpriseBean.ejbName;
        for (final InterfaceType type : InterfaceType.values()) {
            if (type == InterfaceType.UNKNOWN) {
                continue;
            }
            for (final Class interfce : beanContext.getInterfaces(type)) {
                addPossibleEjbMethodPermissions(permissions, ejbName, type.getSpecName(), interfce);
            }
        }
        addPossibleEjbMethodPermissions(permissions, ejbName, null, beanContext.getBeanClass());
        addDeclaredEjbPermissions(ejbJar, enterpriseBean, null, permissions, policyContext);
    }
    return policyContext;
}
Also used : PermissionCollection(java.security.PermissionCollection) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) BeanContext(org.apache.openejb.BeanContext) InterfaceType(org.apache.openejb.InterfaceType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with InterfaceType

use of org.apache.openejb.InterfaceType in project tomee by apache.

the class BaseSessionContext method getBusinessObject.

public Object getBusinessObject(final Class interfce) {
    doCheck(Call.getBusinessObject);
    if (interfce == null) {
        throw new IllegalStateException("Interface argument cannot me null.");
    }
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final BeanContext di = threadContext.getBeanContext();
    final InterfaceType interfaceType = di.getInterfaceType(interfce);
    final BeanType type = di.getComponentType();
    if (interfaceType == null) {
        throw new IllegalStateException("Component has no such interface: " + interfce.getName());
    }
    if (!interfaceType.isBusiness()) {
        throw new IllegalStateException("Interface is not a business interface for this bean: " + interfce.getName());
    }
    try {
        final EjbObjectProxyHandler handler;
        switch(di.getComponentType()) {
            case STATEFUL:
                {
                    handler = new StatefulEjbObjectHandler(di, threadContext.getPrimaryKey(), interfaceType, new ArrayList<Class>(), interfce);
                    break;
                }
            case STATELESS:
                {
                    handler = new StatelessEjbObjectHandler(di, threadContext.getPrimaryKey(), interfaceType, new ArrayList<Class>(), interfce);
                    break;
                }
            case SINGLETON:
                {
                    handler = new SingletonEjbObjectHandler(di, threadContext.getPrimaryKey(), interfaceType, new ArrayList<Class>(), interfce);
                    break;
                }
            case MANAGED:
                {
                    handler = new ManagedObjectHandler(di, threadContext.getPrimaryKey(), interfaceType, new ArrayList<Class>(), interfce);
                    break;
                }
            default:
                throw new IllegalStateException("Bean is not a session bean: " + di.getComponentType());
        }
        if (InterfaceType.LOCALBEAN.equals(interfaceType)) {
            return LocalBeanProxyFactory.constructProxy(di.get(BeanContext.ProxyClass.class).getProxy(), handler);
        } else {
            final List<Class> interfaces = new ArrayList<Class>();
            interfaces.addAll(di.getInterfaces(interfaceType));
            interfaces.add(Serializable.class);
            interfaces.add(IntraVmProxy.class);
            if (BeanType.STATEFUL.equals(type) || BeanType.MANAGED.equals(type)) {
                interfaces.add(BeanContext.Removable.class);
            }
            return ProxyManager.newProxyInstance(interfaces.toArray(new Class[interfaces.size()]), handler);
        }
    } catch (final IllegalAccessException iae) {
        throw new InternalErrorException("Could not create IVM proxy for " + interfce.getName() + " interface", iae);
    }
}
Also used : StatefulEjbObjectHandler(org.apache.openejb.core.stateful.StatefulEjbObjectHandler) ManagedObjectHandler(org.apache.openejb.core.managed.ManagedObjectHandler) ArrayList(java.util.ArrayList) InternalErrorException(org.apache.openejb.InternalErrorException) EjbObjectProxyHandler(org.apache.openejb.core.ivm.EjbObjectProxyHandler) BeanContext(org.apache.openejb.BeanContext) InterfaceType(org.apache.openejb.InterfaceType) BeanType(org.apache.openejb.BeanType) SingletonEjbObjectHandler(org.apache.openejb.core.singleton.SingletonEjbObjectHandler) StatelessEjbObjectHandler(org.apache.openejb.core.stateless.StatelessEjbObjectHandler)

Aggregations

InterfaceType (org.apache.openejb.InterfaceType)9 BeanContext (org.apache.openejb.BeanContext)7 ArrayList (java.util.ArrayList)6 ContainerSystem (org.apache.openejb.spi.ContainerSystem)3 Method (java.lang.reflect.Method)2 BeanType (org.apache.openejb.BeanType)2 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)2 EJBMetaDataImpl (org.apache.openejb.client.EJBMetaDataImpl)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 PermissionCollection (java.security.PermissionCollection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Dependent (javax.enterprise.context.Dependent)1 Context (javax.enterprise.context.spi.Context)1 CreationalContext (javax.enterprise.context.spi.CreationalContext)1 AnnotatedMethod (javax.enterprise.inject.spi.AnnotatedMethod)1 ObserverMethod (javax.enterprise.inject.spi.ObserverMethod)1 Provider (javax.inject.Provider)1 NameNotFoundException (javax.naming.NameNotFoundException)1