1 22 package org.jboss.ejb.txtimer; 23 24 26 import org.jboss.ejb.Container; 27 import org.jboss.invocation.Invocation; 28 import org.jboss.invocation.InvocationKey; 29 import org.jboss.invocation.InvocationType; 30 import org.jboss.invocation.PayloadKey; 31 import org.jboss.security.RunAsIdentity; 32 import org.jboss.metadata.BeanMetaData; 33 import org.jboss.metadata.SecurityIdentityMetaData; 34 import org.jboss.metadata.AssemblyDescriptorMetaData; 35 import org.jboss.metadata.ApplicationMetaData; 36 37 import javax.ejb.TimedObject ; 38 import javax.ejb.Timer ; 39 import java.lang.reflect.Method ; 40 import java.util.Set ; 41 42 51 public class TimedObjectInvokerImpl implements TimedObjectInvoker 52 { 53 private Container container; 54 private TimedObjectId timedObjectId; 55 private Method method; 56 57 public TimedObjectInvokerImpl(TimedObjectId timedObjectId, Container container) 58 { 59 try 60 { 61 this.container = container; 62 this.timedObjectId = timedObjectId; 63 this.method = TimedObject .class.getMethod("ejbTimeout", new Class []{Timer .class}); 64 65 } 66 catch (NoSuchMethodException ignore) 67 { 68 } 69 } 70 71 76 public void callTimeout(Timer timer) 77 throws Exception 78 { 79 ClassLoader callerClassLoader = SecurityActions.getContextClassLoader(); 80 SecurityActions.setContextClassLoader(container.getClassLoader()); 81 try 82 { 83 Invocation inv = new Invocation(timedObjectId.getInstancePk(), method, new Object []{timer}, null, null, null); 84 inv.setValue(InvocationKey.INVOKER_PROXY_BINDING, null, PayloadKey.AS_IS); 85 inv.setType(InvocationType.LOCAL); 86 BeanMetaData bmd = container.getBeanMetaData(); 87 SecurityIdentityMetaData ejbTimeoutIdentity = bmd.getEjbTimeoutIdentity(); 88 if( ejbTimeoutIdentity != null && ejbTimeoutIdentity.getUseCallerIdentity() == false ) 89 { 90 ApplicationMetaData applicationMetaData = bmd.getApplicationMetaData(); 91 AssemblyDescriptorMetaData assemblyDescriptor = applicationMetaData.getAssemblyDescriptor(); 92 String roleName = ejbTimeoutIdentity.getRunAsRoleName(); 93 String principalName = ejbTimeoutIdentity.getRunAsPrincipalName(); 94 Set extraRoleNames = assemblyDescriptor.getSecurityRoleNamesByPrincipal(principalName); 96 RunAsIdentity runAsIdentity = new RunAsIdentity(roleName, principalName, extraRoleNames); 97 SecurityActions.pushRunAsIdentity(runAsIdentity); 98 } 99 container.invoke(inv); 100 } 101 finally 102 { 103 SecurityActions.popRunAsIdentity(); 104 SecurityActions.setContextClassLoader(callerClassLoader); 105 } 106 } 107 } 108
| Popular Tags
|