class JmxConnectionFactory {

  public Optional<JmxCredentials> getJmxCredentialsForCluster(Optional<Cluster> cluster) {
    JmxCredentials credentials = cluster.flatMap(Cluster::getJmxCredentials).orElse(null);
    String clusterName = cluster.map(Cluster::getName).orElse("");

    if (credentials == null && jmxCredentials != null) {
      if (jmxCredentials.containsKey(clusterName)) {
        credentials = jmxCredentials.get(clusterName);
      } else if (jmxCredentials.containsKey(Cluster.toSymbolicName(clusterName))) {
        // As clusters get stored in the database with their "symbolic name" we have to look for that too
        credentials = jmxCredentials.get(Cluster.toSymbolicName(clusterName));
      }
    }

    if (credentials == null && jmxAuth != null) {
      credentials = jmxAuth;
    }

    return Optional.ofNullable(credentials);
  }

  public  JmxConnectionFactory(AppContext context, Cryptograph cryptograph);

}