mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-1239: Add case-sensitivity configuration for UserGroup objects and remove per-extension configuration.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -55,14 +55,14 @@ public abstract class AbstractAuthenticatedUser extends AbstractIdentifiable
|
||||
@Override
|
||||
public boolean isCaseSensitive() {
|
||||
try {
|
||||
return environment.getCaseSensitiveUsernames();
|
||||
return environment.getCaseSensitivity().caseSensitiveUsernames();
|
||||
}
|
||||
catch (GuacamoleException e) {
|
||||
LOGGER.warn("Exception attempting to read the Guacamole configuration, "
|
||||
+ "usernames will be treated as case-sensitive.", e.getMessage());
|
||||
LOGGER.debug("Received GuacamoleException attempting to retrieve the "
|
||||
+ "case-sensitivity setting for usernames. Defaulting to"
|
||||
+ "case-sensitive usernames.", 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;
|
||||
}
|
||||
}
|
||||
|
@@ -73,8 +73,8 @@ public abstract class AbstractIdentifiable implements Identifiable {
|
||||
if (otherIdentifier == null)
|
||||
return identifier == null;
|
||||
|
||||
// If either this identifier or the one we're comparing to is
|
||||
// case-sensitive, evaluate with case-sensitivity.
|
||||
// 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);
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user