Class ServerCredential

java.lang.Object
com.ultikits.ultitools.utils.ServerCredential

final class ServerCredential extends Object
The per-server UltiCloud credential (protocol v2, prefix ucs_) and the facts the device authorization returned with it.

The credential is opaque, never expires and has no refresh token; it is revoked by the owner in the panel or replaced by a rotation. The secret is readable only through the package-private bearerValue(), and toString() leaves it out, so a log line built from this object cannot carry it.

Since:
6.3.1
  • Field Details

  • Constructor Details

    • ServerCredential

      ServerCredential(String credential, String credentialId, String serverId, Long userId, String serverName, long linkedAt)
      Parameters:
      credential - the ucs_ secret; must start with SECRET_PREFIX
      credentialId - the credential's public id, or null
      serverId - the server's public id (a ULID); must be non-empty
      userId - the linking owner's id, or null
      serverName - the name the owner chose on the confirmation page, or null
      linkedAt - when the link was made, epoch milliseconds
  • Method Details

    • isWellFormedSecret

      static boolean isWellFormedSecret(String credential)
      Parameters:
      credential - the candidate secret
      Returns:
      true if it has the ucs_ prefix and at least one character after it
    • fromDocument

      static ServerCredential fromDocument(Object entry)
      Reads one cloud_credential document entry.
      Parameters:
      entry - the value stored under the key, as parsed by CredentialStore
      Returns:
      the credential, or null if the entry is not an object, the secret is not well formed or the server id is missing
    • text

      private static String text(Object value)
    • storedUserId

      private static Long storedUserId(Object value)
      Reads legacy decimal text only at the persistence boundary, never on the REST wire.
    • parseUserId

      static Long parseUserId(Number value)
      Returns:
      the exact contract integer in [1, 2^53 - 1], or null; never truncates or wraps
    • toDocument

      Map<String,Object> toDocument()
      Returns:
      the document entry ServerCredentialStore writes under cloud_credential
    • rotated

      ServerCredential rotated(String rotatedSecret, String rotatedId)
      The same link with a rotated secret (plan 22-21, D-10): server id, owner, name and link time are kept, exactly as ServerCredentialStore.replace(java.lang.String, java.lang.String, java.lang.String) keeps them on disk.
      Parameters:
      rotatedSecret - the new ucs_ secret
      rotatedId - the new credential's public id
      Returns:
      the rotated credential
    • bearerValue

      String bearerValue()
      Returns:
      the secret, for the Authorization: Bearer header only -- never log it
    • getCredentialId

      String getCredentialId()
      Returns:
      the credential's public id, or null
    • getServerId

      String getServerId()
      Returns:
      the server's public id (a ULID); never null
    • getUserId

      Long getUserId()
      Returns:
      the linking owner's id, or null
    • getServerName

      String getServerName()
      Returns:
      the server name chosen on the confirmation page, or null
    • getLinkedAt

      long getLinkedAt()
      Returns:
      when the link was made, epoch milliseconds
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      the public fields only -- never the secret