org.herodbsql.jdbc.GSSEncMode Maven / Gradle / Ivy
/*
 * Copyright (c) 2020, PostgreSQL Global Development Group
 * See the LICENSE file in the project root for more information.
 */
package org.herodbsql.jdbc;
import org.herodbsql.PGProperty;
import org.herodbsql.util.GT;
import org.herodbsql.util.PSQLException;
import org.herodbsql.util.PSQLState;
import java.util.Properties;
public enum GSSEncMode {
  /**
   * Do not use encrypted connections.
   */
  DISABLE("disable"),
  /**
   * Start with non-encrypted connection, then try encrypted one.
   */
  ALLOW("allow"),
  /**
   * Start with encrypted connection, fallback to non-encrypted (default).
   */
  PREFER("prefer"),
  /**
   * Ensure connection is encrypted.
   */
  REQUIRE("require");
  private static final GSSEncMode[] VALUES = values();
  public final String value;
  GSSEncMode(String value) {
    this.value = value;
  }
  public boolean requireEncryption() {
    return this.compareTo(REQUIRE) >= 0;
  }
  public static GSSEncMode of(Properties info) throws PSQLException {
    String gssEncMode = PGProperty.GSS_ENC_MODE.getOrDefault(info);
    // If gssEncMode is not set, fallback to allow
    if (gssEncMode == null) {
      return ALLOW;
    }
    for (GSSEncMode mode : VALUES) {
      if (mode.value.equalsIgnoreCase(gssEncMode)) {
        return mode;
      }
    }
    throw new PSQLException(GT.tr("Invalid gssEncMode value: {0}", gssEncMode),
        PSQLState.CONNECTION_UNABLE_TO_CONNECT);
  }
}
    © 2015 - 2025 Weber Informatics LLC | Privacy Policy