Class AuthorizationContext


  • public class AuthorizationContext
    extends Object
    Context to use for authorization requests. Authorization modules can add additional information to the context, which will be passed on to further authorization filters and the protected resource via request attributes. Provides simple dynamic typing for getting and setting attribute values on the context.
    Since:
    1.4.0
    • Constructor Detail

      • AuthorizationContext

        public AuthorizationContext()
        Constructs a blank authorization context.
      • AuthorizationContext

        public AuthorizationContext​(Map<String,​Object> attributes)
        Creates a new authorization context using the given attribute map as a backing store.
        Parameters:
        attributes - The initial attributes to copy into the new context.
    • Method Detail

      • getAttribute

        public <T> T getAttribute​(String key)
        Gets an attribute from the authorization context, returning null if it does not exist.
        Type Parameters:
        T - The result type.
        Parameters:
        key - The key of the attribute.
        Returns:
        The attribute value, or null if it does not exist.
        Throws:
        NullPointerException - If the key is null.
        ClassCastException - If the attribute exists but is not of the expected type.
      • setAttribute

        public AuthorizationContext setAttribute​(String key,
                                                 Object value)
        Sets an attribute in the shared context.
        Parameters:
        key - The key to set.
        value - The value to associate with the key.
        Returns:
        This context to allow method chaining.
        Throws:
        NullPointerException - If the key or value is null.
      • getAttributes

        public Map<String,​Object> getAttributes()
        Gets a copy of all attributes set in this authorization context. Changes made to the returned map will not be reflected in the authorization context.
        Returns:
        A copy of the attributes in this context.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object