edu.internet2.middleware.grouper.hooks.beans
Class HooksContext

java.lang.Object
  extended by edu.internet2.middleware.grouper.hooks.beans.HooksContext

public class HooksContext
extends Object

context in which hooks are running


Field Summary
static String HOOKS_KEY_SUBJECT_ACT_AS
          hooks internal attribute key for grouper session
static String HOOKS_KEY_SUBJECT_LOGGED_IN
          hooks internal attribute key for grouper session
static String KEY_HTTP_SERVLET_REQUEST
          if application, key in context for request
static String KEY_HTTP_SERVLET_RESPONSE
          if application, key in context for response
static String KEY_HTTP_SESSION
          if application, key in context for session
 
Constructor Summary
HooksContext()
          constructor
HooksContext(boolean theAsynchronous, Map<String,Object> threadSafeAttributes, edu.internet2.middleware.subject.Subject theAsynchronousGrouperSessionSubject, String theAynchronousHookId)
          constructor
 
Method Summary
 edu.internet2.middleware.subject.Subject _internal_getAsynchronousGrouperSessionSubject()
          keep track of grouper session subject if needed
 boolean _internal_isAsynchronousGrouperSessionStarted()
          if we started one, we should stop it
 Map<String,Object> _internal_threadSafeAttributes()
          look at all threadlocal attributes, and extract the names and values of the threadsafe ones.
static void assignSubjectActAs(edu.internet2.middleware.subject.Subject subject)
          this will be a threadsafe attribute
static void assignSubjectLoggedIn(edu.internet2.middleware.subject.Subject subject)
          this will be a threadsafe attribute
 Set<String> attributeKeySet()
          keys of attributes (all put together, global, threadlocal, local
static void clearThreadLocal()
          clear out the threadlocal attributes at a point when everything should be clear
 edu.internet2.middleware.subject.Subject getAsynchronousGrouperSessionSubject()
          if this is an asynchronous hook, the grouper session subject is passed from the other thread to this thread, this is that subject.
 Object getAttribute(String key)
          get an attribute
 GrouperContextType getGrouperContextType()
          get the context in which the hooks are running, e.g.
 String getHookId()
          keep a unique id to keep the logs straight
 edu.internet2.middleware.subject.Subject getSubjectActAs()
          current acting subject in app (if applicable), or just the current subject
 edu.internet2.middleware.subject.Subject getSubjectFromGrouperSession()
          current user in the grouper session or null if none there
 edu.internet2.middleware.subject.Subject getSubjectLoggedIn()
          current user logged in to app (e.g.
 GrouperSession grouperSession()
          get the grouper session from the grouper session threadlocal
 boolean isAsynchronous()
          if this context is asynchronous
 boolean isSubjectActAsInGroup(String groupName)
          see if the current act as subject is in a certain group.
 boolean isSubjectFromGrouperSessionInGroup(String groupName)
          see if the current subject in grouper session is in a certain group (e.g.
static void setAttributeThreadLocal(String key, Object value, boolean okToCopyToNewThread)
          set a threadlocal attribute
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HOOKS_KEY_SUBJECT_LOGGED_IN

public static final String HOOKS_KEY_SUBJECT_LOGGED_IN
hooks internal attribute key for grouper session

See Also:
Constant Field Values

HOOKS_KEY_SUBJECT_ACT_AS

public static final String HOOKS_KEY_SUBJECT_ACT_AS
hooks internal attribute key for grouper session

See Also:
Constant Field Values

KEY_HTTP_SERVLET_RESPONSE

public static final String KEY_HTTP_SERVLET_RESPONSE
if application, key in context for response

See Also:
Constant Field Values

KEY_HTTP_SESSION

public static final String KEY_HTTP_SESSION
if application, key in context for session

See Also:
Constant Field Values

KEY_HTTP_SERVLET_REQUEST

public static final String KEY_HTTP_SERVLET_REQUEST
if application, key in context for request

See Also:
Constant Field Values
Constructor Detail

HooksContext

public HooksContext()
constructor


HooksContext

public HooksContext(boolean theAsynchronous,
                    Map<String,Object> threadSafeAttributes,
                    edu.internet2.middleware.subject.Subject theAsynchronousGrouperSessionSubject,
                    String theAynchronousHookId)
constructor

Parameters:
theAsynchronous - true if this is in a new thread, false if not
threadSafeAttributes - attributes from another thread if applicable
theAsynchronousGrouperSessionSubject - if asynchronous, pass in who the grouper subject should be
theAynchronousHookId - if we are asynchronous, pass in what the hook id should be
Method Detail

getSubjectLoggedIn

public edu.internet2.middleware.subject.Subject getSubjectLoggedIn()
current user logged in to app (e.g. UI or WS)

Returns:
the subject logged in (or null if not available)

getSubjectFromGrouperSession

public edu.internet2.middleware.subject.Subject getSubjectFromGrouperSession()
current user in the grouper session or null if none there

Returns:
the subject logged in (or null if not available)

getSubjectActAs

public edu.internet2.middleware.subject.Subject getSubjectActAs()
current acting subject in app (if applicable), or just the current subject

Returns:
the subject acting as (or null if not available)

grouperSession

public GrouperSession grouperSession()
get the grouper session from the grouper session threadlocal

Returns:
the grouper session (might be null)

getAsynchronousGrouperSessionSubject

public edu.internet2.middleware.subject.Subject getAsynchronousGrouperSessionSubject()
if this is an asynchronous hook, the grouper session subject is passed from the other thread to this thread, this is that subject. note, you can call HooksContext.grouperSession() to start a session instead.

Returns:
the subject

assignSubjectLoggedIn

public static void assignSubjectLoggedIn(edu.internet2.middleware.subject.Subject subject)
this will be a threadsafe attribute

Parameters:
subject - or null to clear

assignSubjectActAs

public static void assignSubjectActAs(edu.internet2.middleware.subject.Subject subject)
this will be a threadsafe attribute

Parameters:
subject - or null to clear

isSubjectActAsInGroup

public boolean isSubjectActAsInGroup(String groupName)
see if the current act as subject is in a certain group. Note, this group uuid will be stored in a cache. Also the result will be stored in a cache, it is not meant to hold too many items

Parameters:
groupName -
Returns:
true if in group, false if not in group, or if the subject is not available

isSubjectFromGrouperSessionInGroup

public boolean isSubjectFromGrouperSessionInGroup(String groupName)
see if the current subject in grouper session is in a certain group (e.g. for authorization)

Parameters:
groupName - fully qualified group name to check
Returns:
true if the subject is in group, false if subject is null or not in group

_internal_threadSafeAttributes

public Map<String,Object> _internal_threadSafeAttributes()
look at all threadlocal attributes, and extract the names and values of the threadsafe ones. if the values are cloneable, then clone them

Returns:
the map, never null

getGrouperContextType

public GrouperContextType getGrouperContextType()
get the context in which the hooks are running, e.g. UI, GSH, etc

Returns:
the context

setAttributeThreadLocal

public static void setAttributeThreadLocal(String key,
                                           Object value,
                                           boolean okToCopyToNewThread)
set a threadlocal attribute

Parameters:
key -
value -
okToCopyToNewThread - if this should be set for hooks spawned in new thread

clearThreadLocal

public static void clearThreadLocal()
clear out the threadlocal attributes at a point when everything should be clear


attributeKeySet

public Set<String> attributeKeySet()
keys of attributes (all put together, global, threadlocal, local

Returns:
the key

getAttribute

public Object getAttribute(String key)
get an attribute

Parameters:
key -
Returns:
the object or null if not found

isAsynchronous

public boolean isAsynchronous()
if this context is asynchronous

Returns:
the asynchronous

_internal_getAsynchronousGrouperSessionSubject

public edu.internet2.middleware.subject.Subject _internal_getAsynchronousGrouperSessionSubject()
keep track of grouper session subject if needed

Returns:
the asynchronousGrouperSessionSubject

_internal_isAsynchronousGrouperSessionStarted

public boolean _internal_isAsynchronousGrouperSessionStarted()
if we started one, we should stop it

Returns:
the asynchronousGrouperSessionStarted

getHookId

public String getHookId()
keep a unique id to keep the logs straight

Returns:
the hookId