As a basic pre-flight check, you could try getting the cluster info. This will fail with
InvalidPasswordException if the credentials are not valid:
CouchbaseCluster cluster = CouchbaseCluster.create("localhost");
ClusterInfo info = cluster.clusterManager(username, password).info();
// Didn't throw exception. User exists and password is valid.
Because Couchbase Server 5.0 and later use Role-Based Access Control, it’s possible for a user to have access to the cluster info but not have permission to open a bucket.
You can see what roles a user has by calling
clusterManager.getUser(AuthDomain authDomain, String username), assuming the cluster manager was created with credentials for a user who has permission to view user info. That might be overkill for your use case though.
Caveat: getUser doesn’t appear to to work with the built-in “Administrator” user, but it should work with external users and any users you add in the web console.