Package org.forgerock.authz.filter.api
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<Set<String>> rolesAttr = new AuthorizationAttribute<>("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
ClassCastException
s if an unexpected value is found in an authorization context.- Since:
- 1.4.0
-
-
Constructor Summary
Constructors Constructor Description AuthorizationAttribute(String key)
Constructs an authorization attribute for the given authorization context key.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
T
get(AuthorizationContext context)
Gets this attribute from the given authorization context.int
hashCode()
void
set(AuthorizationContext context, T value)
Sets this attribute in the given authorization context to the given value.String
toString()
-
-
-
Constructor Detail
-
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 theAuthorizationContext
.- Throws:
NullPointerException
- If the key is null.
-
-
Method Detail
-
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.
-
-