Class GrouperSession

java.lang.Object
edu.internet2.middleware.grouper.GrouperSession
All Implemented Interfaces:
Serializable

public class GrouperSession extends Object implements Serializable
Context for interacting with the Grouper API and Groups Registry.

Version:
$Id: GrouperSession.java,v 1.101 2009-11-05 20:06:42 isgwb Exp $
See Also:
  • Constructor Details

    • GrouperSession

      public GrouperSession()
      Default constructor. Dont call this, use the factory: start(Subject)

      Since:
      1.2.0
  • Method Details

    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
      See Also:
    • isConsiderIfWheelMember

      public boolean isConsiderIfWheelMember()
      if we should take into consideration that we are a wheel member (or act as self if false)
      Returns:
      if considering if wheel member
    • setConsiderIfWheelMember

      public void setConsiderIfWheelMember(boolean considerIfWheelMember1)
      if we should take into consideration that we are a wheel member (or act as self if false)
      Parameters:
      considerIfWheelMember1 -
    • internal_testingGetCurrentSession

      public static GrouperSession internal_testingGetCurrentSession()
    • stopQuietly

      public static void stopQuietly(GrouperSession session)
      stop a session quietly
      Parameters:
      session -
    • startBySubjectIdAndSource

      public static GrouperSession startBySubjectIdAndSource(String subjectId, String sourceId)
      start a session based on a sourceId and subjectId
      Parameters:
      sourceId - if null search all sources
      subjectId -
      Returns:
      return the GrouperSession
    • startBySubjectIdAndSource

      public static GrouperSession startBySubjectIdAndSource(String subjectId, String sourceId, boolean addToThreadLocal)
      start a session based on a sourceId and subjectId
      Parameters:
      sourceId - if null search all sources
      subjectId -
      addToThreadLocal - true if it should be in threadlocal, false if not
      Returns:
      return the GrouperSession
    • startBySubjectIdentifierAndSource

      public static GrouperSession startBySubjectIdentifierAndSource(String subjectIdentifier, String sourceId)
      start a session based on a sourceId and subjectId
      Parameters:
      sourceId - if null search all sources
      subjectIdentifier -
      Returns:
      return the GrouperSession
    • startBySubjectIdentifierAndSource

      public static GrouperSession startBySubjectIdentifierAndSource(String subjectIdentifier, String sourceId, boolean addToThreadLocal)
      start a session based on a sourceId and subjectId
      Parameters:
      subjectIdentifier -
      sourceId - if null search all sources
      addToThreadLocal -
      Returns:
      return the GrouperSession
    • start

      public static GrouperSession start(Subject subject) throws SessionException
      Start a session for interacting with the Grouper API. This adds the session to the threadlocal. This has threadlocal implications, so start and stop these hierarchically, do not alternate. If you need to, use the callback inverse of control.
       // Start a Grouper API session.
       GrouperSession s = GrouperSession.subject);
       
      Parameters:
      subject - Start session as this Subject.
      Returns:
      A Grouper API session.
      Throws:
      SessionException
    • startIfNotStarted

      public static GrouperSessionResult startIfNotStarted(Subject subject) throws SessionException
      Start a session for interacting with the Grouper API. This adds the session to the threadlocal. This has threadlocal implications, so start and stop these hierarchically, do not alternate. If you need to, use the callback inverse of control. This will not start a session if it is already started. If it is started as a different user, it will start
       // Start a Grouper API session.
       GrouperSession s = GrouperSession.subject);
       
      Parameters:
      subject - Start session as this Subject.
      Returns:
      A Grouper API session.
      Throws:
      SessionException
    • startRootSession

      public static GrouperSession startRootSession(boolean addToThreadLocal) throws SessionException
      Start a session for interacting with the Grouper API. This adds the session to the threadlocal. This has threadlocal implications, so start and stop these hierarchically, do not alternate. If you need to, use the callback inverse of control. This uses
       // Start a Grouper API session.
       GrouperSession s = GrouperSession.start(subject);
       
      Parameters:
      addToThreadLocal - true to add this to the grouper session threadlocal which replaces the current one
      Returns:
      A Grouper API session.
      Throws:
      SessionException
    • startRootSession

      public static GrouperSession startRootSession(boolean addToThreadLocal, boolean addToCurrentSession) throws SessionException
      Start a session for interacting with the Grouper API. This adds the session to the threadlocal. This has threadlocal implications, so start and stop these hierarchically, do not alternate. If you need to, use the callback inverse of control. This uses
       // Start a Grouper API session.
       GrouperSession s = GrouperSession.start(subject);
       
      Parameters:
      addToThreadLocal - true to add this to the grouper session threadlocal which replaces the current one
      addToCurrentSession - if the current threadlocal session is set so the session is not garbage collected
      Returns:
      A Grouper API session.
      Throws:
      SessionException
    • startRootSession

      public static GrouperSession startRootSession() throws SessionException
      Start a session for interacting with the Grouper API. This adds the session to the threadlocal. This has threadlocal implications, so start and stop these hierarchically, do not alternate. If you need to, use the callback inverse of control. This uses
       // Start a Grouper API session.
       GrouperSession s = GrouperSession.start(subject);
       
      Returns:
      A Grouper API session.
      Throws:
      SessionException
    • start

      public static GrouperSession start(Subject subject, boolean addToThreadLocal) throws SessionException
      Start a session for interacting with the Grouper API. This has threadlocal implications, so start and stop these hierarchically, do not alternate. If you need to, use the callback inverse of control.
       // Start a Grouper API session.
       GrouperSession s = GrouperSession.start(subject);
       
      Parameters:
      subject - Start session as this Subject.
      addToThreadLocal - true to add this to the grouper session threadlocal which replaces the current one. Though if in the context of a callback, the callback has precedence, and you should use an inner callback to preempt it (callbackGrouperSession)
      Returns:
      A Grouper API session.
      Throws:
      SessionException
    • start

      public static GrouperSession start(Subject subject, boolean addToThreadLocal, boolean addToCurrentSession) throws SessionException
      Start a session for interacting with the Grouper API. This has threadlocal implications, so start and stop these hierarchically, do not alternate. If you need to, use the callback inverse of control.
       // Start a Grouper API session.
       GrouperSession s = GrouperSession.start(subject);
       
      Parameters:
      subject - Start session as this Subject.
      addToThreadLocal - true to add this to the grouper session threadlocal which replaces the current one. Though if in the context of a callback, the callback has precedence, and you should use an inner callback to preempt it (callbackGrouperSession)
      addToCurrentSession - if the current threadlocal session is set so the session is not garbage collected
      Returns:
      A Grouper API session.
      Throws:
      SessionException
    • validate

      public static void validate(GrouperSession s) throws IllegalStateException
      Parameters:
      s -
      Throws:
      IllegalStateException
      Since:
      1.2.0
    • getAccessClass

      public String getAccessClass()
      Get name of class implenting AccessAdapter privilege interface.
       String klass = s.getAccessClass();
       
      Returns:
      access class
    • getAttributeDefClass

      public String getAttributeDefClass()
      Get name of class implenting AccessAdapter privilege interface.
       String klass = s.getAccessClass();
       
      Returns:
      access class
    • getAccessResolver

      public AccessResolver getAccessResolver()
      Returns:
      AccessResolver used by this session.
      Since:
      1.2.1
    • getMember

      public Member getMember() throws IllegalStateException
      Get the Member associated with this API session.
       Member m = s.getMember(); 
       

      As of 1.2.0, this method throws an IllegalStateException instead of a NullPointerException when the member cannot be retrieved.

      Returns:
      A Member object.
      Throws:
      IllegalStateException - if Member cannot be returned.
    • getNamingClass

      public String getNamingClass()
      Get name of class implenting NamingAdapter privilege interface.
       String klass = s.getNamingClass();
       
      Returns:
      naming class
    • getNamingResolver

      public NamingResolver getNamingResolver()
      Returns:
      NamingResolver used by this session.
      Since:
      1.2.1
    • getSessionId

      public String getSessionId()
      Get this session's id.
       String id = s.internal_getSessionId();
       
      Returns:
      The session id.
    • getStartTime

      public Date getStartTime()
      Get this session's start time.
       Date startTime = s.getStartTime();
       
      Returns:
      This session's start time.
    • getSubject

      public Subject getSubject() throws GrouperException
      Get the Subject associated with this API session.
       Subject subj = s.getSubject(); 
       
      Returns:
      A Subject object.
      Throws:
      GrouperException
    • getSubjectDb

      public Subject getSubjectDb() throws GrouperException
      Get the Subject associated with this API session.
       Subject subj = s.getSubject(); 
       
      Returns:
      A Subject object.
      Throws:
      GrouperException
    • stop

      public void stop() throws SessionException
      Stop this API session.
       s.stop();
       
      Throws:
      SessionException
    • toString

      public String toString()
      Overrides:
      toString in class Object
      See Also:
    • validate

      public void validate() throws IllegalStateException
      Throws:
      IllegalStateException
      Since:
      1.2.0
    • internal_getRootSession

      public GrouperSession internal_getRootSession() throws GrouperException
      Returns:
      the grouper session
      Throws:
      GrouperException
    • getMemberUuid

      public String getMemberUuid()
      Returns:
      member uuid
      Since:
      1.2.0
    • getStartTimeLong

      public long getStartTimeLong()
      Returns:
      start time
      Since:
      1.2.0
    • getUuid

      public String getUuid()
      Returns:
      uuid
      Since:
      1.2.0
    • setMemberUuid

      public void setMemberUuid(String memberUUID1)
      Parameters:
      memberUUID1 -
      Since:
      1.2.0
    • setStartTimeLong

      public void setStartTimeLong(long startTime1)
      Parameters:
      startTime1 -
      Since:
      1.2.0
    • setSubject

      public void setSubject(Subject subject1)
      Parameters:
      subject1 -
      Since:
      1.2.0
    • setUuid

      public void setUuid(String uuid1)
      Parameters:
      uuid1 -
      Since:
      1.2.0
    • toStringDto

      public String toStringDto()
      Returns:
      the string
      Since:
      1.2.0
    • getAttributeDefResolver

      public AttributeDefResolver getAttributeDefResolver()
      Returns:
      AttributeDefResolver used by this session.
      Since:
      1.2.1
    • startRootSessionIfNotStarted

      public static GrouperSessionResult startRootSessionIfNotStarted() throws SessionException
      Start a root session for interacting with the Grouper API. This adds the session to the threadlocal. This has threadlocal implications, so start and stop these hierarchically, do not alternate. If you need to, use the callback inverse of control. This will not start a session if it is already started. If it is started as a different user, it will start
      Returns:
      A Grouper API session result.
      Throws:
      SessionException
    • callbackGrouperSession

      public static Object callbackGrouperSession(GrouperSession grouperSession, GrouperSessionHandler grouperSessionHandler) throws GrouperSessionException
      call this to send a callback for the grouper session object. cant use inverse of control for this since it runs it. Any method in the inverse of control can access the grouper session in a threadlocal
      Parameters:
      grouperSession - is the session to do an inverse of control on
      grouperSessionHandler - will get the callback
      Returns:
      the object returned from the callback
      Throws:
      GrouperSessionException - if there is a problem, will preserve runtime exceptions so they are thrown to the caller. The GrouperSessionException wraps the underlying exception
    • internal_callbackRootGrouperSession

      public static Object internal_callbackRootGrouperSession(GrouperSessionHandler grouperSessionHandler) throws GrouperSessionException
      call this to send a callback for the root grouper session object. Any method in the inverse of control can access the grouper session in a threadlocal
      Parameters:
      runAsRoot - true to run as root, false to not run as root
      grouperSessionHandler - will get the callback
      Returns:
      the object returned from the callback
      Throws:
      GrouperSessionException - if there is a problem, will preserve runtime exceptions so they are thrown to the caller. The GrouperSessionException wraps the underlying exception
    • internal_callbackRootGrouperSession

      public static Object internal_callbackRootGrouperSession(boolean runAsRoot, GrouperSessionHandler grouperSessionHandler) throws GrouperSessionException
      call this to send a callback for the root grouper session object. Any method in the inverse of control can access the grouper session in a threadlocal
      Parameters:
      grouperSessionHandler - will get the callback
      Returns:
      the object returned from the callback
      Throws:
      GrouperSessionException - if there is a problem, will preserve runtime exceptions so they are thrown to the caller. The GrouperSessionException wraps the underlying exception
    • staticGrouperSession

      public static GrouperSession staticGrouperSession()
      get the threadlocal grouper session. access this through inverse of control. this should be called by internal grouper methods which need the grouper session
      Returns:
      the grouper session or null if none there
    • clearGrouperSessions

      public static void clearGrouperSessions()
      clear the threadlocal grouper sessions (dont really need to call this, just stop the session, but this is here for testing)
    • staticGrouperSession

      public static GrouperSession staticGrouperSession(boolean exceptionOnNull) throws IllegalStateException
      get the threadlocal grouper session. access this through inverse of control. this should be called by internal grouper methods which need the grouper session
      Parameters:
      exceptionOnNull - true if exception when there is none there
      Returns:
      the grouper session or null if none there
      Throws:
      IllegalStateException - if no sessions available
    • callbackGrouperSessionBySubjectId

      public static void callbackGrouperSessionBySubjectId(String subjectId, String sourceId, GrouperSessionHandler grouperSessionHandler)
      get the subject by root session, then callback in a session for that subject
      Parameters:
      sourceId -
      subjectId -
      grouperSessionHandler -