use of org.apache.openejb.core.ThreadContext in project tomee by apache.
the class MdbPoolContainer method release.
public void release(final BeanContext deployInfo, final Object instance) {
// get the mdb call context
ThreadContext callContext = ThreadContext.getThreadContext();
boolean contextExitRequired = false;
if (callContext == null) {
callContext = new ThreadContext(deployInfo, null);
ThreadContext.enter(callContext);
contextExitRequired = true;
}
try {
// if we have an mdb call context we need to invoke the after invoke method
final MdbCallContext mdbCallContext = callContext.get(MdbCallContext.class);
if (mdbCallContext != null) {
try {
afterInvoke(mdbCallContext.txPolicy, callContext);
} catch (final Exception e) {
logger.error("error while releasing message endpoint", e);
} finally {
if (instance != null) {
try {
instanceManager.poolInstance(callContext, instance);
} catch (OpenEJBException e) {
logger.error("error while releasing message endpoint", e);
}
}
}
}
} finally {
if (contextExitRequired) {
ThreadContext.exit(callContext);
}
}
}
use of org.apache.openejb.core.ThreadContext in project tomee by apache.
the class MdbPoolContainer method invoke.
public Object invoke(final Object deploymentId, final InterfaceType type, final Class callInterface, final Method method, final Object[] args, final Object primKey) throws OpenEJBException {
final BeanContext beanContext = getBeanContext(deploymentId);
final ThreadContext callContext = new ThreadContext(beanContext, primKey);
final Instance instance = this.instanceManager.getInstance(callContext);
try {
beforeDelivery(beanContext, instance, method, null);
final Object value = invoke(instance, method, type, args);
afterDelivery(instance);
return value;
} finally {
if (instance != null) {
if (callContext.isDiscardInstance()) {
this.instanceManager.discardInstance(callContext, instance);
} else {
this.instanceManager.poolInstance(callContext, instance);
}
}
}
}
use of org.apache.openejb.core.ThreadContext in project tomee by apache.
the class PoolEndpointHandler method beforeDelivery.
@Override
public void beforeDelivery(final Method method) throws ApplicationServerInternalException {
// verify current state
switch(state) {
case RELEASED:
throw new IllegalStateException("Message endpoint factory has been released");
case BEFORE_CALLED:
throw new IllegalStateException("beforeDelivery can not be called again until message is delivered and afterDelivery is called");
case METHOD_CALLED:
case SYSTEM_EXCEPTION:
throw new IllegalStateException("The last message delivery must be completed with an afterDeliver before beforeDeliver can be called again");
}
// call beforeDelivery on the container
try {
instance = instanceManager.getInstance(new ThreadContext(deployment, null));
container.beforeDelivery(deployment, instance, method, xaResource);
} catch (final SystemException se) {
final Throwable throwable = se.getRootCause() != null ? se.getRootCause() : se;
throw new ApplicationServerInternalException(throwable);
} catch (OpenEJBException oe) {
throw new ApplicationServerInternalException(oe);
}
// before completed successfully we are now ready to invoke bean
state = State.BEFORE_CALLED;
}
use of org.apache.openejb.core.ThreadContext in project tomee by apache.
the class AbstractSecurityService method isCallerAuthorized.
@Override
public boolean isCallerAuthorized(final Method method, final InterfaceType type) {
final ThreadContext threadContext = ThreadContext.getThreadContext();
final BeanContext beanContext = threadContext.getBeanContext();
try {
final String ejbName = beanContext.getEjbName();
String name = type == null ? null : type.getSpecName();
if ("LocalBean".equals(name) || "LocalBeanHome".equals(name)) {
name = null;
}
final Identity currentIdentity = clientIdentity.get();
final SecurityContext securityContext;
if (currentIdentity == null) {
securityContext = threadContext.get(SecurityContext.class);
} else {
securityContext = new SecurityContext(currentIdentity.getSubject());
}
securityContext.acc.checkPermission(new EJBMethodPermission(ejbName, name, method));
} catch (final AccessControlException e) {
return false;
}
return true;
}
use of org.apache.openejb.core.ThreadContext in project tomee by apache.
the class AbstractSecurityService method isCallerInRole.
@Override
public boolean isCallerInRole(final String role) {
if (role == null) {
throw new IllegalArgumentException("Role must not be null");
}
final ThreadContext threadContext = ThreadContext.getThreadContext();
if (threadContext == null) {
return false;
}
final SecurityContext securityContext = threadContext.get(SecurityContext.class);
if ("**".equals(role)) {
// ie logged in
return securityContext != defaultContext;
}
final Set<Group> grps = securityContext.subject.getPrincipals(Group.class);
for (final Group grp : grps) {
if (grp.getName().equals(role)) {
return true;
}
}
final Set<GroupPrincipal> grpsp = securityContext.subject.getPrincipals(GroupPrincipal.class);
for (final GroupPrincipal grp : grpsp) {
if (grp.getName().equals(role)) {
return true;
}
}
return false;
}
Aggregations