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.
Constructor and Description |
---|
AuthorizationAttribute(String key)
Constructs an authorization attribute for the given authorization context key.
|
Modifier and Type | Method and 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() |
public AuthorizationAttribute(String key)
key
- The key to use for this attribute in the AuthorizationContext
.NullPointerException
- If the key is null.public T get(AuthorizationContext context)
context
- The context to get this attribute from.ClassCastException
- If an entry exists in the context for this key but has the wrong type.NullPointerException
- If the context is null.public void set(AuthorizationContext context, T value)
context
- The context to set the attribute in.value
- The value to set.NullPointerException
- If the context is null.Copyright © 2010-2018, ForgeRock All Rights Reserved.