Skip to content

Commit de0d750

Browse files
committed
GUACAMOLE-1293: Make identifier comparison case-insensitive.
1 parent 6710b31 commit de0d750

File tree

22 files changed

+295
-9
lines changed

22 files changed

+295
-9
lines changed

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

+20
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

+15-2
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

+18
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

+13
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

+5
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

+18
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

+12-1
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

+9-1
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

+12
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

+12
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
}

extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/conf/SQLServerEnvironment.java

+12
Original file line numberDiff line numberDiff line change
@@ -328,5 +328,17 @@ public boolean trustAllServerCertificates() throws GuacamoleException {
328328
SQLServerGuacamoleProperties.SQLSERVER_TRUST_ALL_SERVER_CERTIFICATES,
329329
false);
330330
}
331+
332+
@Override
333+
public boolean getCaseSensitiveUsernames() throws GuacamoleException {
334+
335+
// SQL Server uses case-insensitive string searches by default, so
336+
// we do not enforce case-sensitivity unless otherwise configured.
337+
return getProperty(
338+
SQLServerGuacamoleProperties.SQLSERVER_CASE_SENSITIVE_USERNAMES,
339+
false
340+
);
341+
342+
}
331343

332344
}

extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/conf/SQLServerGuacamoleProperties.java

+8
Original file line numberDiff line numberDiff line change
@@ -257,5 +257,13 @@ private SQLServerGuacamoleProperties() {}
257257
public String getName() { return "sqlserver-trust-all-server-certificates"; }
258258

259259
};
260+
261+
public static final BooleanGuacamoleProperty SQLSERVER_CASE_SENSITIVE_USERNAMES =
262+
new BooleanGuacamoleProperty() {
263+
264+
@Override
265+
public String getName() { return "sqlserver-case-sensitive-usernames" ; }
266+
267+
};
260268

261269
}

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

+32
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Collections;
2525
import org.apache.guacamole.GuacamoleException;
2626
import org.apache.guacamole.environment.Environment;
27+
import org.apache.guacamole.properties.BooleanGuacamoleProperty;
2728
import org.apache.guacamole.properties.ByteArrayProperty;
2829
import org.apache.guacamole.properties.StringListProperty;
2930

@@ -39,6 +40,20 @@ public class ConfigurationService {
3940
@Inject
4041
private Environment environment;
4142

43+
/**
44+
* Whether or not usernames of users associated with the JSON module should
45+
* be treated as case-sensitive.
46+
*/
47+
private static final BooleanGuacamoleProperty JSON_CASE_SENSITIVE_USERNAMES =
48+
new BooleanGuacamoleProperty() {
49+
50+
@Override
51+
public String getName() {
52+
return "json-case-sensitive-usernames";
53+
}
54+
55+
};
56+
4257
/**
4358
* The encryption key to use for all decryption and signature verification.
4459
*/
@@ -64,6 +79,23 @@ public String getName() {
6479
}
6580

6681
};
82+
83+
/**
84+
* Returns true if the usernames of users authenticated by the JSON module
85+
* should be treated as case-sensitive, or false if the usernames should
86+
* be treated as case-insensitive. The default is false, usernames will
87+
* be treated as case-insensitive.
88+
*
89+
* @return
90+
* True if the usernames of users authenticated by this module should
91+
* be treated as case-sensitive, otherwise false.
92+
*
93+
* @throws GuacamoleException
94+
* If guacamole.properties cannot be parsed.
95+
*/
96+
public boolean getCaseSensitiveUsernames() throws GuacamoleException {
97+
return environment.getProperty(JSON_CASE_SENSITIVE_USERNAMES, false);
98+
}
6799

68100
/**
69101
* Returns the symmetric key which will be used to encrypt and sign all

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

+19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.apache.guacamole.auth.json.user;
2121

2222
import com.google.inject.Inject;
23+
import org.apache.guacamole.GuacamoleException;
24+
import org.apache.guacamole.auth.json.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,13 @@ public class AuthenticatedUser extends AbstractAuthenticatedUser {
3739
*/
3840
@Inject
3941
private AuthenticationProvider authProvider;
42+
43+
/**
44+
* Reference to the configuration service associated with this
45+
* authentication provider.
46+
*/
47+
@Inject
48+
private ConfigurationService confService;
4049

4150
/**
4251
* The credentials provided when this user was authenticated.
@@ -66,6 +75,16 @@ public void init(Credentials credentials, UserData userData) {
6675
this.userData = userData;
6776
setIdentifier(userData.getUsername());
6877
}
78+
79+
@Override
80+
public boolean isCaseSensitive() {
81+
try {
82+
return confService.getCaseSensitiveUsernames();
83+
}
84+
catch (GuacamoleException e) {
85+
return false;
86+
}
87+
}
6988

7089
@Override
7190
public AuthenticationProvider getAuthenticationProvider() {

extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/user/LDAPAuthenticatedUser.java

+6
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ public ConnectedLDAPConfiguration getLDAPConfiguration() {
135135
return config;
136136
}
137137

138+
@Override
139+
public boolean isCaseSensitive() {
140+
// LDAP authentication is almost universally case-insensitive
141+
return false;
142+
}
143+
138144
@Override
139145
public AuthenticationProvider getAuthenticationProvider() {
140146
return authProvider;

0 commit comments

Comments
 (0)