Search in sources :

Example 1 with NotGroupMemberException

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

the class GroupsManagerBlImpl method getGroupMemberById.

@Override
public Member getGroupMemberById(PerunSession sess, Group group, int memberId) throws NotGroupMemberException {
    List<Member> members = getGroupsManagerImpl().getGroupMembersById(sess, group, memberId);
    if (members.isEmpty())
        throw new NotGroupMemberException("Member with ID=" + memberId + " is not member of " + group + " or doesn't exists at all.");
    List<Member> filteredMembers = this.filterMembersByMembershipTypeInGroup(members);
    if (filteredMembers.size() == 0)
        throw new InternalErrorException("Filtering DIRECT/INDIRECT members resulted in empty members list.");
    if (filteredMembers.size() > 1)
        throw new ConsistencyErrorException("Filtering DIRECT/INDIRECT members resulted with >1 members with same ID.");
    return filteredMembers.get(0);
}
Also used : NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Example 2 with NotGroupMemberException

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

the class GroupsManagerBlImpl method removeGroupUnion.

@Override
public void removeGroupUnion(PerunSession sess, Group resultGroup, Group operandGroup, boolean parentFlag) throws GroupRelationDoesNotExist, GroupRelationCannotBeRemoved, GroupNotExistsException {
    if (!groupsManagerImpl.isOneWayRelationBetweenGroups(resultGroup, operandGroup)) {
        throw new GroupRelationDoesNotExist("Union does not exist between result group " + resultGroup + " and operand group" + operandGroup + ".");
    }
    Map<Integer, Map<Integer, MemberGroupStatus>> previousStatuses = getPreviousStatuses(sess, operandGroup, getGroupMembers(sess, resultGroup));
    if (parentFlag || groupsManagerImpl.isRelationRemovable(sess, resultGroup, operandGroup)) {
        try {
            removeRelationMembers(sess, resultGroup, getGroupMembers(sess, operandGroup), operandGroup.getId());
        } catch (WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
            throw new InternalErrorException("Removing relation members failed. Cause: {}", ex);
        } catch (NotGroupMemberException ex) {
            throw new ConsistencyErrorException("Database inconsistency. Cause: {}", ex);
        }
    } else {
        throw new GroupRelationCannotBeRemoved("Union between result group " + resultGroup + " and operand group" + operandGroup + " cannot be removed, because it's part of the hierarchical structure of the groups.");
    }
    groupsManagerImpl.removeGroupUnion(sess, resultGroup, operandGroup);
    // recalculates statuses of members in result group
    for (Member member : getGroupMembers(sess, resultGroup)) {
        recalculateMemberGroupStatusRecursively(sess, member, resultGroup, previousStatuses);
    }
}
Also used : NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) GroupRelationCannotBeRemoved(cz.metacentrum.perun.core.api.exceptions.GroupRelationCannotBeRemoved) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) GroupRelationDoesNotExist(cz.metacentrum.perun.core.api.exceptions.GroupRelationDoesNotExist) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Example 3 with NotGroupMemberException

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

the class GroupsManagerBlImpl method removeFormerMemberWhileSynchronization.

/**
 * Remove former member from group (if he is not listed in ExtSource).
 *
 * If this is membersGroup (of some Vo) try to disableMember, if not possible then delete him.
 * If this is regular group (of some Vo) remove him and if this group is also
 * his last authoritative group, disable or delete him also in the Vo.
 *
 * This method runs in separate transaction.
 *
 * @param sess perun session
 * @param group to be synchronized
 * @param memberToRemove member to be removed from Group
 *
 * @throws GroupNotExistsException if group does not exist
 */
public void removeFormerMemberWhileSynchronization(PerunSession sess, Group group, RichMember memberToRemove, boolean isAuthoritative) throws GroupNotExistsException {
    // Member is missing in the external group, so remove him from the perun group
    try {
        // members group
        if (group.getName().equals(VosManager.MEMBERS_GROUP)) {
            // If the group is members group, the member must be disabled as a member of VO
            removeMemberFromMembersGroup(sess, group, memberToRemove);
        // not members group
        } else {
            // If Yes = deleteMember (from Vo), if No = only removeMember
            if (isAuthoritative) {
                removeMemberFromAuthoritativeGroup(sess, group, memberToRemove);
            } else {
                getPerunBl().getGroupsManagerBl().removeMember(sess, group, memberToRemove);
                log.info("Group synchronization {}: Member id {} removed.", group, memberToRemove.getId());
            }
        }
    } catch (NotGroupMemberException e) {
        throw new ConsistencyErrorException("Trying to remove non-existing user");
    } catch (MemberAlreadyRemovedException ex) {
        // Member was probably removed before starting of synchronization removing process, log it and skip this member
        log.debug("Member {} was removed from group {} before removing process. Skip this member.", memberToRemove, group);
    }
}
Also used : NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException)

Example 4 with NotGroupMemberException

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

the class BBMRICollections method approveApplication.

/**
 * Find groups representing collections by input. Groups are looked for in subgroups
 * of group the module is assigned to. Add user as a member to the groups.
 *
 * @param session who approves the application
 * @param app application
 * @return unchanged application
 * @throws PerunException in case of internal error in Perun
 */
@Override
public Application approveApplication(PerunSession session, Application app) throws VoNotExistsException, UserNotExistsException, PrivilegeException, MemberNotExistsException, RegistrarException, GroupNotExistsException, AttributeNotExistsException, WrongAttributeAssignmentException, ExternallyManagedException, WrongAttributeValueException, WrongReferenceAttributeValueException, NotGroupMemberException {
    // get perun and beans from session
    PerunBl perun = (PerunBl) session.getPerun();
    Vo vo = app.getVo();
    User user = app.getUser();
    Member member = perun.getMembersManagerBl().getMemberByUser(session, vo, user);
    // get the field of application with the collections
    Set<String> collectionIDsInApplication = getCollectionIDsFromApplication(session, app);
    // get map of collection IDs to group from Perun
    String directoryGroupName = this.getDirectoryGroupNameFromApplication(session, app);
    Group directoryGroup;
    try {
        directoryGroup = perun.getGroupsManager().getGroupByName(session, vo, directoryGroupName);
    } catch (GroupNotExistsException e) {
        throw new InternalErrorException("Target group does not exist");
    }
    Map<String, Group> collectionIDsToGroupsMap = getCollectionIDsToGroupsMap(session, perun, directoryGroup);
    // add user to all groups from the field on application
    for (String collectionID : collectionIDsInApplication) {
        Group collection = collectionIDsToGroupsMap.get(collectionID);
        if (collection == null) {
            log.debug("There are no groups for collectionID: {}", collectionID);
        } else {
            try {
                perun.getGroupsManager().addMember(session, collection, member);
            } catch (AlreadyMemberException ex) {
            // ignore
            }
        }
    }
    try {
        perun.getGroupsManager().removeMember(session, app.getGroup(), member);
    } catch (MemberNotExistsException | NotGroupMemberException e) {
    // we can ignore these exceptions
    }
    return app;
}
Also used : MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) AlreadyMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException)

Example 5 with NotGroupMemberException

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

the class MembersManagerBlImpl method deleteMember.

@Override
public void deleteMember(PerunSession sess, Member member) throws MemberAlreadyRemovedException {
    Vo vo = this.getMemberVo(sess, member);
    // Remove member from all groups
    List<Group> memberGroups = getPerunBl().getGroupsManagerBl().getMemberDirectGroups(sess, member);
    for (Group group : memberGroups) {
        // Member must be removed from the members group using separate method
        if (group.getName().equals(VosManager.MEMBERS_GROUP))
            continue;
        try {
            getPerunBl().getGroupsManagerBl().removeMember(sess, group, member);
        } catch (NotGroupMemberException e) {
            throw new ConsistencyErrorException("getMemberGroups return group where the member is not member", e);
        } catch (GroupNotExistsException e) {
            throw new ConsistencyErrorException(e);
        }
    }
    // Remove member from the VO members group
    try {
        Group g = getPerunBl().getGroupsManagerBl().getGroupByName(sess, vo, VosManager.MEMBERS_GROUP);
        try {
            getPerunBl().getGroupsManagerBl().removeMemberFromMembersOrAdministratorsGroup(sess, g, member);
        } catch (NotGroupMemberException e) {
            throw new ConsistencyErrorException("Member is not in the \"members\" group." + member + "  " + g, e);
        } catch (WrongAttributeValueException | WrongReferenceAttributeValueException e) {
            throw new InternalErrorException(e);
        }
    } catch (GroupNotExistsException e) {
        throw new InternalErrorException(e);
    }
    // Remove member's  attributes (namespaces: member and resource-member)
    try {
        getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, member);
        List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
        for (Resource resource : resources) {
            getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, member, resource);
        }
    } catch (AttributeValueException ex) {
        throw new ConsistencyErrorException("Member is removed from all groups. There are no required attribute for this member. Member's attributes can be removed without problem.", ex);
    } catch (MemberResourceMismatchException ex) {
        throw new InternalErrorException(ex);
    }
    removeAllMemberBans(sess, member);
    // Remove possible links to member's sponsors
    membersManagerImpl.deleteSponsorLinks(sess, member);
    membersManagerImpl.rejectAllMemberOpenApplications(sess, member);
    // Remove member from the DB
    getMembersManagerImpl().deleteMember(sess, member);
    getPerunBl().getAuditer().log(sess, new MemberDeleted(member));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) AttributeValueException(cz.metacentrum.perun.core.api.exceptions.AttributeValueException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Vo(cz.metacentrum.perun.core.api.Vo) BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) MemberDeleted(cz.metacentrum.perun.audit.events.MembersManagerEvents.MemberDeleted) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

NotGroupMemberException (cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException)8 Member (cz.metacentrum.perun.core.api.Member)5 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)4 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)4 RichMember (cz.metacentrum.perun.core.api.RichMember)3 Group (cz.metacentrum.perun.core.api.Group)2 GroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException)2 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)2 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)2 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)2 ArrayList (java.util.ArrayList)2 MemberDeleted (cz.metacentrum.perun.audit.events.MembersManagerEvents.MemberDeleted)1 Attribute (cz.metacentrum.perun.core.api.Attribute)1 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)1 BanOnResource (cz.metacentrum.perun.core.api.BanOnResource)1 BanOnVo (cz.metacentrum.perun.core.api.BanOnVo)1 Candidate (cz.metacentrum.perun.core.api.Candidate)1 MemberCandidate (cz.metacentrum.perun.core.api.MemberCandidate)1 MemberGroupStatus (cz.metacentrum.perun.core.api.MemberGroupStatus)1 Resource (cz.metacentrum.perun.core.api.Resource)1