Package org.eclipse.hono.auth
Class AuthoritiesImpl
- java.lang.Object
-
- org.eclipse.hono.auth.AuthoritiesImpl
-
- All Implemented Interfaces:
Authorities
public final class AuthoritiesImpl extends Object implements Authorities
A map backed implementation of authorities on resources and operations.
-
-
Field Summary
Fields Modifier and Type Field Description static String
PREFIX_OPERATION
The prefix used to indicate an authority on an operation.static String
PREFIX_RESOURCE
The prefix used to indicate an authority on a resource.
-
Constructor Summary
Constructors Constructor Description AuthoritiesImpl()
Creates empty authorities.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AuthoritiesImpl
addAll(Authorities authoritiesToAdd)
Adds all authorities contained in another object to this instance.AuthoritiesImpl
addOperation(String resource, String operation)
Adds an authority to execute an operation.AuthoritiesImpl
addOperation(String endpoint, String tenant, String operation)
Adds an authority to execute an operation.AuthoritiesImpl
addResource(String endpoint, String tenant, Activity... activities)
Adds an authority to perform one or more activities on a resource.AuthoritiesImpl
addResource(String resource, Activity... activities)
Adds an authority to perform one or more activities on a resource.Map<String,Object>
asMap()
Gets the authorities as a map of claims.static Authorities
from(io.jsonwebtoken.Claims claims)
Creates authorities from claims from a JWT.boolean
isAuthorized(ResourceIdentifier resource, String operation)
Checks if these authorities include claims allowing execution of an operation of a resource.boolean
isAuthorized(ResourceIdentifier resource, Activity intent)
Checks if these authorities include claims allowing an intended activity on a resource.
-
-
-
Field Detail
-
PREFIX_RESOURCE
public static final String PREFIX_RESOURCE
The prefix used to indicate an authority on a resource.- See Also:
- Constant Field Values
-
PREFIX_OPERATION
public static final String PREFIX_OPERATION
The prefix used to indicate an authority on an operation.- See Also:
- Constant Field Values
-
-
Method Detail
-
from
public static Authorities from(io.jsonwebtoken.Claims claims)
Creates authorities from claims from a JWT.- Parameters:
claims
- The claims object to retrieve authorities from.- Returns:
- The authorities.
- Throws:
NullPointerException
- if claims isnull
.
-
addOperation
public AuthoritiesImpl addOperation(String resource, String operation)
Adds an authority to execute an operation.- Parameters:
resource
- The resource the operation belongs to.operation
- The operation.- Returns:
- This instance for command chaining.
-
addOperation
public AuthoritiesImpl addOperation(String endpoint, String tenant, String operation)
Adds an authority to execute an operation.- Parameters:
endpoint
- The endpoint segment of the resource the operation belongs to.tenant
- The tenant segment of the resource the operation belongs to.operation
- The operation.- Returns:
- This instance for command chaining.
-
addResource
public AuthoritiesImpl addResource(String resource, Activity... activities)
Adds an authority to perform one or more activities on a resource.- Parameters:
resource
- The resource.activities
- The activities.- Returns:
- This instance for command chaining.
-
addResource
public AuthoritiesImpl addResource(String endpoint, String tenant, Activity... activities)
Adds an authority to perform one or more activities on a resource.- Parameters:
endpoint
- The endpoint segment of the resource.tenant
- The tenant segment of the resource.activities
- The activities.- Returns:
- This instance for command chaining.
-
addAll
public AuthoritiesImpl addAll(Authorities authoritiesToAdd)
Adds all authorities contained in another object to this instance.- Parameters:
authoritiesToAdd
- The object containing the authorities to add.- Returns:
- This instance for command chaining.
-
isAuthorized
public boolean isAuthorized(ResourceIdentifier resource, Activity intent)
Description copied from interface:Authorities
Checks if these authorities include claims allowing an intended activity on a resource.- Specified by:
isAuthorized
in interfaceAuthorities
- Parameters:
resource
- The resource.intent
- The intended activity on the resource- Returns:
true
if the activity is allowed.
-
isAuthorized
public boolean isAuthorized(ResourceIdentifier resource, String operation)
Description copied from interface:Authorities
Checks if these authorities include claims allowing execution of an operation of a resource.- Specified by:
isAuthorized
in interfaceAuthorities
- Parameters:
resource
- The resource.operation
- The operation to execute.- Returns:
true
if execution is allowed.
-
asMap
public Map<String,Object> asMap()
Description copied from interface:Authorities
Gets the authorities as a map of claims.- Specified by:
asMap
in interfaceAuthorities
- Returns:
- The claims.
-
-