Class AuthoritiesImpl

  • All Implemented Interfaces:
    Authorities

    public final class AuthoritiesImpl
    extends Object
    implements Authorities
    A map backed implementation of authorities on resources and operations.
    • 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
    • Constructor Detail

      • AuthoritiesImpl

        public AuthoritiesImpl()
        Creates empty authorities.
    • 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 is null.
      • 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 interface Authorities
        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 interface Authorities
        Parameters:
        resource - The resource.
        operation - The operation to execute.
        Returns:
        true if execution is allowed.