Search in sources :

Example 1 with GroupAlreadyRemovedFromResourceException

use of cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException in project perun by CESNET.

the class ResourcesManagerBlImpl method removeGroupFromResource.

/**
 * Remove group from a resource. Remove subgroups automatic assignments.
 * After removing, check attributes and fix them if it is needed.
 *
 * @param sess
 * @param group
 * @param resource
 * @param sourceGroupId id of a source group if an automatic assignment should be deleted, null otherwise
 * @throws GroupNotDefinedOnResourceException when there is no such group-resource assignment
 * @throws GroupAlreadyRemovedFromResourceException when the assignment was already removed
 */
private void removeGroupFromResource(PerunSession sess, Group group, Resource resource, Integer sourceGroupId) throws GroupNotDefinedOnResourceException, GroupAlreadyRemovedFromResourceException {
    Vo groupVo = getPerunBl().getGroupsManagerBl().getVo(sess, group);
    // Check if the group and resource belongs to the same VO
    if (!groupVo.equals(this.getVo(sess, resource))) {
        throw new InternalErrorException("Group " + group + " and resource " + resource + " belongs to the different VOs");
    }
    // Check if the group-resource assignment is defined
    Optional<AssignedGroup> assignmentToRemove = getResourcesManagerImpl().getGroupAssignments(sess, resource).stream().filter(assignedGroup -> assignedGroup.getEnrichedGroup().getGroup().equals(group) && Objects.equals(assignedGroup.getSourceGroupId(), sourceGroupId)).findFirst();
    if (assignmentToRemove.isEmpty()) {
        // Group is not defined on the resource
        throw new GroupNotDefinedOnResourceException(group.getName());
    }
    // Remove group
    if (sourceGroupId != null) {
        getResourcesManagerImpl().removeAutomaticGroupFromResource(sess, group, resource, sourceGroupId);
    } else {
        getResourcesManagerImpl().removeGroupFromResource(sess, group, resource);
        // Remove automatically assigned subgroups
        List<AssignedGroup> subgroupsAssignments = getResourcesManagerImpl().getGroupAssignments(sess, resource).stream().filter(assignedGroup -> Objects.equals(assignedGroup.getSourceGroupId(), group.getId())).collect(Collectors.toList());
        for (AssignedGroup assignedSubgroup : subgroupsAssignments) {
            try {
                removeAutomaticGroupFromResource(sess, assignedSubgroup.getEnrichedGroup().getGroup(), resource, group.getId());
            } catch (GroupAlreadyRemovedFromResourceException e) {
            // skip silently
            }
        }
    }
    // If it was the last ACTIVE assignment, we can delete group-resource attributes and audit the removal
    if (!isGroupAssigned(sess, resource, group)) {
        getPerunBl().getAuditer().log(sess, new GroupRemovedFromResource(group, resource));
        // Remove group-resource attributes
        try {
            getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, resource, group);
        } catch (WrongAttributeValueException | WrongReferenceAttributeValueException e) {
            throw new InternalErrorException(e);
        } catch (GroupResourceMismatchException ex) {
            throw new ConsistencyErrorException(ex);
        }
    }
// FIXME - here we should call checkSemantics() and on error re-fill/set user-facility attributes
// for the group members of removed group, which are still allowed on the facility, since we removed
// one relation and attribute constraints might have changed (eg. for shell / default gid/group).
// We don't do this for performance reasons.
}
Also used : InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Arrays(java.util.Arrays) ResourceTag(cz.metacentrum.perun.core.api.ResourceTag) Vo(cz.metacentrum.perun.core.api.Vo) ServiceNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ServiceNotAssignedException) LoggerFactory(org.slf4j.LoggerFactory) GroupResourceAssignment(cz.metacentrum.perun.core.api.GroupResourceAssignment) ServicesPackage(cz.metacentrum.perun.core.api.ServicesPackage) BanSetForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanSetForResource) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) Role(cz.metacentrum.perun.core.api.Role) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) ResourceTagAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.ResourceTagAlreadyAssignedException) Attribute(cz.metacentrum.perun.core.api.Attribute) Facility(cz.metacentrum.perun.core.api.Facility) GroupResourceStatus(cz.metacentrum.perun.core.api.GroupResourceStatus) ResourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.ResourceAlreadyRemovedException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) FacilityNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) Collectors(java.util.stream.Collectors) User(cz.metacentrum.perun.core.api.User) Objects(java.util.Objects) VosManager(cz.metacentrum.perun.core.api.VosManager) BanUpdatedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanUpdatedForResource) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) List(java.util.List) BanRemovedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanRemovedForResource) Optional(java.util.Optional) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) RichMember(cz.metacentrum.perun.core.api.RichMember) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) Service(cz.metacentrum.perun.core.api.Service) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) Resource(cz.metacentrum.perun.core.api.Resource) ResourceDeleted(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceDeleted) Async(org.springframework.scheduling.annotation.Async) PerunSession(cz.metacentrum.perun.core.api.PerunSession) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) ObjectUtils.isEmpty(org.apache.commons.lang3.ObjectUtils.isEmpty) AssignedMember(cz.metacentrum.perun.core.api.AssignedMember) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) GroupResourceStatusException(cz.metacentrum.perun.core.api.exceptions.GroupResourceStatusException) ServiceRemovedFromResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceRemovedFromResource) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) GroupAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupAssignedToResource) Group(cz.metacentrum.perun.core.api.Group) ArrayList(java.util.ArrayList) ResourcesManagerBl(cz.metacentrum.perun.core.bl.ResourcesManagerBl) ResourceCreated(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceCreated) ServiceAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource) ResourceTagNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ResourceTagNotAssignedException) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) ResourceUpdated(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceUpdated) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException) GroupRemovedFromResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupRemovedFromResource) ResourceSelfServiceAddedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceAddedForGroup) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) AttributeValueException(cz.metacentrum.perun.core.api.exceptions.AttributeValueException) RichResource(cz.metacentrum.perun.core.api.RichResource) RichUser(cz.metacentrum.perun.core.api.RichUser) ServiceAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.ServiceAlreadyAssignedException) Member(cz.metacentrum.perun.core.api.Member) Logger(org.slf4j.Logger) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) ResourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceNotExistsException) AttributesManager(cz.metacentrum.perun.core.api.AttributesManager) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) ResourceSelfServiceRemovedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForGroup) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) ResourceSelfServiceRemovedForUser(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForUser) EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) BanAlreadyExistsException(cz.metacentrum.perun.core.api.exceptions.BanAlreadyExistsException) ResourceExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceExistsException) ResourcesManagerImplApi(cz.metacentrum.perun.core.implApi.ResourcesManagerImplApi) Collections(java.util.Collections) Status(cz.metacentrum.perun.core.api.Status) ResourceTagNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceTagNotExistsException) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) GroupRemovedFromResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupRemovedFromResource) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) Vo(cz.metacentrum.perun.core.api.Vo) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup)

Example 2 with GroupAlreadyRemovedFromResourceException

use of cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException in project perun by CESNET.

the class GroupsManagerBlImpl method removeFormerGroupsWhileSynchronization.

/**
 * remove groups which are not listed in extSource anymore
 *
 * If some problem occurs, add groupToRemove to skippedGroups and skip it.
 *
 * Method is used by group structure synchronization.
 *
 * @param sess
 * @param baseGroup from which we will be removing groups
 * @param groupsToRemove list of groups to be removed from baseGroup
 *
 * @return list of ids already removed groups
 * @throws InternalErrorException if some internal error occurs
 */
private List<Integer> removeFormerGroupsWhileSynchronization(PerunSession sess, Group baseGroup, List<Group> groupsToRemove, List<String> skippedGroups) {
    List<Integer> removedGroups = new ArrayList<>();
    groupsToRemove.sort(reverseOrder(comparingInt(g -> g.getName().length())));
    for (Group groupToRemove : groupsToRemove) {
        try {
            groupToRemove = moveSubGroupsUnderBaseGroup(sess, groupToRemove, baseGroup);
            deleteGroup(sess, groupToRemove, true);
            removedGroups.add(groupToRemove.getId());
            log.info("Group structure synchronization {}: Group id {} removed.", baseGroup, groupToRemove.getId());
        } catch (RelationExistsException e) {
            log.warn("Can't remove group {} from baseGroup {} due to group relation exists exception {}.", groupToRemove, e);
            skippedGroups.add("GroupEntry:[" + groupToRemove + "] was skipped because group relation exists: Exception: " + e.getName() + " => " + e.getMessage() + "]");
        } catch (GroupAlreadyRemovedException | GroupAlreadyRemovedFromResourceException e) {
            log.debug("Group {} was removed from group {} before removing process. Skip this group.", groupToRemove, baseGroup);
        } catch (GroupNotExistsException e) {
            log.warn("Can't remove group {} from baseGroup {} due to group not exists exception {}.", groupToRemove, e);
            skippedGroups.add("GroupEntry:[" + groupToRemove + "] was skipped because group does not exists: Exception: " + e.getName() + " => " + e.getMessage() + "]");
        } catch (GroupRelationDoesNotExist e) {
            log.warn("Can't remove group {} from baseGroup {} due to group relation does not exists exception {}.", groupToRemove, e);
            skippedGroups.add("GroupEntry:[" + groupToRemove + "] was skipped because group relation does not exists: Exception: " + e.getName() + " => " + e.getMessage() + "]");
        } catch (GroupRelationCannotBeRemoved e) {
            log.warn("Can't remove group {} from baseGroup {} due to group relation cannot be removed exception {}.", groupToRemove, e);
            skippedGroups.add("GroupEntry:[" + groupToRemove + "] was skipped because group relation cannot be removed: Exception: " + e.getName() + " => " + e.getMessage() + "]");
        } catch (GroupMoveNotAllowedException e) {
            log.warn("Can't remove group {} from baseGroup {} due to group move not allowed exception {}.", groupToRemove, e);
            skippedGroups.add("GroupEntry:[" + groupToRemove + "] was skipped because group move is not allowed: Exception: " + e.getName() + " => " + e.getMessage() + "]");
        } catch (WrongAttributeValueException e) {
            log.warn("Can't remove group {} from baseGroup {} due to wrong attribute value exception {}.", groupToRemove, e);
            skippedGroups.add("GroupEntry:[" + groupToRemove + "] was skipped because wrong attribute value: Exception: " + e.getName() + " => " + e.getMessage() + "]");
        } catch (WrongReferenceAttributeValueException e) {
            log.warn("Can't remove group {} from baseGroup {} due to wrong reference attribute value exception {}.", groupToRemove, e);
            skippedGroups.add("GroupEntry:[" + groupToRemove + "] was skipped because wrong reference attribute value: Exception: " + e.getName() + " => " + e.getMessage() + "]");
        }
    }
    return removedGroups;
}
Also used : EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) RichGroup(cz.metacentrum.perun.core.api.RichGroup) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) Group(cz.metacentrum.perun.core.api.Group) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) GroupRelationCannotBeRemoved(cz.metacentrum.perun.core.api.exceptions.GroupRelationCannotBeRemoved) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) GroupMoveNotAllowedException(cz.metacentrum.perun.core.api.exceptions.GroupMoveNotAllowedException) GroupRelationDoesNotExist(cz.metacentrum.perun.core.api.exceptions.GroupRelationDoesNotExist) ArrayList(java.util.ArrayList) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) GroupAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedException)

Example 3 with GroupAlreadyRemovedFromResourceException

use of cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException in project perun by CESNET.

the class ResourceAssignmentChecker method removeSubgroupFromResource.

/**
 * Remove assigned subgroup which source group is not assigned as source group.
 * Runs in transaction.
 * @param resource
 * @param sourceGroups
 * @param assignedSubgroup
 */
public void removeSubgroupFromResource(Resource resource, List<AssignedGroup> sourceGroups, AssignedGroup assignedSubgroup) {
    boolean sourceIsAssigned;
    try {
        Group srcGroup = perunBl.getGroupsManagerBl().getGroupById(sess, assignedSubgroup.getSourceGroupId());
        sourceIsAssigned = sourceGroups.stream().anyMatch(s -> s.getEnrichedGroup().getGroup().equals(srcGroup));
    } catch (GroupNotExistsException e) {
        sourceIsAssigned = false;
    }
    if (!sourceIsAssigned) {
        try {
            perunBl.getResourcesManagerBl().removeAutomaticGroupFromResource(sess, assignedSubgroup.getEnrichedGroup().getGroup(), resource, assignedSubgroup.getSourceGroupId());
        } catch (GroupNotDefinedOnResourceException | GroupAlreadyRemovedFromResourceException e) {
        // skip silently, already removed
        }
    }
}
Also used : Resource(cz.metacentrum.perun.core.api.Resource) PerunSession(cz.metacentrum.perun.core.api.PerunSession) Logger(org.slf4j.Logger) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) LoggerFactory(org.slf4j.LoggerFactory) Scheduled(org.springframework.scheduling.annotation.Scheduled) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) Collectors(java.util.stream.Collectors) Group(cz.metacentrum.perun.core.api.Group) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) List(java.util.List) ExtSourcesManager(cz.metacentrum.perun.core.api.ExtSourcesManager) PerunClient(cz.metacentrum.perun.core.api.PerunClient) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) Group(cz.metacentrum.perun.core.api.Group) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException)

Example 4 with GroupAlreadyRemovedFromResourceException

use of cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException in project perun by CESNET.

the class GroupsManagerBlImpl method fixMovedTreeAutoassignments.

/**
 * Checks, if moving group would still belong under source group tree of automatic assignments on all assigned resources
 * and removes together with subgroups from source group's autoassignments if not
 * @param sess
 * @param destinationGroup
 * @param movingGroup
 */
private void fixMovedTreeAutoassignments(PerunSession sess, Group destinationGroup, Group movingGroup) {
    List<AssignedResource> autoAssignedResources = perunBl.getResourcesManagerBl().getResourceAssignments(sess, movingGroup, List.of()).stream().filter(g -> g.getSourceGroupId() != null).collect(toList());
    for (AssignedResource autoAssignedResource : autoAssignedResources) {
        int sourceGroupId = autoAssignedResource.getSourceGroupId();
        try {
            Group sourceGroup = this.getGroupById(sess, sourceGroupId);
            List<Group> sourceSubgroups = this.getAllSubGroups(sess, sourceGroup);
            if (destinationGroup == null || !sourceSubgroups.contains(destinationGroup)) {
                // remove automatic group and subgroups' assignments
                List<Group> groupsToRemove = this.getAllSubGroups(sess, movingGroup);
                groupsToRemove.add(movingGroup);
                for (Group groupToRemove : groupsToRemove) {
                    try {
                        perunBl.getResourcesManagerBl().removeAutomaticGroupFromResource(sess, groupToRemove, autoAssignedResource.getEnrichedResource().getResource(), sourceGroupId);
                    } catch (GroupAlreadyRemovedFromResourceException | GroupNotDefinedOnResourceException e) {
                    // skip
                    }
                }
            }
        } catch (GroupNotExistsException e) {
            log.error("Assignment source group doesn't exist: " + autoAssignedResource, e);
        }
    }
}
Also used : Pair(cz.metacentrum.perun.core.api.Pair) Arrays(java.util.Arrays) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) GroupSynchronizationAlreadyRunningException(cz.metacentrum.perun.core.api.exceptions.GroupSynchronizationAlreadyRunningException) Vo(cz.metacentrum.perun.core.api.Vo) GroupSyncStarted(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupSyncStarted) GroupExistsException(cz.metacentrum.perun.core.api.exceptions.GroupExistsException) ExtSource(cz.metacentrum.perun.core.api.ExtSource) Matcher(java.util.regex.Matcher) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) Collections.reverseOrder(java.util.Collections.reverseOrder) Map(java.util.Map) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) ExtSourceApi(cz.metacentrum.perun.core.implApi.ExtSourceApi) Attribute(cz.metacentrum.perun.core.api.Attribute) Facility(cz.metacentrum.perun.core.api.Facility) GroupResourceStatus(cz.metacentrum.perun.core.api.GroupResourceStatus) GroupRelationCannotBeRemoved(cz.metacentrum.perun.core.api.exceptions.GroupRelationCannotBeRemoved) MemberAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException) ParserException(cz.metacentrum.perun.core.api.exceptions.ParserException) BeansUtils(cz.metacentrum.perun.core.api.BeansUtils) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) GroupMoveNotAllowedException(cz.metacentrum.perun.core.api.exceptions.GroupMoveNotAllowedException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Set(java.util.Set) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) User(cz.metacentrum.perun.core.api.User) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) SecurityTeam(cz.metacentrum.perun.core.api.SecurityTeam) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) RichMember(cz.metacentrum.perun.core.api.RichMember) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) GroupSyncFinished(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupSyncFinished) ExtSourceNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotAssignedException) ExtSourceUnsupportedOperationException(cz.metacentrum.perun.core.api.exceptions.ExtSourceUnsupportedOperationException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) SynchronizationPool(cz.metacentrum.perun.core.impl.SynchronizationPool) GroupCreatedAsSubgroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupCreatedAsSubgroup) MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) GroupSyncFinishedWithErrors(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupSyncFinishedWithErrors) GroupNotAllowedToAutoRegistrationException(cz.metacentrum.perun.core.api.exceptions.GroupNotAllowedToAutoRegistrationException) LocalDateTime(java.time.LocalDateTime) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) ExtSourceAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.ExtSourceAlreadyAssignedException) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) GroupsManagerImplApi(cz.metacentrum.perun.core.implApi.GroupsManagerImplApi) GroupRelationDoesNotExist(cz.metacentrum.perun.core.api.exceptions.GroupRelationDoesNotExist) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) GroupCreatedInVo(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupCreatedInVo) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException) ExtSourceSimpleApi(cz.metacentrum.perun.core.implApi.ExtSourceSimpleApi) RichUser(cz.metacentrum.perun.core.api.RichUser) GroupStructureSynchronizationAlreadyRunningException(cz.metacentrum.perun.core.api.exceptions.GroupStructureSynchronizationAlreadyRunningException) Member(cz.metacentrum.perun.core.api.Member) GroupUpdated(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupUpdated) RichGroup(cz.metacentrum.perun.core.api.RichGroup) AbstractMembershipExpirationRulesModule(cz.metacentrum.perun.core.implApi.modules.attributes.AbstractMembershipExpirationRulesModule) ResourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceNotExistsException) AlreadyMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException) AttributesManager(cz.metacentrum.perun.core.api.AttributesManager) ExtendMembershipException(cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) ChronoUnit(java.time.temporal.ChronoUnit) TreeMap(java.util.TreeMap) Utils(cz.metacentrum.perun.core.impl.Utils) MDC(org.slf4j.MDC) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) GroupsPageQuery(cz.metacentrum.perun.core.api.GroupsPageQuery) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Candidate(cz.metacentrum.perun.core.api.Candidate) AuthzResolver(cz.metacentrum.perun.core.api.AuthzResolver) Date(java.util.Date) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) LoggerFactory(org.slf4j.LoggerFactory) MemberRemovedFromGroupTotally(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberRemovedFromGroupTotally) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) ExtSourcesManager(cz.metacentrum.perun.core.api.ExtSourcesManager) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) Role(cz.metacentrum.perun.core.api.Role) ParseException(java.text.ParseException) GroupsManager(cz.metacentrum.perun.core.api.GroupsManager) GroupRelationNotAllowed(cz.metacentrum.perun.core.api.exceptions.GroupRelationNotAllowed) MemberNotValidYetException(cz.metacentrum.perun.core.api.exceptions.MemberNotValidYetException) ImmutableSet(com.google.common.collect.ImmutableSet) CandidateNotExistsException(cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Objects(java.util.Objects) VosManager(cz.metacentrum.perun.core.api.VosManager) DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) List(java.util.List) LocalDate(java.time.LocalDate) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Queue(java.util.Queue) Pattern(java.util.regex.Pattern) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) GroupMoved(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupMoved) Resource(cz.metacentrum.perun.core.api.Resource) PerunSession(cz.metacentrum.perun.core.api.PerunSession) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) TemporalUnit(java.time.temporal.TemporalUnit) Paginated(cz.metacentrum.perun.core.api.Paginated) HashMap(java.util.HashMap) GroupStructureSyncFailed(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupStructureSyncFailed) Group(cz.metacentrum.perun.core.api.Group) GroupSynchronizationNotEnabledException(cz.metacentrum.perun.core.api.exceptions.GroupSynchronizationNotEnabledException) PasswordDeletionFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordDeletionFailedException) HashSet(java.util.HashSet) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) GroupStructureSyncFinishedWithErrors(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupStructureSyncFinishedWithErrors) GroupAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedException) GroupDeleted(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupDeleted) PerunLocksUtils.lockGroupMembership(cz.metacentrum.perun.core.impl.PerunLocksUtils.lockGroupMembership) NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) PasswordOperationTimeoutException(cz.metacentrum.perun.core.api.exceptions.PasswordOperationTimeoutException) AttributeValueException(cz.metacentrum.perun.core.api.exceptions.AttributeValueException) Comparator.comparingInt(java.util.Comparator.comparingInt) GroupRelationAlreadyExists(cz.metacentrum.perun.core.api.exceptions.GroupRelationAlreadyExists) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) GroupSyncFailed(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupSyncFailed) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) ActionType(cz.metacentrum.perun.core.api.ActionType) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) MembershipType(cz.metacentrum.perun.core.api.MembershipType) Host(cz.metacentrum.perun.core.api.Host) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) Collectors.toList(java.util.stream.Collectors.toList) PerunClient(cz.metacentrum.perun.core.api.PerunClient) DateTimeFormatter(java.time.format.DateTimeFormatter) ExtSourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.ExtSourceAlreadyRemovedException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) Comparator(java.util.Comparator) Collections(java.util.Collections) Status(cz.metacentrum.perun.core.api.Status) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) RichGroup(cz.metacentrum.perun.core.api.RichGroup) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) Group(cz.metacentrum.perun.core.api.Group) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource)

Example 5 with GroupAlreadyRemovedFromResourceException

use of cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException in project perun by CESNET.

the class ResourcesManagerBlImpl method deleteResource.

@Override
public void deleteResource(PerunSession sess, Resource resource) throws ResourceAlreadyRemovedException, GroupAlreadyRemovedFromResourceException {
    // Get facility for audit messages
    Facility facility = this.getFacility(sess, resource);
    // remove admins of this resource
    List<Group> adminGroups = getResourcesManagerImpl().getAdminGroups(sess, resource);
    for (Group adminGroup : adminGroups) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, adminGroup, resource, Role.RESOURCEADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("When trying to unsetRole ResourceAdmin for group {} in the resource {} the exception was thrown {}", adminGroup, resource, e);
        // skip and log as warning
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    List<User> adminUsers = getResourcesManagerImpl().getAdmins(sess, resource);
    for (User adminUser : adminUsers) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, adminUser, resource, Role.RESOURCEADMIN);
        } catch (UserNotAdminException e) {
            log.warn("When trying to unsetRole ResourceAdmin for user {} in the resource {} the exception was thrown {}", adminUser, resource, e);
        // skip and log as warning
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    // Remove binding between resource and service
    List<Service> services = getAssignedServices(sess, resource);
    for (Service service : services) {
        try {
            this.removeService(sess, resource, service);
        } catch (ServiceNotAssignedException e) {
            throw new ConsistencyErrorException(e);
        }
    }
    List<AssignedGroup> assignedGroups = getGroupAssignments(sess, resource, List.of());
    for (AssignedGroup assignedGroup : assignedGroups) {
        if (assignedGroup.getSourceGroupId() == null) {
            try {
                removeGroupFromResource(sess, assignedGroup.getEnrichedGroup().getGroup(), resource);
            } catch (GroupNotDefinedOnResourceException ex) {
                throw new GroupAlreadyRemovedFromResourceException(ex);
            }
        }
    }
    // Remove attr values for the resource
    try {
        perunBl.getAttributesManagerBl().removeAllAttributes(sess, resource);
    } catch (AttributeValueException ex) {
        throw new ConsistencyErrorException("All services are removed from this resource. There is no required attribute. So all attribtes for this resource can be removed withou problem.", ex);
    }
    // Remove group-resource attr values for all group and resource
    try {
        this.perunBl.getAttributesManagerBl().removeAllGroupResourceAttributes(sess, resource);
    } catch (WrongAttributeValueException | GroupResourceMismatchException | WrongReferenceAttributeValueException ex) {
        throw new InternalErrorException(ex);
    }
    // Remove all resources tags
    this.removeAllResourcesTagFromResource(sess, resource);
    // Remove all resource bans
    List<BanOnResource> bansOnResource = this.getBansForResource(sess, resource.getId());
    for (BanOnResource banOnResource : bansOnResource) {
        try {
            this.removeBan(sess, banOnResource.getId());
        } catch (BanNotExistsException ex) {
        // it is ok, we just want to remove it anyway
        }
    }
    // Because resource will be tottaly deleted, we can also delete all member-resource attributes
    this.perunBl.getAttributesManagerBl().removeAllMemberResourceAttributes(sess, resource);
    // Get the resource VO
    Vo vo = this.getVo(sess, resource);
    getResourcesManagerImpl().deleteResource(sess, vo, resource);
    getPerunBl().getAuditer().log(sess, new ResourceDeleted(resource, facility));
}
Also used : AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) Group(cz.metacentrum.perun.core.api.Group) ResourceSelfServiceAddedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceAddedForGroup) ResourceSelfServiceRemovedForGroup(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForGroup) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) ResourceSelfServiceRemovedForUser(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForUser) AttributeValueException(cz.metacentrum.perun.core.api.exceptions.AttributeValueException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) Vo(cz.metacentrum.perun.core.api.Vo) ResourceDeleted(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceDeleted) ServiceNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ServiceNotAssignedException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Service(cz.metacentrum.perun.core.api.Service) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) Facility(cz.metacentrum.perun.core.api.Facility) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)

Aggregations

Group (cz.metacentrum.perun.core.api.Group)5 GroupAlreadyRemovedFromResourceException (cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException)4 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)4 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)4 AssignedGroup (cz.metacentrum.perun.core.api.AssignedGroup)3 Facility (cz.metacentrum.perun.core.api.Facility)3 PerunSession (cz.metacentrum.perun.core.api.PerunSession)3 Resource (cz.metacentrum.perun.core.api.Resource)3 RichUser (cz.metacentrum.perun.core.api.RichUser)3 User (cz.metacentrum.perun.core.api.User)3 Vo (cz.metacentrum.perun.core.api.Vo)3 GroupNotDefinedOnResourceException (cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException)3 GroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException)3 GroupResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)3 DirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup)2 DirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup)2 IndirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup)2 IndirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup)2 MemberExpiredInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup)2 MemberValidatedInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup)2