GUACAMOLE-728: Refactor with EnumGuacamoleProperty and fix up comments.

This commit is contained in:
Virtually Nick
2020-06-13 22:34:01 -04:00
parent 8c2df77f2d
commit 31288fc4d0
7 changed files with 130 additions and 124 deletions

View File

@@ -20,6 +20,7 @@
package org.apache.guacamole.auth.postgresql.conf;
import org.apache.guacamole.properties.BooleanGuacamoleProperty;
import org.apache.guacamole.properties.EnumGuacamoleProperty;
import org.apache.guacamole.properties.FileGuacamoleProperty;
import org.apache.guacamole.properties.IntegerGuacamoleProperty;
import org.apache.guacamole.properties.StringGuacamoleProperty;
@@ -176,8 +177,8 @@ public class PostgreSQLGuacamoleProperties {
* The SSL mode that should be used by the JDBC driver when making
* connections to the remote server. By default SSL will be disabled.
*/
public static final PostgreSQLSSLProperty POSTGRESQL_SSL_MODE =
new PostgreSQLSSLProperty() {
public static final EnumGuacamoleProperty<PostgreSQLSSLMode> POSTGRESQL_SSL_MODE =
new EnumGuacamoleProperty<PostgreSQLSSLMode>(PostgreSQLSSLMode.class) {
@Override
public String getName() { return "postgresql-ssl-mode"; }

View File

@@ -19,31 +19,53 @@
package org.apache.guacamole.auth.postgresql.conf;
import org.apache.guacamole.properties.EnumGuacamoleProperty.PropertyValue;
/**
* Possible values for PostgreSQL SSL connectivity.
*/
public enum PostgreSQLSSLMode {
// Do not use SSL to connect to server.
/**
* Do not use SSL to connect to server.
*/
@PropertyValue("disable")
DISABLE("disable"),
// Allow SSL connections, but try non-SSL, first.
/**
* Allow SSL connections, but try non-SSL, first.
*/
@PropertyValue("allow")
ALLOW("allow"),
// Prefer SSL connections, falling back to non-SSL if that fails.
/**
* Prefer SSL connections, falling back to non-SSL if that fails.
*/
@PropertyValue("prefer")
PREFER("prefer"),
// Require SSL connections, do not connect if SSL fails.
/**
* Require SSL connections, do not connect if SSL fails.
*/
@PropertyValue("require")
REQUIRE("require"),
// Require SSL connections and validate the CA certificate.
/**
* Require SSL connections and validate the CA certificate.
*/
@PropertyValue("verify-ca")
VERIFY_CA("verify-ca"),
// Require SSL connections and validate both the CA and server certificates.
/**
* Require SSL connections and validate both the CA and server certificates.
*/
@PropertyValue("verify-full")
VERIFY_FULL("verify-full");
// The value actually passed on to the JDBC driver.
private String configValue;
/**
* The value actually passed on to the JDBC driver.
*/
private final String configValue;
/**
* Create a new instance of this enum with the given configValue as the

View File

@@ -1,47 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.guacamole.auth.postgresql.conf;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleServerException;
import org.apache.guacamole.properties.GuacamoleProperty;
/**
*
* @author nick_couchman
*/
public abstract class PostgreSQLSSLProperty
implements GuacamoleProperty<PostgreSQLSSLMode> {
@Override
public PostgreSQLSSLMode parseValue(String value) throws GuacamoleException {
if (value == null)
return null;
PostgreSQLSSLMode mode = PostgreSQLSSLMode.getValue(value);
if (mode != null)
return mode;
throw new GuacamoleServerException("Invalid PostgreSQL SSL mode configured.");
}
}