GUACAMOLE-728: Migrate existing enum-based GuacamoleProperty implementations to EnumGuacamoleProperty.

This commit is contained in:
Michael Jumper
2020-06-10 18:05:53 -07:00
parent 7d6e383e4a
commit 7c44ee2a67
19 changed files with 80 additions and 496 deletions

View File

@@ -68,10 +68,10 @@ public class RadiusAuthenticationProviderModule extends AbstractModule {
// Check for MD4 requirement
RadiusAuthenticationProtocol authProtocol = environment.getProperty(RadiusGuacamoleProperties.RADIUS_AUTH_PROTOCOL);
RadiusAuthenticationProtocol innerProtocol = environment.getProperty(RadiusGuacamoleProperties.RADIUS_EAP_TTLS_INNER_PROTOCOL);
if (authProtocol == RadiusAuthenticationProtocol.MSCHAPv1
|| authProtocol == RadiusAuthenticationProtocol.MSCHAPv2
|| innerProtocol == RadiusAuthenticationProtocol.MSCHAPv1
|| innerProtocol == RadiusAuthenticationProtocol.MSCHAPv2) {
if (authProtocol == RadiusAuthenticationProtocol.MSCHAP_V1
|| authProtocol == RadiusAuthenticationProtocol.MSCHAP_V2
|| innerProtocol == RadiusAuthenticationProtocol.MSCHAP_V1
|| innerProtocol == RadiusAuthenticationProtocol.MSCHAP_V2) {
try {
MessageDigest.getInstance("MD4");

View File

@@ -19,6 +19,8 @@
package org.apache.guacamole.auth.radius.conf;
import org.apache.guacamole.properties.EnumGuacamoleProperty.PropertyValue;
/**
* This enum represents supported RADIUS authentication protocols for
* the guacamole-auth-radius extension.
@@ -26,93 +28,45 @@ package org.apache.guacamole.auth.radius.conf;
public enum RadiusAuthenticationProtocol {
/**
* Password Authentication Protocol (PAP)
* Password Authentication Protocol (PAP).
*/
PAP("pap"),
@PropertyValue("pap")
PAP,
/**
* Challenge-Handshake Authentication Protocol (CHAP)
* Challenge-Handshake Authentication Protocol (CHAP).
*/
CHAP("chap"),
@PropertyValue("chap")
CHAP,
/**
* Microsoft implementation of CHAP, Version 1 (MS-CHAPv1)
* Microsoft implementation of CHAP, Version 1 (MS-CHAPv1).
*/
MSCHAPv1("mschapv1"),
@PropertyValue("mschapv1")
MSCHAP_V1,
/**
* Microsoft implementation of CHAP, Version 2 (MS-CHAPv2)
* Microsoft implementation of CHAP, Version 2 (MS-CHAPv2).
*/
MSCHAPv2("mschapv2"),
@PropertyValue("mschapv2")
MSCHAP_V2,
/**
* Extensible Authentication Protocol (EAP) with MD5 Hashing (EAP-MD5)
* Extensible Authentication Protocol (EAP) with MD5 Hashing (EAP-MD5).
*/
EAP_MD5("eap-md5"),
@PropertyValue("eap-md5")
EAP_MD5,
/**
* Extensible Authentication Protocol (EAP) with TLS encryption (EAP-TLS).
*/
EAP_TLS("eap-tls"),
@PropertyValue("eap-tls")
EAP_TLS,
/**
* Extensible Authentication Protocol (EAP) with Tunneled TLS (EAP-TTLS).
*/
EAP_TTLS("eap-ttls");
@PropertyValue("eap-ttls")
EAP_TTLS;
/**
* This variable stores the string value of the protocol, and is also
* used within the extension to pass to JRadius for configuring the
* library to talk to the RADIUS server.
*/
private final String strValue;
/**
* Create a new RadiusAuthenticationProtocol object having the
* given string value.
*
* @param strValue
* The value of the protocol to store as a string, which will be used
* in specifying the protocol within the guacamole.properties file, and
* will also be used by the JRadius library for its configuration.
*/
RadiusAuthenticationProtocol(String strValue) {
this.strValue = strValue;
}
/**
* {@inheritDoc}
* <p>
* This function returns the stored string values of the selected RADIUS
* protocol, which is used both in Guacamole configuration and also to pass
* on to the JRadius library for its configuration.
*
* @return
* The string value stored for the selected RADIUS protocol.
*/
@Override
public String toString() {
return strValue;
}
/**
* For a given String value, return the enum value that matches that string,
* or null if no matchi is found.
*
* @param value
* The string value to search for in the list of enums.
*
* @return
* The RadiusAuthenticationProtocol value that is identified by the
* provided String value.
*/
public static RadiusAuthenticationProtocol getEnum(String value) {
for (RadiusAuthenticationProtocol v : values())
if(v.toString().equals(value))
return v;
return null;
}
}

View File

@@ -1,54 +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.radius.conf;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleServerException;
import org.apache.guacamole.properties.GuacamoleProperty;
/**
* A GuacamoleProperty whose value is a RadiusAuthenticationProtocol.
*/
public abstract class RadiusAuthenticationProtocolProperty
implements GuacamoleProperty<RadiusAuthenticationProtocol> {
@Override
public RadiusAuthenticationProtocol parseValue(String value)
throws GuacamoleException {
// Nothing provided, nothing returned
if (value == null)
return null;
// Attempt to parse the string value
RadiusAuthenticationProtocol authProtocol =
RadiusAuthenticationProtocol.getEnum(value);
// Throw an exception if nothing matched.
if (authProtocol == null)
throw new GuacamoleServerException(
"Invalid or unsupported RADIUS authentication protocol.");
// Return the answer
return authProtocol;
}
}

View File

@@ -20,6 +20,7 @@
package org.apache.guacamole.auth.radius.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;
@@ -81,8 +82,8 @@ public class RadiusGuacamoleProperties {
/**
* The authentication protocol of the RADIUS server to connect to when authenticating users.
*/
public static final RadiusAuthenticationProtocolProperty RADIUS_AUTH_PROTOCOL =
new RadiusAuthenticationProtocolProperty() {
public static final EnumGuacamoleProperty<RadiusAuthenticationProtocol> RADIUS_AUTH_PROTOCOL =
new EnumGuacamoleProperty<RadiusAuthenticationProtocol>(RadiusAuthenticationProtocol.class) {
@Override
public String getName() { return "radius-auth-protocol"; }
@@ -182,8 +183,8 @@ public class RadiusGuacamoleProperties {
/**
* The tunneled protocol to use inside a RADIUS EAP-TTLS connection.
*/
public static final RadiusAuthenticationProtocolProperty RADIUS_EAP_TTLS_INNER_PROTOCOL =
new RadiusAuthenticationProtocolProperty() {
public static final EnumGuacamoleProperty<RadiusAuthenticationProtocol> RADIUS_EAP_TTLS_INNER_PROTOCOL =
new EnumGuacamoleProperty<RadiusAuthenticationProtocol>(RadiusAuthenticationProtocol.class) {
@Override
public String getName() { return "radius-eap-ttls-inner-protocol"; }