fixed initialization of AccessControlStore internal structures after initial load;

the userToOwnership and userGroupToOwnership structures weren't
correctly filled because of a missing call to
internalSetOwnershipAndMapUserAndUserGroupToOwnership for cleanly
updating the internal structures. This caused problems when deleting
users or groups in replication scenarios.

Change-Id: I656090242d40e9792a46835440eaf6865f3434a7
This commit is contained in:
Axel Uhl
2019-06-27 00:24:29 +02:00
parent 2d47fca207
commit 82786a38ae
2 changed files with 12 additions and 9 deletions
@@ -89,7 +89,6 @@ public class AccessControlStoreImpl implements AccessControlStore {
@Override
public void loadACLsAndOwnerships() {
LockUtil.executeWithWriteLock(lockForManagementMappings, new Runnable() {
@Override
public void run() {
if (domainObjectFactory != null) {
@@ -97,7 +96,7 @@ public class AccessControlStoreImpl implements AccessControlStore {
internalAddACL(acl);
}
for (OwnershipAnnotation ownership : domainObjectFactory.loadAllOwnerships(userStore)) {
internalSetOwnershipAndmapUserAndUserGroupToOwnership(ownership);
internalSetOwnershipAndMapUserAndUserGroupToOwnership(ownership);
}
}
}
@@ -294,13 +293,12 @@ public class AccessControlStoreImpl implements AccessControlStore {
final OwnershipAnnotation ownership = new OwnershipAnnotation(new Ownership(userOwnerName, tenantOwner), id,
displayNameOfOwnedObject);
LockUtil.executeWithWriteLock(lockForManagementMappings, new Runnable() {
@Override
public void run() {
// first removing it, prevents the necessity to do a delta update
removeUserAndUserGroupToOwnershipMapping(ownership);
// and add it to the new ownership
internalSetOwnershipAndmapUserAndUserGroupToOwnership(ownership);
internalSetOwnershipAndMapUserAndUserGroupToOwnership(ownership);
}
});
// and that it is finally written
@@ -308,7 +306,7 @@ public class AccessControlStoreImpl implements AccessControlStore {
return ownership;
}
private void internalSetOwnershipAndmapUserAndUserGroupToOwnership(final OwnershipAnnotation ownership) {
private void internalSetOwnershipAndMapUserAndUserGroupToOwnership(final OwnershipAnnotation ownership) {
ownerships.put(ownership.getIdOfAnnotatedObject(), ownership);
UserGroup tenantOwner = ownership.getAnnotation().getTenantOwner();
if (tenantOwner != null) {
@@ -413,7 +411,6 @@ public class AccessControlStoreImpl implements AccessControlStore {
@Override
public void replaceContentsFrom(final AccessControlStore newAccessControlStore) {
LockUtil.executeWithWriteLock(lockForManagementMappings, new Runnable() {
@Override
public void run() {
clear();
@@ -421,7 +418,7 @@ public class AccessControlStoreImpl implements AccessControlStore {
internalAddACL(acl);
}
for (OwnershipAnnotation ownership : newAccessControlStore.getOwnerships()) {
ownerships.put(ownership.getIdOfAnnotatedObject(), ownership);
internalSetOwnershipAndMapUserAndUserGroupToOwnership(ownership);
}
}
});
@@ -1182,7 +1182,7 @@ public class SecurityServiceImpl implements ReplicableSecurityService, ClearStat
store.removeAllQualifiedRolesForUser(userToDelete);
final String defaultTenantNameForUsername = getDefaultTenantNameForUsername(username);
UserGroup defaultTenantUserGroup = getUserGroupByName(defaultTenantNameForUsername);
final UserGroup defaultTenantUserGroup = getUserGroupByName(defaultTenantNameForUsername);
if (defaultTenantUserGroup != null) {
List<User> usersInGroupList = Util.asList(defaultTenantUserGroup.getUsers());
if (usersInGroupList.size() == 1 && usersInGroupList.contains(userToDelete)) {
@@ -1196,7 +1196,9 @@ public class SecurityServiceImpl implements ReplicableSecurityService, ClearStat
}
// also remove from all usergroups
for (UserGroup userGroup : userToDelete.getUserGroups()) {
internalRemoveUserFromUserGroup(userGroup.getId(), userToDelete.getName());
if (userGroup != defaultTenantUserGroup) { // the defaultTenantUserGroup has already been deleted above
internalRemoveUserFromUserGroup(userGroup.getId(), userToDelete.getName());
}
}
store.deleteUser(username);
}
@@ -2024,6 +2026,7 @@ public class SecurityServiceImpl implements ReplicableSecurityService, ClearStat
@Override
public void initiallyFillFromInternal(ObjectInputStream is) throws IOException, ClassNotFoundException,
InterruptedException {
logger.info("Reading cache manager...");
ReplicatingCacheManager newCacheManager = (ReplicatingCacheManager) is.readObject();
cacheManager.replaceContentsFrom(newCacheManager);
// overriding thread context class loader because the user store may be provided by a different bundle;
@@ -2032,6 +2035,7 @@ public class SecurityServiceImpl implements ReplicableSecurityService, ClearStat
if (store != null) {
Thread.currentThread().setContextClassLoader(store.getClass().getClassLoader());
}
logger.info("Reading user store...");
try {
UserStore newUserStore = (UserStore) is.readObject();
store.replaceContentsFrom(newUserStore);
@@ -2041,12 +2045,14 @@ public class SecurityServiceImpl implements ReplicableSecurityService, ClearStat
if (accessControlStore != null) {
Thread.currentThread().setContextClassLoader(accessControlStore.getClass().getClassLoader());
}
logger.info("Reading access control store...");
try {
AccessControlStore newAccessControlStore = (AccessControlStore) is.readObject();
accessControlStore.replaceContentsFrom(newAccessControlStore);
} finally {
Thread.currentThread().setContextClassLoader(oldCCL);
}
logger.info("Done filling SecurityService");
}
@Override