Skip to content

Commit 580f710

Browse files
committed
GUACAMOLE-1239: Make identifier comparison case-insensitive.
1 parent 6710b31 commit 580f710

22 files changed

Lines changed: 295 additions & 9 deletions

File tree

extensions/guacamole-auth-header/src/main/java/org/apache/guacamole/auth/header/ConfigurationService.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,25 @@ public String getHttpAuthHeader() throws GuacamoleException {
5353
"REMOTE_USER"
5454
);
5555
}
56+
57+
/**
58+
* Returns true if the username provided to the header authentication
59+
* module should be treated as case-sensitive, or false if the username
60+
* provided should be treated as case-insensitive. The default is false,
61+
* the username will be case-insensitive.
62+
*
63+
* @return
64+
* True if the username should be treated as case-sensitive, otherwise
65+
* false.
66+
*
67+
* @throws GuacamoleException
68+
* If guacamole.properties cannot be parsed.
69+
*/
70+
public boolean getCaseSensitiveUsernames() throws GuacamoleException {
71+
return environment.getProperty(
72+
HTTPHeaderGuacamoleProperties.HTTP_AUTH_CASE_SENSITIVE_USERNAMES,
73+
false
74+
);
75+
}
5676

5777
}

extensions/guacamole-auth-header/src/main/java/org/apache/guacamole/auth/header/HTTPHeaderGuacamoleProperties.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
package org.apache.guacamole.auth.header;
2121

22-
import org.apache.guacamole.properties.IntegerGuacamoleProperty;
22+
import org.apache.guacamole.properties.BooleanGuacamoleProperty;
2323
import org.apache.guacamole.properties.StringGuacamoleProperty;
2424

2525

@@ -36,13 +36,26 @@ public class HTTPHeaderGuacamoleProperties {
3636
private HTTPHeaderGuacamoleProperties() {}
3737

3838
/**
39-
* The header used for HTTP header authentication.
39+
* A property used to configure the header used for HTTP header authentication.
4040
*/
4141
public static final StringGuacamoleProperty HTTP_AUTH_HEADER = new StringGuacamoleProperty() {
4242

4343
@Override
4444
public String getName() { return "http-auth-header"; }
4545

4646
};
47+
48+
/**
49+
* A property used to configure whether or not the username provided by the
50+
* header module should be treated as case-sensitive. By default usernames
51+
* will not be case-sensitive.
52+
*/
53+
public static final BooleanGuacamoleProperty HTTP_AUTH_CASE_SENSITIVE_USERNAMES =
54+
new BooleanGuacamoleProperty() {
55+
56+
@Override
57+
public String getName() { return "http-auth-case-sensitive-usernames"; }
58+
59+
};
4760

4861
}

extensions/guacamole-auth-header/src/main/java/org/apache/guacamole/auth/header/user/AuthenticatedUser.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.apache.guacamole.auth.header.user;
2121

2222
import com.google.inject.Inject;
23+
import org.apache.guacamole.GuacamoleException;
24+
import org.apache.guacamole.auth.header.ConfigurationService;
2325
import org.apache.guacamole.net.auth.AbstractAuthenticatedUser;
2426
import org.apache.guacamole.net.auth.AuthenticationProvider;
2527
import org.apache.guacamole.net.auth.Credentials;
@@ -37,6 +39,12 @@ public class AuthenticatedUser extends AbstractAuthenticatedUser {
3739
*/
3840
@Inject
3941
private AuthenticationProvider authProvider;
42+
43+
/**
44+
* Service for retrieving header configuration information.
45+
*/
46+
@Inject
47+
private ConfigurationService confService;
4048

4149
/**
4250
* The credentials provided when this user was authenticated.
@@ -58,6 +66,16 @@ public void init(String username, Credentials credentials) {
5866
setIdentifier(username.toLowerCase());
5967
}
6068

69+
@Override
70+
public boolean isCaseSensitive() {
71+
try {
72+
return confService.getCaseSensitiveUsernames();
73+
}
74+
catch (GuacamoleException e) {
75+
return false;
76+
}
77+
}
78+
6179
@Override
6280
public AuthenticationProvider getAuthenticationProvider() {
6381
return authProvider;

extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,5 +271,18 @@ public boolean shouldUseBatchExecutor() {
271271
return true;
272272

273273
}
274+
275+
/**
276+
* Returns a boolean value that indicates whether or not usernames should
277+
* be treated as case-sensitive.
278+
*
279+
* @return
280+
* true if usernames should be treated as case-sensitive, or false if
281+
* usernames should be treated as case-insensitive.
282+
*
283+
* @throws GuacamoleException
284+
* If guacamole.properties cannot be parsed.
285+
*/
286+
public abstract boolean getCaseSensitiveUsernames() throws GuacamoleException;
274287

275288
}

extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledAuthenticatedUser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,10 @@ public Set<String> getEffectiveUserGroups() {
194194
public boolean isPrivileged() throws GuacamoleException {
195195
return getUser().isPrivileged();
196196
}
197+
198+
@Override
199+
public boolean isCaseSensitive() {
200+
return user.isCaseSensitive();
201+
}
197202

198203
}

extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledUser.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.guacamole.auth.jdbc.security.PasswordEncryptionService;
3737
import org.apache.guacamole.auth.jdbc.security.SaltService;
3838
import org.apache.guacamole.GuacamoleException;
39+
import org.apache.guacamole.auth.jdbc.JDBCEnvironment;
3940
import org.apache.guacamole.auth.jdbc.base.ModeledPermissions;
4041
import org.apache.guacamole.form.BooleanField;
4142
import org.apache.guacamole.form.DateField;
@@ -188,6 +189,13 @@ public class ModeledUser extends ModeledPermissions<UserModel> implements User {
188189
*/
189190
@Inject
190191
private Provider<UserRecordSet> userRecordSetProvider;
192+
193+
/**
194+
* The environment associated with this instance of the JDBC authentication
195+
* module.
196+
*/
197+
@Inject
198+
private JDBCEnvironment environment;
191199

192200
/**
193201
* Whether attributes which control access restrictions should be exposed
@@ -798,5 +806,15 @@ public Permissions getEffectivePermissions() throws GuacamoleException {
798806
public boolean isSkeleton() {
799807
return (getModel().getEntityID() == null);
800808
}
809+
810+
@Override
811+
public boolean isCaseSensitive() {
812+
try {
813+
return environment.getCaseSensitiveUsernames();
814+
}
815+
catch (GuacamoleException e) {
816+
return true;
817+
}
818+
}
801819

802820
}

extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/conf/MySQLEnvironment.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,18 @@ public boolean enforceAccessWindowsForActiveSessions() throws GuacamoleException
439439
// Enforce access window restrictions for active sessions unless explicitly disabled
440440
return getProperty(
441441
MySQLGuacamoleProperties.MYSQL_ENFORCE_ACCESS_WINDOWS_FOR_ACTIVE_SESSIONS,
442-
true);
442+
true
443+
);
444+
}
445+
446+
@Override
447+
public boolean getCaseSensitiveUsernames() throws GuacamoleException {
448+
449+
return getProperty(
450+
MySQLGuacamoleProperties.MYSQL_CASE_SENSITIVE_USERNAMES,
451+
false
452+
);
453+
443454
}
444455

445456
}

extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/conf/MySQLGuacamoleProperties.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ private MySQLGuacamoleProperties() {}
301301
@Override
302302
public String getName() { return "mysql-batch-size"; }
303303

304-
};
304+
};
305+
306+
public static final BooleanGuacamoleProperty MYSQL_CASE_SENSITIVE_USERNAMES =
307+
new BooleanGuacamoleProperty() {
308+
309+
@Override
310+
public String getName() { return "mysql-case-sensitive-usernames"; }
311+
312+
};
305313

306314
}

extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLEnvironment.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,5 +398,17 @@ public boolean enforceAccessWindowsForActiveSessions() throws GuacamoleException
398398
PostgreSQLGuacamoleProperties.POSTGRESQL_ENFORCE_ACCESS_WINDOWS_FOR_ACTIVE_SESSIONS,
399399
true);
400400
}
401+
402+
@Override
403+
public boolean getCaseSensitiveUsernames() throws GuacamoleException {
404+
405+
// By default, PostgreSQL does use case-sensitive string searches, so
406+
// we will honor case-sensitive usernames.
407+
return getProperty(
408+
PostgreSQLGuacamoleProperties.POSTGRESQL_CASE_SENSITIVE_USERNAMES,
409+
true
410+
);
411+
412+
}
401413

402414
}

extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLGuacamoleProperties.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,5 +314,17 @@ private PostgreSQLGuacamoleProperties() {}
314314
public String getName() { return "postgresql-batch-size"; }
315315

316316
};
317+
318+
/**
319+
* A property that configures whether or not usernames should be treated as
320+
* case-sensitive with the Postgres JDBC backend.
321+
*/
322+
public static final BooleanGuacamoleProperty POSTGRESQL_CASE_SENSITIVE_USERNAMES =
323+
new BooleanGuacamoleProperty() {
324+
325+
@Override
326+
public String getName() { return "postgresql-case-sensitive-usernames"; }
327+
328+
};
317329

318330
}

0 commit comments

Comments
 (0)