Class Auth


  • public class Auth
    extends java.lang.Object
    Token-generation and authentication operations for the Ably API. See the Ably Authentication documentation for details of the authentication methods available.
    • Field Detail

      • clientId

        public java.lang.String clientId
        The clientId for this library instance Spec RSA7b
      • WILDCARD_CLIENTID

        public static final java.lang.String WILDCARD_CLIENTID
        See Also:
        Constant Field Values
    • Method Detail

      • authorize

        public Auth.TokenDetails authorize​(Auth.TokenParams params,
                                           Auth.AuthOptions options)
                                    throws AblyException
        Ensure valid auth credentials are present. This may rely in an already-known and valid token, and will obtain a new token if necessary or explicitly requested. Authorization will use the parameters supplied on construction except where overridden with the options supplied in the call.
        Parameters:
        params - an object containing the request params: - key: (optional) the key to use; if not specified, the key passed in constructing the Rest interface may be used - ttl: (optional) the requested life of any new token in ms. If none is specified a default of 1 hour is provided. The maximum lifetime is 24hours; any request exceeeding that lifetime will be rejected with an error. - capability: (optional) the capability to associate with the access token. If none is specified, a token will be requested with all of the capabilities of the specified key. - clientId: (optional) a client Id to associate with the token - timestamp: (optional) the time in ms since the epoch. If none is specified, the system will be queried for a time value to use. - queryTime (optional) boolean indicating that the Ably system should be queried for the current time when none is specified explicitly.
        options -
        Throws:
        AblyException
      • getAuthMethod

        public Auth.AuthMethod getAuthMethod()
        Get the authentication method for this library instance.
        Returns:
      • getBasicCredentials

        public java.lang.String getBasicCredentials()
        Get the credentials for HTTP basic auth, if available.
        Returns:
      • getAuthParams

        public Param[] getAuthParams()
                              throws AblyException
        Get query params representing the current authentication method and credentials.
        Returns:
        Throws:
        AblyException
      • getAuthOptions

        public Auth.AuthOptions getAuthOptions()
        Get (a copy of) auth options currently set in this Auth.
      • renew

        public Auth.TokenDetails renew()
                                throws AblyException
        Renew auth credentials. Will obtain a new token, even if we already have an apparently valid one. Authorization will use the parameters supplied on construction.
        Throws:
        AblyException
      • onAuthError

        public void onAuthError​(ErrorInfo err)
      • timestamp

        public static long timestamp()
      • getEncodedToken

        public java.lang.String getEncodedToken()
      • assertAuthorizationHeader

        public void assertAuthorizationHeader​(boolean forceRenew)
                                       throws AblyException
        Get the Authorization header, forcing the creation of a new token if requested
        Parameters:
        forceRenew -
        Throws:
        AblyException
      • getAuthorizationHeader

        public java.lang.String getAuthorizationHeader()
      • setClientId

        public void setClientId​(java.lang.String clientId)
                         throws AblyException
        Set the clientId, after first initialisation in the construction of the library therefore an existing null value is significant - it means that ClientOptions.clientId was null
        Parameters:
        clientId -
        Throws:
        AblyException
      • checkClientId

        public java.lang.String checkClientId​(BaseMessage msg,
                                              boolean allowNullClientId,
                                              boolean connected)
                                       throws AblyException
        Verify that a message, possibly containing a clientId, is compatible with Auth.clientId if it is set
        Parameters:
        msg -
        allowNullClientId - : true if it is ok for there to be no resolved clientId
        connected - : true if connected; if false it is ok for the library to be unidentified
        Returns:
        the resolved clientId
        Throws:
        AblyException
      • serverTimestamp

        public long serverTimestamp()
        Using time delta obtained before guess current server time
      • clearCachedServerTime

        public void clearCachedServerTime()
        For testing purposes we need method to clear cached timeDelta