Search in sources :

Example 6 with MemberGroupMismatchException

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

the class GroupsManagerBlImpl method convertGroupsToRichGroupsWithAttributes.

@Override
public List<RichGroup> convertGroupsToRichGroupsWithAttributes(PerunSession sess, Member member, List<Group> groups, List<String> attrNames) throws MemberGroupMismatchException, MemberNotExistsException, GroupNotExistsException {
    if (attrNames == null)
        return convertGroupsToRichGroupsWithAttributes(sess, member, groups);
    List<RichGroup> richGroups = new ArrayList<>();
    // separate group and member-group attribute names
    List<String> groupAttrNames = attrNames.stream().filter(attrName -> attrName.startsWith(AttributesManager.NS_GROUP_ATTR)).collect(toList());
    List<String> memberGroupAttrNames = attrNames.stream().filter(attrName -> attrName.startsWith(AttributesManager.NS_MEMBER_GROUP_ATTR)).collect(toList());
    for (Group group : groups) {
        List<Attribute> attributes = new ArrayList<>();
        attributes.addAll(getPerunBl().getAttributesManager().getAttributes(sess, member, group, memberGroupAttrNames));
        attributes.addAll(getPerunBl().getAttributesManager().getAttributes(sess, group, groupAttrNames));
        richGroups.add(new RichGroup(group, attributes));
    }
    return richGroups;
}
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) Attribute(cz.metacentrum.perun.core.api.Attribute) RichGroup(cz.metacentrum.perun.core.api.RichGroup) ArrayList(java.util.ArrayList)

Example 7 with MemberGroupMismatchException

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

the class GroupsManagerBlImpl method getMemberRichGroupsWithAttributesByNames.

@Override
public List<RichGroup> getMemberRichGroupsWithAttributesByNames(PerunSession sess, Member member, List<String> attrNames) {
    List<Group> memberGroups = this.getMemberGroups(sess, member);
    List<RichGroup> richGroups = new ArrayList<>();
    if (attrNames == null) {
        // if attrNames is null, it means all possible group and member-group attributes
        for (Group group : memberGroups) {
            List<Attribute> allGroupAndMemberGroupAttributes = new ArrayList<>();
            allGroupAndMemberGroupAttributes.addAll(this.getPerunBl().getAttributesManagerBl().getAttributes(sess, group));
            try {
                allGroupAndMemberGroupAttributes.addAll(this.getPerunBl().getAttributesManagerBl().getAttributes(sess, member, group));
            } catch (MemberGroupMismatchException e) {
                throw new InternalErrorException(e);
            }
            richGroups.add(new RichGroup(group, allGroupAndMemberGroupAttributes));
        }
    } else {
        // if attrNames is not null, it means only selected group and member-group attributes
        for (Group group : memberGroups) {
            List<Attribute> selectedGroupAndMemberGroupAttributes = new ArrayList<>();
            selectedGroupAndMemberGroupAttributes.addAll(this.getPerunBl().getAttributesManagerBl().getAttributes(sess, group, attrNames));
            try {
                selectedGroupAndMemberGroupAttributes.addAll(this.getPerunBl().getAttributesManagerBl().getAttributes(sess, member, group, attrNames));
            } catch (MemberGroupMismatchException e) {
                throw new InternalErrorException(e);
            }
            richGroups.add(new RichGroup(group, selectedGroupAndMemberGroupAttributes));
        }
    }
    return richGroups;
}
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) MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichGroup(cz.metacentrum.perun.core.api.RichGroup) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 8 with MemberGroupMismatchException

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

the class MetacentrumSocial method approveApplication.

/**
 * Set GROUP MEMBERSHIP EXPIRATION based on the current VO MEMBERSHIP EXPIRATION
 */
@Override
public Application approveApplication(PerunSession session, Application app) throws MemberNotExistsException, WrongAttributeAssignmentException, AttributeNotExistsException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    PerunBl perun = (PerunBl) session.getPerun();
    Vo vo = app.getVo();
    User user = app.getUser();
    Member member = perun.getMembersManagerBl().getMemberByUser(session, vo, user);
    Group group = app.getGroup();
    Attribute voExpiration = perun.getAttributesManagerBl().getAttribute(session, member, A_MEMBER_MEMBERSHIP_EXPIRATION);
    try {
        Attribute groupExpiration = perun.getAttributesManagerBl().getAttribute(session, member, group, A_MEMBER_GROUP_MEMBERSHIP_EXPIRATION);
        groupExpiration.setValue(voExpiration.getValue());
        perun.getAttributesManagerBl().setAttribute(session, member, group, groupExpiration);
        log.debug("{} expiration in Group {} aligned with the VO {} expiration: {}", member, group.getName(), vo.getName(), groupExpiration.valueAsString());
    } catch (MemberGroupMismatchException e) {
        log.error("Member and group should be from the same VO.", e);
        throw new ConsistencyErrorException("Member and group should be from the same VO.", e);
    }
    return app;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) Vo(cz.metacentrum.perun.core.api.Vo) Member(cz.metacentrum.perun.core.api.Member)

Example 9 with MemberGroupMismatchException

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

the class GroupsManagerBlImpl method deleteAnyGroup.

/**
 * If forceDelete is false, delete only group which has no subgroup and no member.
 * If forceDelete is true, delete group with all subgroups and members.
 *
 * @param sess
 * @param group
 * @param forceDelete if false, delete only empty group without subgroups. If true, delete group including subgroups and members.
 * @throws InternalErrorException
 * @throws RelationExistsException Raise only if forceDelete is false and the group has any subgroup or member.
 * @throws GroupAlreadyRemovedException if there are 0 rows affected by deleting from DB
 */
private void deleteAnyGroup(PerunSession sess, Group group, boolean forceDelete) throws RelationExistsException, GroupAlreadyRemovedException, GroupAlreadyRemovedFromResourceException, GroupNotExistsException, GroupRelationDoesNotExist, GroupRelationCannotBeRemoved {
    Vo vo = this.getVo(sess, group);
    if (getGroupsManagerImpl().getSubGroupsCount(sess, group) > 0) {
        if (!forceDelete)
            throw new RelationExistsException("Group group=" + group + " contains subgroups");
        // get subgroups of this group
        List<Group> subGroups = getSubGroups(sess, group);
        for (Group subGroup : subGroups) {
            deleteAnyGroup(sess, subGroup, true);
        }
    }
    if ((this.getGroupMembersCount(sess, group) > 0) && !forceDelete) {
        throw new RelationExistsException("Group group=" + group + " contains members");
    }
    List<AssignedResource> assignedResources = getPerunBl().getResourcesManagerBl().getResourceAssignments(sess, group, List.of());
    try {
        for (AssignedResource assignedResource : assignedResources) {
            if (assignedResource.getSourceGroupId() == null) {
                getPerunBl().getResourcesManagerBl().removeGroupFromResource(sess, group, assignedResource.getEnrichedResource().getResource());
            } else {
                getPerunBl().getResourcesManagerBl().removeAutomaticGroupFromResource(sess, group, assignedResource.getEnrichedResource().getResource(), assignedResource.getSourceGroupId());
            }
        }
        // remove group's attributes
        getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, group);
    } catch (GroupNotDefinedOnResourceException ex) {
        throw new ConsistencyErrorException(ex);
    } catch (AttributeValueException ex) {
        throw new ConsistencyErrorException("All resources was removed from this group, so no attributes should remain assigned.", ex);
    }
    // delete all Groups reserved logins from KDC
    List<Integer> list = getGroupsManagerImpl().getGroupApplicationIds(sess, group);
    for (Integer appId : list) {
        // for each application
        for (Pair<String, String> login : getGroupsManagerImpl().getApplicationReservedLogins(appId)) {
            // for all reserved logins - delete them in ext. system (e.g. KDC)
            try {
                // left = namespace / right = login
                getPerunBl().getUsersManagerBl().deletePassword(sess, login.getRight(), login.getLeft());
            } catch (LoginNotExistsException ex) {
                log.error("Login: {} not exists in namespace: {} while deleting passwords.", login.getRight(), login.getLeft());
            } catch (InvalidLoginException e) {
                throw new InternalErrorException("We are deleting reserved login from group applications, but its syntax is not allowed by namespace configuration.", e);
            } catch (PasswordDeletionFailedException | PasswordOperationTimeoutException ex) {
                throw new InternalErrorException("Failed to delete reserved login " + login.getRight() + " from KDC.", ex);
            }
        }
    }
    // delete all Groups reserved logins from DB
    getGroupsManagerImpl().deleteGroupReservedLogins(sess, group);
    // remove all assigned ExtSources to this group
    List<ExtSource> assignedSources = getPerunBl().getExtSourcesManagerBl().getGroupExtSources(sess, group);
    for (ExtSource source : assignedSources) {
        try {
            getPerunBl().getExtSourcesManagerBl().removeExtSource(sess, group, source);
        } catch (ExtSourceNotAssignedException | ExtSourceAlreadyRemovedException ex) {
            // Just log this, because if method can't remove it, it is probably not assigned now
            log.warn("Try to remove not existing extSource {} from group {} when deleting group.", source, group);
        }
    }
    // 1. remove all relations with group g as an operand group.
    // this removes all relations that depend on this group
    List<Integer> relations = groupsManagerImpl.getResultGroupsIds(sess, group.getId());
    for (Integer groupId : relations) {
        removeGroupUnion(sess, groupsManagerImpl.getGroupById(sess, groupId), group, true);
    }
    // 2. remove all relations with group as a result group
    // We can remove relations without recalculation (@see removeRelationMembers)
    // because all dependencies of group were deleted in step 1.
    groupsManagerImpl.removeResultGroupRelations(sess, group);
    // Group applications, submitted data and app_form are deleted on cascade with "deleteGroup()"
    List<Member> membersFromDeletedGroup = getGroupMembers(sess, group);
    // delete all member-group attributes
    for (Member member : membersFromDeletedGroup) {
        try {
            perunBl.getAttributesManagerBl().removeAllAttributes(sess, member, group);
        } catch (AttributeValueException ex) {
            throw new ConsistencyErrorException("All members were removed from this group. So all member-group attribute values can be removed.", ex);
        } catch (MemberGroupMismatchException e) {
            throw new InternalErrorException("Member we tried to remove all member-group attributes doesn't come from the same VO as group", e);
        }
    }
    // remove admin roles of group
    List<Facility> facilitiesWhereGroupIsAdmin = getGroupsManagerImpl().getFacilitiesWhereGroupIsAdmin(sess, group);
    for (Facility facility : facilitiesWhereGroupIsAdmin) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, group, facility, Role.FACILITYADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("Can't unset group {} as admin of facility {} due to group not admin exception {}.", group, facility, e);
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    List<Group> groupsWhereGroupIsAdmin = getGroupsManagerImpl().getGroupsWhereGroupIsAdmin(sess, group);
    for (Group group1 : groupsWhereGroupIsAdmin) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, group, group1, Role.GROUPADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("Can't unset group {} as admin of group {} due to group not admin exception {}.", group, group1, e);
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    List<Resource> resourcesWhereGroupIsAdmin = getGroupsManagerImpl().getResourcesWhereGroupIsAdmin(sess, group);
    for (Resource resource : resourcesWhereGroupIsAdmin) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, group, resource, Role.RESOURCEADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("Can't unset group {} as admin of resource {} due to group not admin exception {}.", group, resource, e);
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    List<Resource> resourcesWhereGroupIsResourceSelfService = getGroupsManagerImpl().getResourcesWhereGroupIsResourceSelfService(sess, group);
    for (Resource resource : resourcesWhereGroupIsResourceSelfService) {
        try {
            perunBl.getResourcesManagerBl().removeResourceSelfServiceGroup(sess, resource, group);
        } catch (GroupNotAdminException e) {
            log.warn("Can't unset group {} as admin of resource {} due to group not admin exception {}.", group, resource, e);
        }
    }
    List<SecurityTeam> securityTeamsWhereGroupIsAdmin = getGroupsManagerImpl().getSecurityTeamsWhereGroupIsAdmin(sess, group);
    for (SecurityTeam securityTeam : securityTeamsWhereGroupIsAdmin) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, group, securityTeam, Role.SECURITYADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("Can't unset group {} as admin of security team {} due to group not admin exception {}.", group, securityTeam, e);
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    List<Vo> vosWhereGroupIsAdmin = getGroupsManagerImpl().getVosWhereGroupIsAdmin(sess, group);
    for (Vo vo1 : vosWhereGroupIsAdmin) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, group, vo1, Role.VOADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("Can't unset group {} as admin of facility {} due to group not admin exception {}.", group, vo1, e);
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    // remove admins of this group
    List<Group> adminGroups = getGroupsManagerImpl().getGroupAdmins(sess, group);
    for (Group adminGroup : adminGroups) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, adminGroup, group, Role.GROUPADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("When trying to unsetRole GroupAdmin for group {} in the group {} the exception was thrown {}", adminGroup, group, e);
        // skip and log as warning
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    List<User> adminUsers = getGroupsManagerImpl().getAdmins(sess, group);
    for (User adminUser : adminUsers) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, adminUser, group, Role.GROUPADMIN);
        } catch (UserNotAdminException e) {
            log.warn("When trying to unsetRole GroupAdmin for user {} in the group {} the exception was thrown {}", adminUser, group, e);
        // skip and log as warning
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    // Deletes also all direct and indirect members of the group
    getGroupsManagerImpl().deleteGroup(sess, vo, group);
    logTotallyRemovedMembers(sess, group.getParentGroupId(), membersFromDeletedGroup);
    getPerunBl().getAuditer().log(sess, new GroupDeleted(group));
}
Also used : ExtSourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.ExtSourceAlreadyRemovedException) 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) MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) AttributeValueException(cz.metacentrum.perun.core.api.exceptions.AttributeValueException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) Vo(cz.metacentrum.perun.core.api.Vo) GroupCreatedInVo(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupCreatedInVo) GroupDeleted(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupDeleted) ExtSourceNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotAssignedException) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) Resource(cz.metacentrum.perun.core.api.Resource) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) SecurityTeam(cz.metacentrum.perun.core.api.SecurityTeam) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) PasswordOperationTimeoutException(cz.metacentrum.perun.core.api.exceptions.PasswordOperationTimeoutException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) PasswordDeletionFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordDeletionFailedException) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Facility(cz.metacentrum.perun.core.api.Facility) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException)

Example 10 with MemberGroupMismatchException

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

the class GroupsManagerBlImpl method removeIndirectMembers.

/**
 * Remove records of the members with an INDIRECT membership type from the group.
 *
 * @param sess perun session
 * @param group group to remove records of INDIRECT members from
 * @param members list of members to remove
 * @param sourceGroupId id of a group from which members originate
 * @return list of members that were removed (their only record in the group was deleted)
 */
private List<Member> removeIndirectMembers(PerunSession sess, Group group, List<Member> members, int sourceGroupId) throws WrongAttributeValueException, WrongReferenceAttributeValueException, NotGroupMemberException {
    List<Member> membersToRemove = new ArrayList<>(members);
    lockGroupMembership(group, membersToRemove);
    for (Member member : membersToRemove) {
        member.setSourceGroupId(sourceGroupId);
        groupsManagerImpl.removeMember(sess, group, member);
    }
    // get list of new members
    List<Member> newMembers = this.getGroupMembers(sess, group);
    // get only removed members
    membersToRemove.removeAll(newMembers);
    for (Member removedIndirectMember : membersToRemove) {
        addMemberToGroupsFromTriggerAttribute(sess, group, removedIndirectMember);
        notifyMemberRemovalFromGroup(sess, group, removedIndirectMember);
        // remove all member-group attributes because member is not part of group any more
        try {
            getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, removedIndirectMember, group);
        } catch (MemberGroupMismatchException e) {
            throw new InternalErrorException("Member we tried to remove all member-group attributes is not from the same VO as Group.", e);
        }
        getPerunBl().getAuditer().log(sess, new IndirectMemberRemovedFromGroup(removedIndirectMember, group));
    }
    return membersToRemove;
}
Also used : MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Aggregations

MemberGroupMismatchException (cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException)19 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)14 Attribute (cz.metacentrum.perun.core.api.Attribute)8 Member (cz.metacentrum.perun.core.api.Member)8 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)8 Group (cz.metacentrum.perun.core.api.Group)7 RichMember (cz.metacentrum.perun.core.api.RichMember)7 ArrayList (java.util.ArrayList)7 DirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup)5 IndirectMemberRemovedFromGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup)5 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)5 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)5 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)5 DirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup)4 IndirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup)4 MemberExpiredInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup)4 MemberValidatedInGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup)4 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)4 CandidateGroup (cz.metacentrum.perun.core.api.CandidateGroup)4 EnrichedGroup (cz.metacentrum.perun.core.api.EnrichedGroup)4