GUACAMOLE-1661: Parse config only once when iterating records.

This commit is contained in:
James Muehlner
2022-08-25 00:03:18 +00:00
parent 2b997a9992
commit c7bb1cb50c

View File

@@ -277,13 +277,13 @@ public class KsmClient {
cachedAmbiguousDomains.clear(); cachedAmbiguousDomains.clear();
cachedRecordsByDomain.clear(); cachedRecordsByDomain.clear();
// Parse configuration
final boolean shouldSplitUsernames = confService.getSplitWindowsUsernames();
final boolean shouldMatchByDomain = confService.getMatchUserRecordsByDomain();
// Store all records, sorting each into host-based, login-based, // Store all records, sorting each into host-based, login-based,
// and domain-based buckets // and domain-based buckets
Iterator<KeeperRecord> recordIterator = records.iterator(); records.forEach(record -> {
while(recordIterator.hasNext()) {
// Go through records one at a time
KeeperRecord record = recordIterator.next();
// Store based on UID ... // Store based on UID ...
cachedRecordsByUid.put(record.getRecordUid(), record); cachedRecordsByUid.put(record.getRecordUid(), record);
@@ -300,8 +300,7 @@ public class KsmClient {
String username = recordService.getUsername(record); String username = recordService.getUsername(record);
// If we have a username, and there isn't already a domain explicitly defined // If we have a username, and there isn't already a domain explicitly defined
if (username != null && domain == null if (username != null && domain == null && shouldSplitUsernames) {
&& confService.getSplitWindowsUsernames()) {
// Attempt to split out the domain of the username // Attempt to split out the domain of the username
WindowsUsername usernameAndDomain = ( WindowsUsername usernameAndDomain = (
@@ -319,7 +318,7 @@ public class KsmClient {
// If domain matching is not enabled for user records, // If domain matching is not enabled for user records,
// explicitly set all domains to null to allow matching // explicitly set all domains to null to allow matching
// on username only // on username only
if (!confService.getMatchUserRecordsByDomain()) if (!shouldMatchByDomain)
domain = null; domain = null;
// Store based on login ONLY if no hostname (will otherwise // Store based on login ONLY if no hostname (will otherwise
@@ -328,7 +327,7 @@ public class KsmClient {
if (hostname == null) if (hostname == null)
addRecordForLogin(record, username, domain); addRecordForLogin(record, username, domain);
} });
// Cache has been refreshed // Cache has been refreshed
this.cacheTimestamp = System.currentTimeMillis(); this.cacheTimestamp = System.currentTimeMillis();