Class HooksContext

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

public class HooksContext extends Object
context in which hooks are running
  • Field Details

    • HOOKS_KEY_SUBJECT_LOGGED_IN

      public static final String HOOKS_KEY_SUBJECT_LOGGED_IN
      hooks internal attribute key for grouper session
      See Also:
    • HOOKS_KEY_SUBJECT_ACT_AS

      public static final String HOOKS_KEY_SUBJECT_ACT_AS
      hooks internal attribute key for grouper session
      See Also:
    • KEY_HTTP_SERVLET_RESPONSE

      public static final String KEY_HTTP_SERVLET_RESPONSE
      if application, key in context for response
      See Also:
    • KEY_HTTP_SESSION

      public static final String KEY_HTTP_SESSION
      if application, key in context for session
      See Also:
    • KEY_HTTP_SERVLET_REQUEST

      public static final String KEY_HTTP_SERVLET_REQUEST
      if application, key in context for request
      See Also:
  • Constructor Details

    • HooksContext

      public HooksContext()
      constructor
    • HooksContext

      public HooksContext(boolean theAsynchronous, Map<String,Object> threadSafeAttributes, 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 Details

    • getSubjectLoggedIn

      public 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 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 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 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(Subject subject)
      this will be a threadsafe attribute
      Parameters:
      subject - or null to clear
    • assignSubjectActAs

      public static void assignSubjectActAs(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 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