user store role mapping feature

pull/266/head
Amalka Subasinghe 1 year ago
parent 53c48d87ca
commit 3d159c0111

@ -75,38 +75,40 @@ public class UserStoreRoleMapper implements ServerStartupObserver {
.getTenantUserRealm(MultitenantConstants.SUPER_TENANT_ID).getUserStoreManager(); .getTenantUserRealm(MultitenantConstants.SUPER_TENANT_ID).getUserStoreManager();
for (RoleMapping mapping : roleMappings) { for (RoleMapping mapping : roleMappings) {
String[] users = userStoreManager.getUserListOfRole(mapping.getSecondaryRole()); if (userStoreManager.isExistingRole(mapping.getSecondaryRole())) {
if (users != null && users.length > 0) { String[] users = userStoreManager.getUserListOfRole(mapping.getSecondaryRole());
List<String> primaryRoles = mapping.getInternalRoles(); if (users != null && users.length > 0) {
for (String role : primaryRoles) { List<String> primaryRoles = mapping.getInternalRoles();
if (userStoreManager.isExistingRole(role)) { for (String role : primaryRoles) {
String[] existingUsers = userStoreManager.getUserListOfRole(role); if (userStoreManager.isExistingRole(role)) {
List<String> existingUserList = new ArrayList<>(Arrays.asList(existingUsers)); String[] existingUsers = userStoreManager.getUserListOfRole(role);
List<String> newUserList = new ArrayList<>(); List<String> existingUserList = new ArrayList<>(Arrays.asList(existingUsers));
for (String user: users) { List<String> newUserList = new ArrayList<>();
if (existingUserList.contains(user)) { for (String user : users) {
// if contains, remove from existing list if (existingUserList.contains(user)) {
existingUserList.remove(user); // if contains, remove from existing list
} else { existingUserList.remove(user);
// new user } else {
newUserList.add(user); // new user
newUserList.add(user);
}
} }
}
List<String> deleteUserList = new ArrayList<>(); List<String> deleteUserList = new ArrayList<>();
if (!existingUserList.isEmpty()) { if (!existingUserList.isEmpty()) {
String domain = mapping.getSecondaryRole().substring(0,mapping.getSecondaryRole().indexOf("/")); String domain = mapping.getSecondaryRole().substring(0, mapping.getSecondaryRole().indexOf("/"));
for (String user : existingUserList) { for (String user : existingUserList) {
if (user.startsWith(domain.toUpperCase())) { if (user.startsWith(domain.toUpperCase())) {
deleteUserList.add(user); deleteUserList.add(user);
}
} }
} }
}
// update user list of given role // update user list of given role
if (!newUserList.isEmpty() || !deleteUserList.isEmpty()) { if (!newUserList.isEmpty() || !deleteUserList.isEmpty()) {
userStoreManager.updateUserListOfRole(role, deleteUserList.toArray(new String[0]), newUserList.toArray(new String[0])); userStoreManager.updateUserListOfRole(role, deleteUserList.toArray(new String[0]), newUserList.toArray(new String[0]));
log.info("update user role mapping executed....."); log.info("update user role mapping executed.....");
}
} }
} }
} }

Loading…
Cancel
Save