GUACAMOLE-1239: Make identifier comparison case-insensitive.

This commit is contained in:
Virtually Nick
2023-07-18 17:26:40 -04:00
parent 073d1d476e
commit 4d5101574a
43 changed files with 853 additions and 12 deletions

View File

@@ -113,5 +113,10 @@ public class DelegatingEnvironment implements Environment {
public void addGuacamoleProperties(GuacamoleProperties properties) throws GuacamoleException {
environment.addGuacamoleProperties(properties);
}
@Override
public boolean getCaseSensitiveUsernames() throws GuacamoleException {
return environment.getCaseSensitiveUsernames();
}
}

View File

@@ -69,6 +69,18 @@ public interface Environment {
public String getName() { return "guacd-ssl"; }
};
/**
* A property that configures whether or not Guacamole will take case
* into account when comparing and processing usernames.
*/
public static final BooleanGuacamoleProperty CASE_SENSITIVE_USERNAMES =
new BooleanGuacamoleProperty() {
@Override
public String getName() { return "case-sensitive-usernames"; }
};
/**
* Returns the Guacamole home directory as determined when this Environment
@@ -367,5 +379,23 @@ public interface Environment {
+ "support dynamic definition of Guacamole properties.",
getClass()));
}
/**
* 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.
*
* @return
* true if Guacamole should consider usernames case-sensitive, otherwise
* false.
*
* @throws GuacamoleException
* If guacamole.properties cannot be parsed.
*/
public default boolean getCaseSensitiveUsernames() throws GuacamoleException {
return getProperty(CASE_SENSITIVE_USERNAMES, true);
}
}

View File

@@ -19,7 +19,6 @@
package org.apache.guacamole.net.auth;
/**
* Abstract implementation of Identifiable which provides equals() and
* hashCode() implementations which use the identifier to determine equality.
@@ -34,12 +33,18 @@ public abstract class AbstractIdentifiable implements Identifiable {
@Override
public String getIdentifier() {
return identifier;
if (identifier == null || isCaseSensitive())
return identifier;
return identifier.toLowerCase();
}
@Override
public void setIdentifier(String identifier) {
this.identifier = identifier;
if (isCaseSensitive() || identifier == null)
this.identifier = identifier;
else
this.identifier = identifier.toLowerCase();
}
@Override
@@ -48,7 +53,10 @@ public abstract class AbstractIdentifiable implements Identifiable {
if (identifier == null)
return 0;
return identifier.hashCode();
if (isCaseSensitive())
return identifier.hashCode();
return identifier.toLowerCase().hashCode();
}
@Override
@@ -65,8 +73,12 @@ public abstract class AbstractIdentifiable implements Identifiable {
if (otherIdentifier == null)
return identifier == null;
// Otherwise, equal only if strings are identical
return otherIdentifier.equals(identifier);
// If this identifier is case-sensitive, evaluate with case-sensitivity.
if (isCaseSensitive())
return otherIdentifier.equals(identifier);
// The identifier should not be evaluated in a case-sensitive manner.
return otherIdentifier.equalsIgnoreCase(identifier);
}

View File

@@ -49,6 +49,14 @@ public abstract class AbstractUser extends AbstractIdentifiable
public void setPassword(String password) {
this.password = password;
}
@Override
public boolean isCaseSensitive() {
// In order to avoid causing incompatibility with other extensions,
// this class maintains case-sensitive comparisons.
return true;
}
/**
* {@inheritDoc}

View File

@@ -43,5 +43,18 @@ public interface Identifiable {
* The identifier to assign.
*/
public void setIdentifier(String identifier);
/**
* 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.
*
* @return
* True if the comparisons of this identifier should be case-sensitive,
* otherwise false.
*/
default public boolean isCaseSensitive() {
return true;
}
}