edu.internet2.middleware.grouper
Class GrouperSession

java.lang.Object
  extended by 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 $
Author:
blair christensen.
See Also:
Serialized Form

Constructor Summary
GrouperSession()
          Default constructor.
 
Method Summary
static Object callbackGrouperSession(GrouperSession grouperSession, GrouperSessionHandler grouperSessionHandler)
          call this to send a callback for the grouper session object.
static void clearGrouperSession()
          clear the threadlocal grouper session (dont really need to call this, just stop the session, but this is here for testing)
static void clearGrouperSessions()
          clear the threadlocal grouper sessions (dont really need to call this, just stop the session, but this is here for testing)
 String getAccessClass()
          Get name of class implenting AccessAdapter privilege interface.
 AccessResolver getAccessResolver()
           
 String getAttributeDefClass()
          Get name of class implenting AccessAdapter privilege interface.
 AttributeDefResolver getAttributeDefResolver()
           
 Member getMember()
          Get the Member associated with this API session.
 String getMemberUuid()
           
 String getNamingClass()
          Get name of class implenting NamingAdapter privilege interface.
 NamingResolver getNamingResolver()
           
 String getSessionId()
          Get this session's id.
 Date getStartTime()
          Get this session's start time.
 long getStartTimeLong()
           
 edu.internet2.middleware.subject.Subject getSubject()
          Get the Subject associated with this API session.
 edu.internet2.middleware.subject.Subject getSubjectDb()
          Get the Subject associated with this API session.
 String getUuid()
           
static Object internal_callbackRootGrouperSession(GrouperSessionHandler grouperSessionHandler)
          call this to send a callback for the root grouper session object.
 GrouperSession internal_getRootSession()
           
 boolean isConsiderIfWheelMember()
          if we should take into consideration that we are a wheel member (or act as self if false)
 void setConsiderIfWheelMember(boolean considerIfWheelMember1)
          if we should take into consideration that we are a wheel member (or act as self if false)
 void setMemberUuid(String memberUUID1)
           
 void setStartTimeLong(long startTime1)
           
 void setSubject(edu.internet2.middleware.subject.Subject subject1)
           
 void setUuid(String uuid1)
           
static GrouperSession start(edu.internet2.middleware.subject.Subject subject)
          Start a session for interacting with the Grouper API.
static GrouperSession start(edu.internet2.middleware.subject.Subject subject, boolean addToThreadLocal)
          Start a session for interacting with the Grouper API.
static GrouperSession startBySubjectIdAndSource(String subjectId, String sourceId)
          start a session based on a sourceId and subjectId
static GrouperSession startBySubjectIdAndSource(String subjectId, String sourceId, boolean addToThreadLocal)
          start a session based on a sourceId and subjectId
static GrouperSession startBySubjectIdentifierAndSource(String subjectIdentifier, String sourceId)
          start a session based on a sourceId and subjectId
static GrouperSession startBySubjectIdentifierAndSource(String subjectIdentifier, String sourceId, boolean addToThreadLocal)
          start a session based on a sourceId and subjectId
static GrouperSessionResult startIfNotStarted(edu.internet2.middleware.subject.Subject subject)
          Start a session for interacting with the Grouper API.
static GrouperSession startRootSession()
          Start a session for interacting with the Grouper API.
static GrouperSession startRootSession(boolean addToThreadLocal)
          Start a session for interacting with the Grouper API.
static GrouperSessionResult startRootSessionIfNotStarted()
          Start a root session for interacting with the Grouper API.
static GrouperSession staticGrouperSession()
          get the threadlocal grouper session.
static GrouperSession staticGrouperSession(boolean exceptionOnNull)
          get the threadlocal grouper session.
 void stop()
          Stop this API session.
static void stopQuietly(GrouperSession session)
          stop a session quietly
 String toString()
           
 String toStringDto()
           
 void validate()
           
static void validate(GrouperSession s)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GrouperSession

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

Since:
1.2.0
Method Detail

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 -

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(edu.internet2.middleware.subject.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(edu.internet2.middleware.subject.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()
                                       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(edu.internet2.middleware.subject.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

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 edu.internet2.middleware.subject.Subject getSubject()
                                                    throws GrouperException
Get the Subject associated with this API session.
 Subject subj = s.getSubject(); 
 

Returns:
A Subject object.
Throws:
GrouperException

getSubjectDb

public edu.internet2.middleware.subject.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:
Object.toString()

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(edu.internet2.middleware.subject.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:
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

clearGrouperSession

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


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