Class AuthorizationAttribute<T>

java.lang.Object
org.forgerock.authz.filter.api.AuthorizationAttribute<T>
Type Parameters:
T - The type of the attribute.

public final class AuthorizationAttribute<T> extends Object

Provides a convenience layer on top of AuthorizationContext to simplify access to particular attributes in the authorisation context. Usage:


     AuthorizationAttribute&lt;Set&lt;String&gt;&gt; rolesAttr = new AuthorizationAttribute&lt;&gt;("roles");
     ...
     rolesAttr.set(context, Collections.singleton("someRole"));
     ...
     Set<String> roles = rolesAttr.get(context);
 

Note that due to the dynamic nature of request attributes, it is not possible to make this completely type-safe.

Clients should be prepared for runtime ClassCastExceptions if an unexpected value is found in an authorization context.

Since:
1.4.0
  • Constructor Details

    • AuthorizationAttribute

      public AuthorizationAttribute(String key)
      Constructs an authorization attribute for the given authorization context key.
      Parameters:
      key - The key to use for this attribute in the AuthorizationContext.
      Throws:
      NullPointerException - If the key is null.
  • Method Details

    • get

      public T get(AuthorizationContext context)
      Gets this attribute from the given authorization context.
      Parameters:
      context - The context to get this attribute from.
      Returns:
      The attribute from the context or null if not set.
      Throws:
      ClassCastException - If an entry exists in the context for this key but has the wrong type.
      NullPointerException - If the context is null.
    • set

      public void set(AuthorizationContext context, T value)
      Sets this attribute in the given authorization context to the given value.
      Parameters:
      context - The context to set the attribute in.
      value - The value to set.
      Throws:
      NullPointerException - If the context is null.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object