Skip to content
Snippets Groups Projects

update: make LDAP search happen before accounts lookup, not in parallel

Closed Martin Lowe requested to merge malowe/main/122 into main
1 unresolved thread
4 files
+ 20
12
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -117,21 +117,23 @@ public class DefaultProfileService implements ProfileService {
@@ -117,21 +117,23 @@ public class DefaultProfileService implements ProfileService {
@Override
@Override
public EfUser getProfileByUsername(String username) {
public EfUser getProfileByUsername(String username) {
try {
try {
// Search in LDAP and accounts asynchronously
// Search in LDAP first and then accounts
CompletableFuture<Optional<LdapResult>> ldapSearch = executor.supplyAsync(() -> ldapService.searchLdapByUsername(username));
Optional<LdapResult> ldapSearch = ldapService.searchLdapByUsername(username);
CompletableFuture<Optional<AccountsProfileData>> accountsSearch = executor
// ldap is really reliable, if it has no results, then its incredibly likely there is no user
.supplyAsync(() -> profileHelper.getAccountsProfileByUsername(username));
if (ldapSearch.isEmpty()) {
return null;
Optional<LdapResult> ldapResult = ldapSearch.get();
}
Optional<AccountsProfileData> accountsResult = accountsSearch.get();
 
// retrieve accounts results for the given username
 
Optional<AccountsProfileData> accountsSearch = profileHelper.getAccountsProfileByUsername(username);
// #114 - If results are asymmetrical, throw an exception
// #114 - If results are asymmetrical, throw an exception
if (ldapResult.isPresent() ^ accountsResult.isPresent()) {
if (accountsSearch.isEmpty()) {
throw new ApplicationException(
throw new ApplicationException(
String.format("Results from services are inconsistent regarding user, cannot return: %s", username));
String.format("Results from services are inconsistent regarding user, cannot return: %s", username));
}
}
// if either result is empty, both are empty with above bitwise check
// if either result is empty, both are empty with above bitwise check
return ldapResult.isEmpty() ? null : buildEfUser(ldapResult.get(), accountsResult.get());
return buildEfUser(ldapSearch.get(), accountsSearch.get());
} catch (Exception e) {
} catch (Exception e) {
if (e.getClass().equals(InterruptedException.class)) {
if (e.getClass().equals(InterruptedException.class)) {
// only interrupt on interrupts
// only interrupt on interrupts
Loading