final Method meth = beanClassMethod;
final Object obj = o;
final Object[] objArr = oa;
Object ret;
EJBSecurityManager mgr = (EJBSecurityManager) c.getSecurityManager();
if (mgr == null) {
throw new SecurityException("SecurityManager not set");
}
// Optimization. Skip doAsPrivileged call if this is a local
// invocation and the target ejb uses caller identity or the
// System Security Manager is disabled.
// Still need to execute it within the target bean's policy context.
// see CR 6331550
if((inv.isLocal && mgr.getUsesCallerIdentity()) ||
System.getSecurityManager() == null) {
ret = mgr.runMethod(meth, obj, objArr);
} else {
try {
PrivilegedExceptionAction pea =
new PrivilegedExceptionAction(){
public java.lang.Object run() throws Exception {
return meth.invoke(obj, objArr);
}
};
ret = mgr.doAsPrivileged(pea);
} catch(PrivilegedActionException pae) {
Throwable cause = pae.getCause();
if( cause instanceof InvocationTargetException ) {
cause = ((InvocationTargetException) cause).getCause();
}