Skip to content

Commit

Permalink
GUACAMOLE-1239: JDBC module should pull case-sensitivity from authent…
Browse files Browse the repository at this point in the history
…cated user when possible.
  • Loading branch information
necouchman committed Oct 28, 2024
1 parent d3da20f commit 240dcd9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,15 @@ public List<ConnectionRecord> retrieveHistory(String identifier,
if (user.isPrivileged() || user.getUser().getEffectivePermissions().getSystemPermissions().hasPermission(SystemPermission.Type.AUDIT))
searchResults = connectionRecordMapper.search(identifier,
recordIdentifier, requiredContents, sortPredicates, limit,
environment.getCaseSensitiveUsernames());
user.isCaseSensitive());

// Otherwise only return explicitly readable history records
else
searchResults = connectionRecordMapper.searchReadable(identifier,
user.getUser().getModel(), recordIdentifier,
requiredContents, sortPredicates, limit,
user.getEffectiveUserGroups(),
environment.getCaseSensitiveUsernames());
user.isCaseSensitive());

return getObjectInstances(searchResults);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ private GuacamoleTunnel assignGuacamoleTunnel(ActiveConnectionRecord activeConne
try {
// This MUST happen before getUUID() is invoked, to ensure the ID driving the UUID exists
connectionRecordMapper.insert(activeConnection.getModel(),
environment.getCaseSensitiveUsernames());
activeConnection.getUser().isCaseSensitive());
activeTunnels.put(activeConnection.getUUID().toString(), activeConnection);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void recordUserLogin() throws GuacamoleException {
userRecord.setRemoteHost(getCurrentUser().getCredentials().getRemoteAddress());

// Insert record representing login
userRecordMapper.insert(userRecord, environment.getCaseSensitiveUsernames());
userRecordMapper.insert(userRecord, getCurrentUser().isCaseSensitive());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ public class UserService extends ModeledDirectoryObjectService<ModeledUser, User
*/
@Inject
private PasswordPolicyService passwordPolicyService;

/**
* The server environment for retrieving configuration.
*/
@Inject
private JDBCEnvironment environment;

@Override
protected ModeledDirectoryObjectMapper<UserModel> getObjectMapper() {
return userMapper;
Expand Down Expand Up @@ -254,7 +254,7 @@ protected void beforeCreate(ModeledAuthenticatedUser user, User object,

// Do not create duplicate users
Collection<UserModel> existing = userMapper.select(Collections.singleton(
model.getIdentifier()), environment.getCaseSensitiveUsernames());
model.getIdentifier()), user.isCaseSensitive());
if (!existing.isEmpty())
throw new GuacamoleClientException("User \"" + model.getIdentifier() + "\" already exists.");

Expand Down Expand Up @@ -291,7 +291,7 @@ protected void beforeUpdate(ModeledAuthenticatedUser user,

// Check whether such a user is already present
UserModel existing = userMapper.selectOne(model.getIdentifier(),
environment.getCaseSensitiveUsernames());
user.isCaseSensitive());
if (existing != null) {

// Do not rename to existing user
Expand Down Expand Up @@ -359,7 +359,7 @@ public void deleteObject(ModeledAuthenticatedUser user, String identifier)
beforeDelete(user, identifier);

// Delete object
userMapper.delete(identifier, environment.getCaseSensitiveUsernames());
userMapper.delete(identifier, user.isCaseSensitive());

}

Expand Down Expand Up @@ -401,7 +401,7 @@ public ModeledAuthenticatedUser retrieveAuthenticatedUser(AuthenticationProvider

// Retrieve corresponding user model, if such a user exists
UserModel userModel = userMapper.selectOne(username,
environment.getCaseSensitiveUsernames());
getCaseSensitiveIdentifiers());
if (userModel == null)
return null;

Expand Down Expand Up @@ -443,7 +443,7 @@ public ModeledUser retrieveUser(AuthenticationProvider authenticationProvider,

// Retrieve corresponding user model, if such a user exists
UserModel userModel = userMapper.selectOne(authenticatedUser.getIdentifier(),
environment.getCaseSensitiveUsernames());
authenticatedUser.isCaseSensitive());
if (userModel == null)
return null;

Expand Down Expand Up @@ -642,15 +642,15 @@ public List<ActivityRecord> retrieveHistory(String username,
if (user.isPrivileged() || user.getUser().getEffectivePermissions().getSystemPermissions().hasPermission(SystemPermission.Type.AUDIT))
searchResults = userRecordMapper.search(username, recordIdentifier,
requiredContents, sortPredicates, limit,
environment.getCaseSensitiveUsernames());
user.isCaseSensitive());

// Otherwise only return explicitly readable history records
else
searchResults = userRecordMapper.searchReadable(username,
user.getUser().getModel(), recordIdentifier,
requiredContents, sortPredicates, limit,
user.getEffectiveUserGroups(),
environment.getCaseSensitiveUsernames());
user.isCaseSensitive());

return getObjectInstances(searchResults);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,10 @@ public class UserGroupMemberUserSet extends RelatedObjectSet<ModeledUserGroup, U
*/
@Inject
private UserGroupMemberUserMapper userGroupMemberUserMapper;

/**
* The server environment for retrieving configuration information.
*/
@Inject
private JDBCEnvironment environment;

@Override
protected boolean getCaseSensitiveIdentifiers() throws GuacamoleException {
return environment.getCaseSensitiveUsernames();
return getCurrentUser().isCaseSensitive();
}

@Override
Expand Down

0 comments on commit 240dcd9

Please sign in to comment.