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

@@ -1,62 +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.ldap.conf;
import org.apache.directory.api.ldap.model.message.AliasDerefMode;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleServerException;
import org.apache.guacamole.properties.GuacamoleProperty;
/**
* A GuacamoleProperty with a value of AliasDerefMode. The possible strings
* "never", "searching", "finding", and "always" are mapped to their values as
* an AliasDerefMode object. Anything else results in a parse error.
*/
public abstract class DereferenceAliasesProperty implements GuacamoleProperty<AliasDerefMode> {
@Override
public AliasDerefMode parseValue(String value) throws GuacamoleException {
// No value provided, so return null.
if (value == null)
return null;
// Never dereference aliases
if (value.equals("never"))
return AliasDerefMode.NEVER_DEREF_ALIASES;
// Dereference aliases during search operations, but not at base
if (value.equals("searching"))
return AliasDerefMode.DEREF_IN_SEARCHING;
// Dereference aliases to locate base, but not during searches
if (value.equals("finding"))
return AliasDerefMode.DEREF_FINDING_BASE_OBJ;
// Always dereference aliases
if (value.equals("always"))
return AliasDerefMode.DEREF_ALWAYS;
// Anything else is invalid and results in an error
throw new GuacamoleServerException("Dereference aliases must be one of \"never\", \"searching\", \"finding\", or \"always\".");
}
}

View File

@@ -19,6 +19,8 @@
package org.apache.guacamole.auth.ldap.conf;
import org.apache.guacamole.properties.EnumGuacamoleProperty.PropertyValue;
/**
* All possible encryption methods which may be used when connecting to an LDAP
* server.
@@ -29,12 +31,14 @@ public enum EncryptionMethod {
* No encryption will be used. All data will be sent to the LDAP server in
* plaintext. Unencrypted LDAP connections use port 389 by default.
*/
@PropertyValue("none")
NONE(389),
/**
* The connection to the LDAP server will be encrypted with SSL. LDAP over
* SSL (LDAPS) will use port 636 by default.
*/
@PropertyValue("ssl")
SSL(636),
/**
@@ -42,6 +46,7 @@ public enum EncryptionMethod {
* connections are negotiated over the standard LDAP port of 389 - the same
* port used for unencrypted traffic.
*/
@PropertyValue("starttls")
STARTTLS(389);
/**

View File

@@ -1,58 +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.ldap.conf;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleServerException;
import org.apache.guacamole.properties.GuacamoleProperty;
/**
* A GuacamoleProperty whose value is an EncryptionMethod. The string values
* "none", "ssl", and "starttls" are each parsed to their corresponding values
* within the EncryptionMethod enum. All other string values result in parse
* errors.
*/
public abstract class EncryptionMethodProperty implements GuacamoleProperty<EncryptionMethod> {
@Override
public EncryptionMethod parseValue(String value) throws GuacamoleException {
// If no value provided, return null.
if (value == null)
return null;
// Plaintext (no encryption)
if (value.equals("none"))
return EncryptionMethod.NONE;
// SSL
if (value.equals("ssl"))
return EncryptionMethod.SSL;
// STARTTLS
if (value.equals("starttls"))
return EncryptionMethod.STARTTLS;
// The provided value is not legal
throw new GuacamoleServerException("Encryption method must be one of \"none\", \"ssl\", or \"starttls\".");
}
}

View File

@@ -19,7 +19,9 @@
package org.apache.guacamole.auth.ldap.conf;
import org.apache.directory.api.ldap.model.message.AliasDerefMode;
import org.apache.guacamole.properties.BooleanGuacamoleProperty;
import org.apache.guacamole.properties.EnumGuacamoleProperty;
import org.apache.guacamole.properties.IntegerGuacamoleProperty;
import org.apache.guacamole.properties.StringGuacamoleProperty;
@@ -158,8 +160,8 @@ public class LDAPGuacamoleProperties {
* The chosen method will also dictate the default port if not already
* explicitly specified via LDAP_PORT.
*/
public static final EncryptionMethodProperty LDAP_ENCRYPTION_METHOD =
new EncryptionMethodProperty() {
public static final EnumGuacamoleProperty<EncryptionMethod> LDAP_ENCRYPTION_METHOD =
new EnumGuacamoleProperty<EncryptionMethod>(EncryptionMethod.class) {
@Override
public String getName() { return "ldap-encryption-method"; }
@@ -181,8 +183,13 @@ public class LDAPGuacamoleProperties {
* Property that controls whether or not the LDAP connection follows
* (dereferences) aliases as it searches the tree.
*/
public static final DereferenceAliasesProperty LDAP_DEREFERENCE_ALIASES =
new DereferenceAliasesProperty() {
public static final EnumGuacamoleProperty<AliasDerefMode> LDAP_DEREFERENCE_ALIASES =
new EnumGuacamoleProperty<AliasDerefMode>(
"never", AliasDerefMode.NEVER_DEREF_ALIASES,
"searching", AliasDerefMode.DEREF_IN_SEARCHING,
"finding", AliasDerefMode.DEREF_FINDING_BASE_OBJ,
"always", AliasDerefMode.DEREF_ALWAYS
) {
@Override
public String getName() { return "ldap-dereference-aliases"; }
@@ -257,10 +264,10 @@ public class LDAPGuacamoleProperties {
};
/**
* Specify the type of data contained in 'ldap-member-attribute'
* Specify the type of data contained in 'ldap-member-attribute'.
*/
public static final MemberAttributeTypeProperty LDAP_MEMBER_ATTRIBUTE_TYPE =
new MemberAttributeTypeProperty() {
public static final EnumGuacamoleProperty<MemberAttributeType> LDAP_MEMBER_ATTRIBUTE_TYPE =
new EnumGuacamoleProperty<MemberAttributeType>(MemberAttributeType.class) {
@Override
public String getName() { return "ldap-member-attribute-type"; }

View File

@@ -19,20 +19,24 @@
package org.apache.guacamole.auth.ldap.conf;
import org.apache.guacamole.properties.EnumGuacamoleProperty.PropertyValue;
/**
* All possible means of describing membership within
* LDAP group directory records.
* All possible means of describing membership within LDAP group directory
* records.
*/
public enum MemberAttributeType {
/**
* group membership is specified by DN
* Group membership is specified by DN.
*/
@PropertyValue("dn")
DN,
/**
* group membership is specified by usercode
* Group membership is specified by usercode.
*/
@PropertyValue("uid")
UID;
}

View File

@@ -1,56 +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.ldap.conf;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleServerException;
import org.apache.guacamole.properties.GuacamoleProperty;
/**
* A GuacamoleProperty whose value is a MemberAttributeType. The possible
* strings "dn" or "uid" are mapped to their values as a MemberAttributeType
* enum. Anything else results in a parse error.
*/
public abstract class MemberAttributeTypeProperty
implements GuacamoleProperty<MemberAttributeType> {
@Override
public MemberAttributeType parseValue(String value)
throws GuacamoleException {
// If no value provided, return null.
if (value == null)
return null;
// dn
if (value.equals("dn"))
return MemberAttributeType.DN;
// uid
if (value.equals("uid"))
return MemberAttributeType.UID;
// The provided value is not legal
throw new GuacamoleServerException("Member attribute type must be "
+ "one of \"dn\" or \"uid\".");
}
}