FileDocCategorySizeDatePackage
RunAsSecurityInterceptorFactory.javaAPI DocJBoss 4.2.15112Fri Jul 13 20:53:52 BST 2007org.jboss.ejb3.security

RunAsSecurityInterceptorFactory

public class RunAsSecurityInterceptorFactory extends Object implements org.jboss.aop.advice.AspectFactory

Fields Summary
private static final Logger
log
Constructors Summary
Methods Summary
public java.lang.ObjectcreatePerClass(org.jboss.aop.Advisor advisor)

      EJBContainer container = (EJBContainer)advisor;
      RunAsIdentity runAsIdentity = getRunAsIdentity(container);
      /*if (runAsIdentity == null)
      {
         return new NullInterceptor();
      }*/

      Object domain = null;
      try
      {
         InitialContext ctx = container.getInitialContext();
         org.jboss.annotation.security.SecurityDomain anSecurityDomain = (org.jboss.annotation.security.SecurityDomain) advisor.resolveAnnotation(org.jboss.annotation.security.SecurityDomain.class);
         if (anSecurityDomain != null)
         {
            String domainName = anSecurityDomain.value();
            domain = SecurityDomainManager.getSecurityManager(domainName, ctx);
         }
      }
      catch (NamingException e)
      {
         throw new RuntimeException(e);
      }
      
      Interceptor interceptor = new NullInterceptor();
      if (domain != null)
      {
         AuthenticationManager manager = (AuthenticationManager) domain;
         RealmMapping mapping = (RealmMapping) domain;
         interceptor = new RunAsSecurityInterceptor(manager, mapping, getRunAsIdentity(container));
      }
      return interceptor;
   
public java.lang.ObjectcreatePerInstance(org.jboss.aop.Advisor advisor, org.jboss.aop.InstanceAdvisor instanceAdvisor)

      throw new RuntimeException("PER_VM not supported for this interceptor factory, only PER_CLASS");
   
public java.lang.ObjectcreatePerJoinpoint(org.jboss.aop.Advisor advisor, org.jboss.aop.joinpoint.Joinpoint jp)

      throw new RuntimeException("PER_VM not supported for this interceptor factory, only PER_CLASS");
   
public java.lang.ObjectcreatePerJoinpoint(org.jboss.aop.Advisor advisor, org.jboss.aop.InstanceAdvisor instanceAdvisor, org.jboss.aop.joinpoint.Joinpoint jp)

      throw new RuntimeException("PER_VM not supported for this interceptor factory, only PER_CLASS");
   
public java.lang.ObjectcreatePerVM()


     
   
      throw new RuntimeException("PER_VM not supported for this interceptor factory, only PER_CLASS");
   
public java.lang.StringgetName()

      return getClass().getName();
   
protected org.jboss.security.RunAsIdentitygetRunAsIdentity(org.jboss.ejb3.EJBContainer container)

      RunAs runAs = (RunAs) container.resolveAnnotation(RunAs.class);
      if (runAs == null) return null;
      if (container.getXml() != null && container.getXml().getSecurityIdentity() != null)
      {
         if (container.getXml().getSecurityIdentity().isUseCallerIdentity()) return null;
      }
      RunAsPrincipal rap = (RunAsPrincipal) container.resolveAnnotation(RunAsPrincipal.class);
      String runAsPrincipal = null;
      if (rap != null) 
         runAsPrincipal = rap.value();
      else
      {
         //Check if jboss.xml has it  
         if(container.getXml() != null && container.getXml().getSecurityIdentity() != null)
         {
            runAsPrincipal = container.getXml().getSecurityIdentity().getRunAsPrincipal();
         }
      }

      HashSet extraRoles = new HashSet();  
      AssemblyDescriptor ad = container.getAssemblyDescriptor();
      if(ad != null)
      {
         extraRoles.addAll(ad.getSecurityRolesGivenPrincipal(runAsPrincipal));
      }

      return new RunAsIdentity(runAs.value(), runAsPrincipal, extraRoles);