Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 package org.jboss.security;
 
 import java.util.Set;
 
 
 //$Id: RunAsIdentity.java 70624 2008-03-10 14:51:00Z anil.saldhana@jboss.com $
 
The RunAsIdentity is a Principal that associates the run-as principal with his run-as role(s).

Author(s):
Thomas.Diesler@jboss.org
Scott.Stark@jboss.org
Anil.Saldhana@jboss.org
Version:
$Revision: 70624 $
 
 public class RunAsIdentity extends SimplePrincipal implements CloneableRunAs
 {
   

Since:
4.0.2
 
    private static final long serialVersionUID = -3236178735180485083L;

   
The run-as role principals
 
    private HashSet<PrincipalrunAsRoles = new HashSet<Principal>(); 
    private HashSet<PrincipalprincipalsSet
 
    private static final String ANOYMOUS_PRINCIPAL = "anonymous";

   
Construct an inmutable instance of a RunAsIdentity
 
    public RunAsIdentity(String roleNameString principalName)
    {
       // we don't support run-as credetials
       super(principalName != null ? principalName : );
 
       if (roleName == null)
          throw new IllegalArgumentException("The run-as identity must have at least one role");
 
       .add(new SimplePrincipal(roleName));
    }

   
Construct an inmutable instance of a RunAsIdentity
 
    public RunAsIdentity(String roleNameString principalNameSet<StringextraRoleNames)
    {
       this(roleNameprincipalName);
 
       // these come from the assembly-descriptor
       if (extraRoleNames != null)
       {
          Iterator<Stringit = extraRoleNames.iterator();
          while (it.hasNext())
          {
             String extraRoleName = (Stringit.next();
             .add(new SimplePrincipal(extraRoleName));
          }
       }
    }

   
Return a set with the configured run-as role

Returns:
Set<Principal> for the run-as roles
 
    public Set<PrincipalgetRunAsRoles()
    {
       return new HashSet<Principal>();
    }
   
   
Return a RoleGroup of Run-As roles

Returns:
 
   {
      return new SimpleRoleGroup(); 
   }
    
   
Return a set with the configured run-as principal and a Group("Roles") with teh run-as roles

Returns:
Set<Principal> for the run-as principal and roles
   public synchronized Set<PrincipalgetPrincipalsSet()
   {
      if == null )
      {
          = new HashSet<Principal>();
         .add(this);
         SimpleGroup roles = new SimpleGroup("Roles");
         .add(roles);
         Iterator<Principaliter = .iterator();
         whileiter.hasNext() )
         {
            Principal role = (Principaliter.next();
            roles.addMember(role);
         }
      }
      return ;
   }
   public boolean doesUserHaveRole(Principal role)
   {
      return .contains(role);
   }

   
True if the run-as principal has any of the method roles
   public boolean doesUserHaveRole(Set<PrincipalmethodRoles)
   {
      Iterator<Principalit = methodRoles.iterator();
      while (it.hasNext())
      {
         Principal role = (Principalit.next();
         if (doesUserHaveRole(role))
            return true;
      }
      return false;
   }

   
Returns a string representation of the object.

Returns:
a string representation of the object.
   public String toString()
   {
      return "[roles=" +  + ",principal=" + getName() + "]";
   }
   
   @SuppressWarnings("unchecked")
   public synchronized Object clone() throws CloneNotSupportedException    
   {  
      RunAsIdentity clone = (RunAsIdentitysuper.clone(); 
      if(clone != null
      { 
         clone.principalsSet =  != null ?
                   (HashSet<Principal>)this..clone() : null
         clone.runAsRoles = (HashSet<Principal>)this..clone(); 
      }  
      return clone
   }
   @SuppressWarnings("unchecked")
   public <T> T getIdentity()
   { 
      return (T) getName();
   }
   @SuppressWarnings("unchecked")
   public <T> T getProof()
   { 
      return (T) .;
   } 
New to GrepCode? Check out our FAQ X