Index records by username ONLY if not related to a hostname.
Doing otherwise would mean that a particular user would never be able
to be associated with a specific password/key by their username if they
have any explicit server-specific account.
@@ -238,10 +238,14 @@ public class KsmClient {
// Store based on UID ...
cachedRecordsByUid.put(record.getRecordUid(), record);
- // ... and hostname/address ...
- addRecordForHost(record, recordService.getHostname(record));
+ // ... and hostname/address
+ String hostname = recordService.getHostname(record);
+ addRecordForHost(record, hostname);
- // ... and username
+ // Store based on username ONLY if no hostname (will otherwise
+ // result in ambiguous entries for servers tied to identical
+ // accounts)
+ if (hostname == null)
addRecordForLogin(record, recordService.getUsername(record));
});
