Skip to content
Snippets Groups Projects
Commit f037a08d authored by Philippe Larose's avatar Philippe Larose
Browse files

ad/ldap-connector: prevent revocation if AD/LDAP is down

Ticket: https://redmine.savoirfairelinux.com/issues/7656
Change-Id: Ibd79d6db688ec4662aa756d82051cd03a3493127
parent 484b43dc
No related branches found
No related tags found
No related merge requests found
......@@ -200,19 +200,23 @@ public class UserProfileService {
public void synchronizeUsersWithAD() {
log.info("Synchronizing Active Directory user profiles");
// Fetch all users from the Active Directory
List<UserProfile> profilesFromResponse =
List<UserProfile> profilesFromAD =
getUserProfile("*", "LOGON_NAME", false, Optional.empty());
// There is a use case where a user is not in the LDAP directory but is in the database.
// When this happens, we need to revoke the user from the database.
List<UserProfile> profilesFromDatabase = dataStore.getUserProfileDao().getAllUserProfile();
for (UserProfile p : profilesFromDatabase) {
if (profilesFromResponse.stream()
.noneMatch(r -> r.getUsername().equals(p.getUsername()))) {
log.info("Revoking user " + p.getUsername() + " from the database.");
RevokeUserFlow.revokeUser(p.getUsername());
// We also remove the user from the local_directory table to avoid duplicate
// revocations
dataStore.getUserProfileDao().deleteUserProfile(p.getUsername());
// Do not revoke users if there is an error, the AD server could be down.
if (profilesFromAD != null) {
// There is a use case where a user is not in the AD server but is in the database.
// When this happens, we need to revoke the user from the database.
List<UserProfile> profilesFromDatabase =
dataStore.getUserProfileDao().getAllUserProfile();
for (UserProfile p : profilesFromDatabase) {
if (profilesFromAD.stream()
.noneMatch(r -> r.getUsername().equals(p.getUsername()))) {
log.info("Revoking user " + p.getUsername() + " from the database.");
RevokeUserFlow.revokeUser(p.getUsername());
// We also remove the user from the local_directory table to avoid duplicate
// revocations
dataStore.getUserProfileDao().deleteUserProfile(p.getUsername());
}
}
}
}
......
......@@ -152,16 +152,21 @@ public class UserProfileService {
// Fetcg all users from the LDAP
List<UserProfile> profilesFromLDAP =
getUserProfile("*", "LOGON_NAME", false, Optional.empty());
// There is a use case where a user is not in the LDAP directory but is in the database.
// When this happens, we need to revoke the user from the database.
List<UserProfile> profilesFromDatabase = dataStore.getUserProfileDao().getAllUserProfile();
for (UserProfile p : profilesFromDatabase) {
if (profilesFromLDAP.stream().noneMatch(r -> r.getUsername().equals(p.getUsername()))) {
log.info("Revoking user " + p.getUsername() + " from the database.");
RevokeUserFlow.revokeUser(p.getUsername());
// We also remove the user from the local_directory table to avoid duplicate
// revocations
dataStore.getUserProfileDao().deleteUserProfile(p.getUsername());
// Do not revoke users if there is an error, the LDAP server could be down.
if (profilesFromLDAP != null) {
// There is a use case where a user is not in the LDAP server but is in the database.
// When this happens, we need to revoke the user from the database.
List<UserProfile> profilesFromDatabase =
dataStore.getUserProfileDao().getAllUserProfile();
for (UserProfile p : profilesFromDatabase) {
if (profilesFromLDAP.stream()
.noneMatch(r -> r.getUsername().equals(p.getUsername()))) {
log.info("Revoking user " + p.getUsername() + " from the database.");
RevokeUserFlow.revokeUser(p.getUsername());
// We also remove the user from the local_directory table to avoid duplicate
// revocations
dataStore.getUserProfileDao().deleteUserProfile(p.getUsername());
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment