1 22 package org.jboss.aspects.security; 23 24 import org.jboss.aop.Advisor; 25 import org.jboss.aop.InstanceAdvisor; 26 import org.jboss.aop.advice.AspectFactory; 27 import org.jboss.aop.joinpoint.Joinpoint; 28 import org.jboss.security.AuthenticationManager; 29 import org.jboss.security.RealmMapping; 30 31 import javax.naming.InitialContext ; 32 import javax.naming.NamingException ; 33 34 41 public class RunAsSecurityInterceptorFactory implements AspectFactory 42 { 43 public Object createPerVM() 44 { 45 throw new RuntimeException ("PER_VM not supported for this interceptor factory, only PER_CLASS"); 46 } 47 48 public Object createPerClass(Advisor advisor) 49 { 50 AuthenticationManager manager = (AuthenticationManager)advisor.getDefaultMetaData().getMetaData("security", "authentication-manager"); 51 RealmMapping mapping = (RealmMapping)advisor.getDefaultMetaData().getMetaData("security", "realm-mapping"); 52 if (manager == null) 53 { 54 SecurityDomain domain = (SecurityDomain)advisor.resolveAnnotation(SecurityDomain.class); 55 if (domain == null) throw new RuntimeException ("Unable to determine security domain"); 56 try 57 { 58 manager = (AuthenticationManager)new InitialContext ().lookup("java:/jaas/" + domain.value()); 59 } 60 catch (NamingException e) 61 { 62 throw new RuntimeException (e); } 64 mapping = (RealmMapping)manager; 65 } 66 if (manager == null) throw new RuntimeException ("Unable to find Security Domain"); 67 return new RunAsSecurityInterceptor(manager, mapping); 68 } 69 70 public Object createPerInstance(Advisor advisor, InstanceAdvisor instanceAdvisor) 71 { 72 throw new RuntimeException ("PER_VM not supported for this interceptor factory, only PER_CLASS"); 73 } 74 75 public Object createPerJoinpoint(Advisor advisor, Joinpoint jp) 76 { 77 throw new RuntimeException ("PER_VM not supported for this interceptor factory, only PER_CLASS"); 78 } 79 80 public Object createPerJoinpoint(Advisor advisor, InstanceAdvisor instanceAdvisor, Joinpoint jp) 81 { 82 throw new RuntimeException ("PER_VM not supported for this interceptor factory, only PER_CLASS"); 83 } 84 85 public String getName() 86 { 87 return getClass().getName(); 88 } 89 } 90 | Popular Tags |