Class UserContext


  • public class UserContext
    extends Object
    Provides a thread local user context object.
    • Constructor Detail

      • UserContext

        public UserContext​(String userName)
        Constructor for the class
        Parameters:
        userName - user name
      • UserContext

        public UserContext​(String userName,
                           Set<String> permissions)
        Constructor for the class
        Parameters:
        userName - user name
        permissions - a set of permissions
    • Method Detail

      • getThreadUserContext

        public static UserContext getThreadUserContext()
        Return thread local user context object.
        Returns:
        thread local user context object
      • setThreadUserContext

        public static void setThreadUserContext​(UserContext userContext)
        Set thread local user context object.
        Parameters:
        userContext - user context object
      • getUserName

        public String getUserName()
        Return user name for the user context object.
        Returns:
        user name
      • setUserName

        public void setUserName​(String userName)
        Set user name for the user context object.
        Parameters:
        userName - user name
      • getPermissions

        public Set<String> getPermissions()
        Return a set of permissions for the user context object.
        Returns:
        a set of permissions
      • setPermissions

        public void setPermissions​(Set<String> permissions)
        Set a set of permissions to the user context object.
        Parameters:
        permissions - a set of permissions
      • hasPermission

        public boolean hasPermission​(String permission)
        Check whether the permission is in the permissions set.
        Parameters:
        permission - a permission
        Returns:
        ture if the permission is in the set
      • toString

        public String toString()
        Returns a string representation of the object. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the character [, the user name, permissions set and ]. In other words, this method returns a string equal to the value of:
         getClass().getSimpleName() + "[userName=" + userName + ",permissions=" + permissions + "]";
         
        Overrides:
        toString in class Object
        Returns:
        a string representation of the object.
        See Also:
        Object.toString()