1 22 package org.jboss.aspects.security; 23 24 import org.jboss.aop.joinpoint.Invocation; 25 import org.jboss.logging.Logger; 26 import org.jboss.security.AuthenticationManager; 27 import org.jboss.security.RealmMapping; 28 import org.jboss.security.RunAsIdentity; 29 30 37 public class RunAsSecurityInterceptor implements org.jboss.aop.advice.Interceptor 38 { 39 private static final Logger log = Logger.getLogger(RunAsSecurityInterceptor.class); 40 41 protected AuthenticationManager securityManager; 42 protected RealmMapping realmMapping; 43 44 public RunAsSecurityInterceptor(AuthenticationManager manager, RealmMapping realmMapping) 45 { 46 this.securityManager = manager; 47 this.realmMapping = realmMapping; 48 } 49 50 public String getName() { return "RunAsSecurityInterceptor"; } 51 52 protected RunAsIdentity getRunAsIdentity(Invocation invocation) 53 { 54 RunAsIdentity identity = (RunAsIdentity)invocation.getMetaData("security", "run-as"); 55 if (identity == null) identity = getAnnotationRunAsIdentity(invocation); 56 return identity; 57 } 58 59 protected RunAsIdentity getAnnotationRunAsIdentity(Invocation invocation) 60 { 61 RunAs runAs = (RunAs) invocation.resolveAnnotation(RunAs.class); 62 if (runAs == null) return null; 63 RunAsIdentity runAsRole = new RunAsIdentity(runAs.value(), null); 64 return runAsRole; 65 } 66 public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable 67 { 68 RunAsIdentity runAsRole = getRunAsIdentity(invocation); 69 if(runAsRole != null) 73 { 74 SecurityActions.pushRunAsIdentity(runAsRole); 75 } 76 77 try 78 { 79 return invocation.invokeNext(); 80 } 81 finally 82 { 83 if(runAsRole != null) 84 { 85 SecurityActions.popRunAsIdentity(); 86 } 87 } 88 } 89 } 90 | Popular Tags |