1 22 package org.jboss.ejb3.security; 23 24 import java.lang.reflect.Method ; 25 import java.security.CodeSource ; 26 import javax.security.jacc.EJBMethodPermission ; 27 import org.jboss.aop.advice.Interceptor; 28 import org.jboss.aop.joinpoint.Invocation; 29 import org.jboss.aop.joinpoint.MethodInvocation; 30 import org.jboss.aspects.remoting.InvokeRemoteInterceptor; 31 import org.jboss.remoting.InvokerLocator; 32 33 34 40 public class JaccAuthorizationInterceptor implements Interceptor 41 { 42 public static final String JACC = "JACC"; 43 public static final String CTX = "ctx"; 44 45 private String ejbName; 46 private CodeSource ejbCS; 47 48 public JaccAuthorizationInterceptor(String ejbName, CodeSource cs) 49 { 50 this.ejbName = ejbName; 51 this.ejbCS = cs; 52 } 53 54 public String getName() 55 { 56 return "JaccAuthorizationInterceptor"; 57 } 58 59 public Object invoke(Invocation inv) throws Throwable 60 { 61 try 62 { 63 checkSecurityAssociation((MethodInvocation) inv); 64 return inv.invokeNext(); 65 } 66 catch (ClassCastException e) 67 { 68 throw new RuntimeException ("Jacc authorization is only available for method invocations", e); 69 } 70 } 71 72 75 private void checkSecurityAssociation(MethodInvocation mi) throws Throwable 76 { 77 String contextID = (String ) mi.getMetaData(JACC, CTX); 78 SecurityActions.setContextID(contextID); 79 80 81 83 86 Method m = mi.getMethod(); 87 88 InvokerLocator locator = (InvokerLocator) mi.getMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR); 89 90 String iface = (locator != null) ? "Remote" : "Local"; 91 92 EJBMethodPermission methodPerm = new EJBMethodPermission (ejbName, iface, m); 93 JaccHelper.checkPermission(ejbCS, methodPerm); 94 113 } 114 } 115 | Popular Tags |