Fix realm removal when orgs are enabled

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
This commit is contained in:
Stefan Guilhen 2024-05-10 12:15:14 -03:00 committed by Pedro Igor
parent f0620353a4
commit 3186b6db8e

View file

@ -107,13 +107,14 @@ public class JpaOrganizationProvider implements OrganizationProvider {
@Override
public boolean remove(OrganizationModel organization) {
OrganizationEntity entity = getEntity(organization.getId());
GroupModel group = getOrganizationGroup(entity);
GroupModel group = getOrganizationGroup(organization);
if (group != null) {
//TODO: won't scale, requires a better mechanism for bulk deleting users
userProvider.getGroupMembersStream(realm, group).forEach(userModel -> removeMember(organization, userModel));
groupProvider.removeGroup(realm, group);
organization.getIdentityProviders().forEach((model) -> removeIdentityProvider(organization, model));
}
em.remove(entity);
@ -132,7 +133,7 @@ public class JpaOrganizationProvider implements OrganizationProvider {
throwExceptionIfObjectIsNull(user, "User");
OrganizationEntity entity = getEntity(organization.getId());
GroupModel group = groupProvider.getGroupById(realm, entity.getGroupId());
GroupModel group = getOrganizationGroup(entity);
if (user.isMemberOf(group)) {
return false;
@ -384,8 +385,7 @@ public class JpaOrganizationProvider implements OrganizationProvider {
private GroupModel getOrganizationGroup(OrganizationModel organization) {
throwExceptionIfObjectIsNull(organization, "Organization");
OrganizationEntity entity = getEntity(organization.getId());
GroupModel group = groupProvider.getGroupById(realm, entity.getGroupId());
GroupModel group = getOrganizationGroup(entity);
if (group == null) {
throw new ModelException("Organization group " + entity.getGroupId() + " not found");
@ -394,6 +394,10 @@ public class JpaOrganizationProvider implements OrganizationProvider {
return group;
}
private GroupModel getOrganizationGroup(OrganizationEntity entity) {
return groupProvider.getGroupById(realm, entity.getGroupId());
}
private void throwExceptionIfObjectIsNull(Object object, String objectName) {
if (object == null) {
throw new ModelException(String.format("%s cannot be null", objectName));