/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.web.tomcat.security;

import java.security.Principal;
import java.util.List;
import java.util.Set;
import javax.security.auth.Subject;

import org.apache.catalina.Realm;
import org.apache.catalina.realm.GenericPrincipal;

/**
 * An implementation of the catalina GenericPrincipal to allow caching of
 * security manager invocation results.
 * 
 * @author remm@jboss.org
 * @author Scott.Stark@jboss.org
 * @version $Revision: 1.3.4.3 $
 */
class JBossGenericPrincipal
   extends GenericPrincipal
{
   /** The authenticated user name as a Principal */
   private Principal authPrincipal = null;
   /** The caller principal name mapping if any */
   private Principal callerPrincipal = null;
   /** The authenticated user credentials */
   private Object credentials = null;
   /** The authenticated user Subject */
   private Subject subject = null;
   /** Set<Principal> of the roles assigned to the subject */
   private Set userRoles = null;

   /**
    * Create an encapsulation of the authenticated caller information.
    * 
    * @param realm - the Relam implementation creating the principal
    * @param subject - the authenticated JAAS subject
    * @param authPrincipal - the principal used for authentication and stored in
    * the security manager cache
    * @param callerPrincipal - the possibly different caller principal
    * representation of the authenticated principal
    * @param credentials - the opaque credentials used for authentication
    * @param roles - the List<String> of the role names assigned to the subject
    * @param userRoles - the Set<Principal> of the roles assigned to the subject
    */ 
   JBossGenericPrincipal(Realm realm, Subject subject,
      Principal authPrincipal, Principal callerPrincipal,
      Object credentials, List roles, Set userRoles)
   {
      super(realm, callerPrincipal.getName(), null, roles);
      this.credentials = credentials;
      this.authPrincipal = authPrincipal;
      this.callerPrincipal = callerPrincipal;
      this.subject = subject;
      this.userRoles = userRoles;
   }

   Principal getAuthPrincipal()
   {
      return this.authPrincipal;
   }
   /**
    * Gets the value of principal
    * 
    * @return the value of principal
    */
   Principal getCallerPrincipal()
   {
      return this.callerPrincipal;
   }

   /**
    * Gets the value of credentials
    * 
    * @return the value of credentials
    */
   Object getCredentials()
   {
      return this.credentials;
   }

   Subject getSubject()
   {
      return subject;
   }

   /**
    * Get the original set of role Principals
    * @return Set<Princpals> for the roles assigned to the user
    */ 
   Set getUserRoles()
   {
      return userRoles;
   }
}