User: starksm 
  Date: 01/06/15 07:22:03

  Modified:    src/main/org/jboss/security SecurityAssociation.java
  Log:
  Add support for implementation of the EJB2.0 run-as
  
  Revision  Changes    Path
  1.4       +64 -12    jboss/src/main/org/jboss/security/SecurityAssociation.java
  
  Index: SecurityAssociation.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/security/SecurityAssociation.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SecurityAssociation.java  2001/06/12 08:00:43     1.3
  +++ SecurityAssociation.java  2001/06/15 14:22:03     1.4
  @@ -8,6 +8,7 @@
   package org.jboss.security;
   
   import java.security.Principal;
  +import java.util.ArrayList;
   
   /** The SecurityAssociation class maintains the security principal and
   credentials. This can be done on either a singleton basis or a thread
  @@ -31,27 +32,29 @@
   
   @author Daniel O'Connor ([EMAIL PROTECTED])
   @author [EMAIL PROTECTED]
  -@version $Revision: 1.3 $
  +@version $Revision: 1.4 $
   */
   public final class SecurityAssociation
   {
       private static boolean server;
       private static Principal principal;
       private static Object credential;
  -    private static ThreadLocal thread_principal;
  -    private static ThreadLocal thread_credential;
  +    private static ThreadLocal threadPrincipal;
  +    private static ThreadLocal threadCredential;
  +    private static RunAsThreadLocalStack threadRunAsStacks = new 
RunAsThreadLocalStack();
  +
       static
       {
           boolean useThreadLocal = 
Boolean.getBoolean("org.jboss.security.SecurityAssociation.ThreadLocal");
           if( useThreadLocal )
           {
  -            thread_principal = new ThreadLocal();
  -            thread_credential = new ThreadLocal();
  +            threadPrincipal = new ThreadLocal();
  +            threadCredential = new ThreadLocal();
           }
           else
           {
  -            thread_principal = new InheritableThreadLocal();
  -            thread_credential = new InheritableThreadLocal();
  +            threadPrincipal = new InheritableThreadLocal();
  +            threadCredential = new InheritableThreadLocal();
           }
       }
   
  @@ -61,7 +64,7 @@
       public static Principal getPrincipal()
       {
         if (server)
  -        return (Principal) thread_principal.get();
  +        return (Principal) threadPrincipal.get();
         else
           return principal;
       }
  @@ -74,7 +77,7 @@
       public static Object getCredential()
       {
         if (server)
  -        return thread_credential.get();
  +        return threadCredential.get();
         else
           return credential;
       }
  @@ -85,7 +88,7 @@
       public static void setPrincipal( Principal principal )
       {
         if (server)
  -        thread_principal.set( principal );
  +        threadPrincipal.set( principal );
         else
           SecurityAssociation.principal = principal;
       }
  @@ -98,11 +101,28 @@
       public static void setCredential( Object credential )
       {
         if (server)
  -        thread_credential.set( credential );
  +        threadCredential.set( credential );
         else
           SecurityAssociation.credential = credential;
       }
   
  +    /**
  +     */
  +    public static void pushRunAsRole(Principal runAsRole)
  +    {
  +        threadRunAsStacks.push(runAsRole);
  +    }
  +    public static Principal popRunAsRole()
  +    {
  +        Principal runAsRole = threadRunAsStacks.pop();
  +        return runAsRole;
  +    }
  +    public static Principal peekRunAsRole()
  +    {
  +        Principal runAsRole = threadRunAsStacks.peek();
  +        return runAsRole;
  +    }
  +
       /** Set the server mode of operation. When the server property has
       been set to true, the security information is maintained in thread local
       storage. This should be called to enable property security semantics
  @@ -113,5 +133,37 @@
       {
         server = true;
       }
  -}
   
  +    /**
  +     */
  +    private static class RunAsThreadLocalStack extends ThreadLocal
  +    {
  +        protected Object initialValue()
  +        {
  +            return new ArrayList();
  +        }
  +        void push(Principal runAs)
  +        {
  +            ArrayList stack = (ArrayList) super.get();
  +            stack.add(runAs);
  +        }
  +        Principal pop()
  +        {
  +            ArrayList stack = (ArrayList) super.get();
  +            Principal runAs = null;
  +            int lastIndex = stack.size() - 1;
  +            if( lastIndex >= 0 )
  +                runAs = (Principal) stack.remove(lastIndex);
  +            return runAs;
  +        }
  +        Principal peek()
  +        {
  +            ArrayList stack = (ArrayList) super.get();
  +            Principal runAs = null;
  +            int lastIndex = stack.size() - 1;
  +            if( lastIndex >= 0 )
  +                runAs = (Principal) stack.get(lastIndex);
  +            return runAs;
  +        }
  +    }
  +}
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to