Class Capability


  • public class Capability
    extends java.lang.Object
    A class representing an Ably Capability, providing convenience methods to simplify creation of token requests
    • Constructor Summary

      Constructors 
      Constructor Description
      Capability()
      Construct a new empty Capability
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addOperation​(java.lang.String resource, java.lang.String op)
      Add an operation to an existing Capability instance for a given resource.
      void addResource​(java.lang.String resource, java.lang.String... ops)
      Add a resource to an existing Capability instance with the given set of operations.
      static java.lang.String c14n​(java.lang.String capability)
      Convenience method to canonicalise a JSON capability expression.
      void removeOperation​(java.lang.String resource, java.lang.String op)
      Remove an operation for a given resource.
      void removeResource​(java.lang.String resource)
      Remove a resource from an existing Capability instance
      java.lang.String toString()
      Get the canonicalised String text for a Capability instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Capability

        public Capability()
        Construct a new empty Capability
    • Method Detail

      • c14n

        public static java.lang.String c14n​(java.lang.String capability)
                                     throws AblyException
        Convenience method to canonicalise a JSON capability expression.
        Parameters:
        capability - a capability string, which is the JSON text for the capability
        Returns:
        a capability string which has been canonicalised
        Throws:
        AblyException - if there is an error processing the given string (if for example it is not valid JSON)
      • addResource

        public void addResource​(java.lang.String resource,
                                java.lang.String... ops)
        Add a resource to an existing Capability instance with the given set of operations. If the resource already exists, it is wholly replaced by the given set of operations.
        Parameters:
        resource - the resource string
        ops - a String varargs of the operations permitted for this resource; the arguments do not need to be sorted
      • removeResource

        public void removeResource​(java.lang.String resource)
        Remove a resource from an existing Capability instance
        Parameters:
        resource - the (possibly existing) resource
      • addOperation

        public void addOperation​(java.lang.String resource,
                                 java.lang.String op)
        Add an operation to an existing Capability instance for a given resource. If the resource does not already exist, it is created.
        Parameters:
        resource - the resource string
        op - a single operation String to be added for this resource;
      • removeOperation

        public void removeOperation​(java.lang.String resource,
                                    java.lang.String op)
        Remove an operation for a given resource. If the resource becomes empty as a result, it is removed.
        Parameters:
        resource - the resource string
        op - a operation String to be removed for this resource;
      • toString

        public java.lang.String toString()
        Get the canonicalised String text for a Capability instance. The json object and its members are sorted if the object has been modified since the last time it was canonicalised.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the canonicalised String text