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);
}
}
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);
}
}
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;
}
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);
}
}
Aggregations