GUACAMOLE-728: Properly expose JDBC driver values from enums.

This commit is contained in:
Virtually Nick
2020-06-16 11:44:07 -04:00
parent 31288fc4d0
commit 986d5a1225
4 changed files with 51 additions and 30 deletions

View File

@@ -86,7 +86,7 @@ public class MySQLAuthenticationProviderModule implements Module {
// Set the SSL mode to use when conncting // Set the SSL mode to use when conncting
MySQLSSLMode sslMode = environment.getMySQLSSLMode(); MySQLSSLMode sslMode = environment.getMySQLSSLMode();
driverProperties.setProperty("sslMode", sslMode.toString()); driverProperties.setProperty("sslMode", sslMode.getDriverValue());
// Set legacy properties // Set legacy properties
if (sslMode == MySQLSSLMode.DISABLED) if (sslMode == MySQLSSLMode.DISABLED)

View File

@@ -30,31 +30,60 @@ public enum MySQLSSLMode {
* Do not use SSL at all. * Do not use SSL at all.
*/ */
@PropertyValue("disabled") @PropertyValue("disabled")
DISABLED, DISABLED("disabled"),
/** /**
* Prefer SSL, but fall back to unencrypted. * Prefer SSL, but fall back to unencrypted.
*/ */
@PropertyValue("preferred") @PropertyValue("preferred")
PREFERRED, PREFERRED("preferred"),
/** /**
* Require SSL, but perform no certificate validation. * Require SSL, but perform no certificate validation.
*/ */
@PropertyValue("required") @PropertyValue("required")
REQUIRED, REQUIRED("required"),
/** /**
* Require SSL, and validate server certificate issuer. * Require SSL, and validate server certificate issuer.
*/ */
@PropertyValue("verify-ca") @PropertyValue("verify-ca")
VERIFY_CA, VERIFY_CA("verify-ca"),
/** /**
* Require SSL and validate both server certificate issuer and server * Require SSL and validate both server certificate issuer and server
* identity. * identity.
*/ */
@PropertyValue("verify-identity") @PropertyValue("verify-identity")
VERIFY_IDENTITY; VERIFY_IDENTITY("verify-identity");
/**
* The value expected by and passed on to the JDBC driver for the given
* SSL operation mode.
*/
private final String driverValue;
/**
* Create a new instance of this enum with the given driverValue as the
* value that will be used when configuring the JDBC driver.
*
* @param driverValue
* The value to use when configuring the JDBC driver.
*/
MySQLSSLMode(String driverValue) {
this.driverValue = driverValue;
}
/**
* Returns the String value for a given Enum that properly configures the
* JDBC driver for the desired mode of SSL operation.
*
* @return
* The String value for the current Enum that configures the JDBC driver
* for the desired mode of SSL operation.
*/
public String getDriverValue() {
return driverValue;
}
} }

View File

@@ -75,10 +75,12 @@ public class PostgreSQLAuthenticationProviderModule implements Module {
// Check the SSL mode and set if configured. // Check the SSL mode and set if configured.
PostgreSQLSSLMode sslMode = environment.getPostgreSQLSSLMode(); PostgreSQLSSLMode sslMode = environment.getPostgreSQLSSLMode();
driverProperties.setProperty("sslmode", sslMode.toString()); driverProperties.setProperty("sslmode", sslMode.getDriverValue());
// If SSL is enabled, check for and set other SSL properties. // If SSL is enabled, check for and set other SSL properties.
if (sslMode != PostgreSQLSSLMode.DISABLE) { if (sslMode != PostgreSQLSSLMode.DISABLE) {
// Sets the legacy SSL configuration mode required by older servers.
driverProperties.setProperty("ssl", "true"); driverProperties.setProperty("ssl", "true");
File sslClientCert = environment.getPostgreSQLSSLClientCertFile(); File sslClientCert = environment.getPostgreSQLSSLClientCertFile();

View File

@@ -63,42 +63,32 @@ public enum PostgreSQLSSLMode {
VERIFY_FULL("verify-full"); VERIFY_FULL("verify-full");
/** /**
* The value actually passed on to the JDBC driver. * The value expected by and passed on to the JDBC driver for the given
* SSL operation mode.
*/ */
private final String configValue; private final String driverValue;
/** /**
* Create a new instance of this enum with the given configValue as the * Create a new instance of this enum with the given driverValue as the
* value that will be used when configuring the JDBC driver. * value that will be used when configuring the JDBC driver.
* *
* @param configValue * @param driverValue
* The value to use when configuring the JDBC driver. * The value to use when configuring the JDBC driver.
*/ */
PostgreSQLSSLMode(String configValue) { PostgreSQLSSLMode(String driverValue) {
this.configValue = configValue; this.driverValue = driverValue;
}
@Override
public String toString() {
return configValue;
} }
/** /**
* Given the String value, determine the correct enum value that matches * Returns the String value for a given Enum that properly configures the
* the string, or null if there is no match. * JDBC driver for the desired mode of SSL operation.
*
* @param value
* The String value to test to find a match.
* *
* @return * @return
* The enum value matching the given String. * The String value for the current Enum that configures the JDBC driver
* for the desired mode of SSL operation.
*/ */
public static PostgreSQLSSLMode getValue(String value) { public String getDriverValue() {
for (PostgreSQLSSLMode mode : PostgreSQLSSLMode.values()) { return driverValue;
if (mode.toString().equals(value))
return mode;
}
return null;
} }
} }