Merge changes from patch branch back to main.

This commit is contained in:
Michael Jumper
2024-11-10 10:47:51 -08:00
130 changed files with 2166 additions and 1529 deletions

View File

@@ -24,6 +24,7 @@ import java.util.Collection;
import java.util.Map;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.auth.GuacamoleProxyConfiguration;
import org.apache.guacamole.properties.CaseSensitivity;
import org.apache.guacamole.properties.GuacamoleProperties;
import org.apache.guacamole.properties.GuacamoleProperty;
import org.apache.guacamole.protocols.ProtocolInfo;
@@ -115,8 +116,8 @@ public class DelegatingEnvironment implements Environment {
}
@Override
public boolean getCaseSensitiveUsernames() throws GuacamoleException {
return environment.getCaseSensitiveUsernames();
public CaseSensitivity getCaseSensitivity() throws GuacamoleException {
return environment.getCaseSensitivity();
}
}

View File

@@ -28,6 +28,8 @@ import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleUnsupportedException;
import org.apache.guacamole.net.auth.GuacamoleProxyConfiguration;
import org.apache.guacamole.properties.BooleanGuacamoleProperty;
import org.apache.guacamole.properties.CaseSensitivity;
import org.apache.guacamole.properties.EnumGuacamoleProperty;
import org.apache.guacamole.properties.GuacamoleProperty;
import org.apache.guacamole.properties.IntegerGuacamoleProperty;
import org.apache.guacamole.properties.StringGuacamoleProperty;
@@ -71,15 +73,16 @@ public interface Environment {
};
/**
* A property that configures whether or not Guacamole will take case
* into account when comparing and processing usernames.
* A property that configures how Guacamole handles case sensitivity - it
* can be enabled for both usernames and group names, just usernames, just
* group names, or disabled for both.
*/
public static final BooleanGuacamoleProperty CASE_SENSITIVE_USERNAMES =
new BooleanGuacamoleProperty() {
public static final EnumGuacamoleProperty<CaseSensitivity> CASE_SENSITIVITY =
new EnumGuacamoleProperty<CaseSensitivity>(CaseSensitivity.class) {
@Override
public String getName() { return "case-sensitive-usernames"; }
public String getName() { return "case-sensitivity"; }
};
/**
@@ -381,21 +384,19 @@ public interface Environment {
}
/**
* Returns true if Guacamole should consider case when comparing and
* processing usernames (case-sensitive), or false if case should not be
* considered (case-insensitive). Because the past behavior of Guacamole,
* prior to the introduction of this option, was case-sensitive, the default
* value is true.
* Returns the case sensitivity configuration for Guacamole as defined
* in guacamole.properties, or the default of enabling case sensitivity
* for both usernames and group names.
*
* @return
* true if Guacamole should consider usernames case-sensitive, otherwise
* false.
* The case sensitivity setting as configured in guacamole.properties,
* or the default of enabling case sensitivity.
*
* @throws GuacamoleException
* If guacamole.properties cannot be parsed.
* If guacamole.properties cannot be read or parsed.
*/
public default boolean getCaseSensitiveUsernames() throws GuacamoleException {
return getProperty(CASE_SENSITIVE_USERNAMES, true);
public default CaseSensitivity getCaseSensitivity() throws GuacamoleException {
return getProperty(CASE_SENSITIVITY, CaseSensitivity.ENABLED);
}
}

View File

@@ -21,6 +21,11 @@ package org.apache.guacamole.net.auth;
import java.util.Collections;
import java.util.Set;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.environment.Environment;
import org.apache.guacamole.environment.LocalEnvironment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Basic implementation of an AuthenticatedUser which uses the username to
@@ -29,6 +34,17 @@ import java.util.Set;
public abstract class AbstractAuthenticatedUser extends AbstractIdentifiable
implements AuthenticatedUser {
/**
* The logger for this class.
*/
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractAuthenticatedUser.class);
/**
* The server environment in which this Guacamole Client instance is
* running.
*/
private final Environment environment = LocalEnvironment.getInstance();
// Prior functionality now resides within AbstractIdentifiable
@Override
@@ -36,6 +52,21 @@ public abstract class AbstractAuthenticatedUser extends AbstractIdentifiable
return Collections.<String>emptySet();
}
@Override
public boolean isCaseSensitive() {
try {
return environment.getCaseSensitivity().caseSensitiveUsernames();
}
catch (GuacamoleException e) {
LOGGER.error("Failed to retrieve the configuration for case sensitivity: {}. "
+ "Username comparisons will be case-sensitive.",
e.getMessage());
LOGGER.debug("An exception was caught when attempting to retrieve the "
+ "case sensitivity configuration.", e);
return true;
}
}
@Override
public void invalidate() {
// Nothing to invalidate

View File

@@ -73,11 +73,12 @@ public abstract class AbstractIdentifiable implements Identifiable {
if (otherIdentifier == null)
return identifier == null;
// If this identifier is case-sensitive, evaluate with case-sensitivity.
if (isCaseSensitive())
// If either this identifier or the one we're comparing to is
// case-sensitive, evaluate with case sensitivity.
if (isCaseSensitive() || ((AbstractIdentifiable) other).isCaseSensitive())
return otherIdentifier.equals(identifier);
// The identifier should not be evaluated in a case-sensitive manner.
// Both identifiers can be evaluated in a case-insensitive manner.
return otherIdentifier.equalsIgnoreCase(identifier);
}

View File

@@ -22,8 +22,12 @@ package org.apache.guacamole.net.auth;
import java.util.Collections;
import java.util.Map;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.environment.Environment;
import org.apache.guacamole.environment.LocalEnvironment;
import org.apache.guacamole.net.auth.permission.ObjectPermissionSet;
import org.apache.guacamole.net.auth.permission.SystemPermissionSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Base implementation of UserGroup which provides default implementations of
@@ -31,6 +35,17 @@ import org.apache.guacamole.net.auth.permission.SystemPermissionSet;
*/
public abstract class AbstractUserGroup extends AbstractIdentifiable implements UserGroup {
/**
* The logger for this class.
*/
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractUserGroup.class);
/**
* The server environment in which this Guacamole Client instance is
* running.
*/
private final Environment environment = LocalEnvironment.getInstance();
/**
* {@inheritDoc}
*
@@ -179,5 +194,20 @@ public abstract class AbstractUserGroup extends AbstractIdentifiable implements
public RelatedObjectSet getMemberUserGroups() throws GuacamoleException {
return RelatedObjectSet.EMPTY_SET;
}
@Override
public boolean isCaseSensitive() {
try {
return environment.getCaseSensitivity().caseSensitiveGroupNames();
}
catch (GuacamoleException e) {
LOGGER.warn("Unable to retrieve server configuration, group names "
+ "will default to case-sensitive.");
LOGGER.debug("Received an exception attempting to retrieve the "
+ "property for group name case sensitivity, group names"
+ "will be treated as case-sensitive.", e);
return true;
}
}
}

View File

@@ -83,6 +83,11 @@ public class DelegatingUser implements User {
return user.isDisabled();
}
@Override
public boolean isCaseSensitive() {
return user.isCaseSensitive();
}
@Override
public void setDisabled(boolean disabled) {
user.setDisabled(disabled);

View File

@@ -46,8 +46,8 @@ public interface Identifiable {
/**
* Whether or not this identifier should be evaluated in a case-sensitive
* manner or not. By default this returns true and the identifier will
* be evaluated in a case-sensitive manner.
* manner. By default this returns true and the identifier will be
* evaluated in a case-sensitive manner.
*
* @return
* True if the comparisons of this identifier should be case-sensitive,

View File

@@ -0,0 +1,92 @@
/*
* 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.properties;
import org.apache.guacamole.properties.EnumGuacamoleProperty.PropertyValue;
/**
* An enum that supports configuring various user and group case sensitivity
* settings.
*/
public enum CaseSensitivity {
/**
* Case sensitivity enabled for both usernames and group names.
*/
@PropertyValue("enabled")
ENABLED(true, true),
/**
* Case sensitivity enabled for usernames but disabled for group names.
*/
@PropertyValue("usernames")
USERS(true, false),
/**
* Case sensitivity disabled for usernames but enabled for group names.
*/
@PropertyValue("group-names")
GROUPS(false, true),
/**
* Case sensitivity disabled for both usernames and group names.
*/
@PropertyValue("disabled")
DISABLED(false, false);
/**
* Whether or not case sensitivity should be enabled for usernames.
*/
private final boolean usernames;
/**
* Whether or not case sensitivity should be enabled for group names.
*/
private final boolean groupNames;
CaseSensitivity(boolean usernames, boolean groupNames) {
this.usernames = usernames;
this.groupNames = groupNames;
}
/**
* Return "true" if case sensitivity is enabled for usernames, otherwise
* "false".
*
* @return
* "true" if case sensitivity is enabled for usernames, otherwise "false".
*/
public boolean caseSensitiveUsernames() {
return usernames;
}
/**
* Return "true" if case sensitivity is enabled group names, otherwise
* "false".
*
* @return
* "true" if case sensitivity is enabled for group names, otherwise
* "false".
*/
public boolean caseSensitiveGroupNames() {
return groupNames;
}
}