Class Credential

java.lang.Object
com.couchbase.analytics.client.java.Credential

@ThreadSafe public abstract class Credential extends Object
Create an instance like this:
 Credential.of(username, password)
 
Alternatively, to use a client certificate:
 Credential.fromKeyStore(
     Paths.get("/path/to/client-cert.p12"),
     "password"
 )
 
See Also:
  • Method Details

    • of

      public static Credential of(String username, String password)
      Returns a new instance that holds the given username and password.
    • ofJwt

      public static Credential ofJwt(String jwt)
      Returns a new instance that holds the given JSON Web Token (JWT).

      Requires Enterprise Analytics 2.2 or later.

      NOTE: This kind of credential often has a relatively short validity period. To prevent authentication failures caused by stale credentials, periodically pass a fresh credential to Cluster.credential(Credential).

    • fromKeyStore

      public static Credential fromKeyStore(Path pkcs12Path, @Nullable String password)
      Returns a new instance that holds a client certificate loaded from the specified PKCS#12 key store file.

      The key store must have a single entry which must contain a private key and certificate chain. The same password must be used for integrity and encryption.

      TIP: One way to create a suitable PKCS#12 file from a PEM-encoded private key and certificate is to concatenate the key and certificate into a file named "client-cert.pem", then run this command:

       openssl pkcs12 -export -in client-cert.pem -out client-cert.p12 -passout pass:password
       
      This creates a PKCS#12 file named "client-cert.p12" protected by the password "password".
      Parameters:
      password - for verifying key store integrity and decrypting the private key
    • fromKeyStore

      public static Credential fromKeyStore(KeyStore keyStore, @Nullable String password)
      Returns a new instance that holds a client certificate loaded from the specified key store.

      The key store must have a single entry which must contain a private key and certificate chain.

      Parameters:
      password - for decrypting the private key
    • ofDynamic

      @Deprecated public static Credential ofDynamic(Supplier<Credential> supplier)
      Deprecated.
      This method is not compatible with client certificate credentials. Instead, please update the credential by calling Cluster.credential(Credential).
      Returns a new instance of a dynamic credential that invokes the given supplier every time a credential is required.

      This enables updating a credential without having to restart your application.