Search in sources :

Example 1 with MemberGroupMismatchException

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

the class AttributesManagerBlImpl method checkMemberIsFromTheSameVoLikeGroup.

/**
 * Check if Member is from the same VO like Group. If not, throw MemberGroupMismatchException
 */
private void checkMemberIsFromTheSameVoLikeGroup(PerunSession sess, Member member, Group group) throws MemberGroupMismatchException {
    Utils.notNull(sess, "sess");
    Utils.notNull(member, "member");
    Utils.notNull(group, "group");
    if (member.getVoId() != group.getVoId())
        throw new MemberGroupMismatchException("Member is not from the same vo like Group: " + member + " " + group, member, group);
}
Also used : MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException)

Example 2 with MemberGroupMismatchException

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

the class MembersManagerBlImpl method getMembersPage.

@Override
public Paginated<RichMember> getMembersPage(PerunSession sess, Vo vo, MembersPageQuery query, List<String> attrNames) {
    Paginated<Member> paginatedMembers = membersManagerImpl.getMembersPage(sess, vo, query);
    List<RichMember> richMembers = convertMembersToRichMembers(sess, paginatedMembers.getData());
    List<AttributeDefinition> attrDefs = new ArrayList<>();
    for (String attrsName : attrNames) {
        try {
            attrDefs.add(getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, attrsName));
        } catch (AttributeNotExistsException e) {
        // pass
        }
    }
    if (query.getGroupId() == null) {
        richMembers = convertMembersToRichMembersWithAttributes(sess, richMembers, attrDefs);
    } else {
        try {
            richMembers = convertMembersToRichMembersWithAttributes(sess, perunBl.getGroupsManagerBl().getGroupById(sess, query.getGroupId()), richMembers, attrDefs);
        } catch (GroupNotExistsException | MemberGroupMismatchException e) {
            throw new InternalErrorException(e);
        }
    }
    return new Paginated<>(richMembers, paginatedMembers.getOffset(), paginatedMembers.getPageSize(), paginatedMembers.getTotalCount());
}
Also used : MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RichMember(cz.metacentrum.perun.core.api.RichMember) Paginated(cz.metacentrum.perun.core.api.Paginated) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Example 3 with MemberGroupMismatchException

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

the class MembersManagerBlImpl method moveMembersAttributes.

/**
 * Moves member related attributes from source member to target member.
 *
 * @param sess
 * @param vo VO where sourceUser and targetUser are members
 * @param sourceMember member to move attributes from
 * @param targetMember member to move attributes to
 * @param groups groups for which move member-group attributes
 */
private void moveMembersAttributes(PerunSession sess, Vo vo, Member sourceMember, Member targetMember, List<Group> groups) {
    try {
        // set member attributes
        List<Attribute> memberAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, sourceMember);
        for (Attribute attribute : memberAttributes) {
            if (!getPerunBl().getAttributesManagerBl().isVirtAttribute(sess, attribute) && !getPerunBl().getAttributesManagerBl().isCoreAttribute(sess, attribute))
                getPerunBl().getAttributesManagerBl().setAttribute(sess, targetMember, attribute);
        }
        // set member-group attributes
        for (Group group : groups) {
            List<Attribute> groupMemberAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, sourceMember, group);
            for (Attribute attribute : groupMemberAttributes) {
                if (!getPerunBl().getAttributesManagerBl().isVirtAttribute(sess, attribute)) {
                    getPerunBl().getAttributesManagerBl().setAttribute(sess, targetMember, group, attribute);
                }
            }
        }
        // set member-resource attributes
        List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
        for (Resource resource : resources) {
            List<Attribute> memberResourceAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, sourceMember, resource);
            for (Attribute attribute : memberResourceAttributes) {
                if (!getPerunBl().getAttributesManagerBl().isVirtAttribute(sess, attribute)) {
                    getPerunBl().getAttributesManagerBl().setAttribute(sess, targetMember, resource, attribute);
                }
            }
        }
    } catch (WrongAttributeValueException | WrongAttributeAssignmentException | WrongReferenceAttributeValueException | MemberGroupMismatchException | MemberResourceMismatchException e) {
        throw new InternalErrorException(e);
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Resource(cz.metacentrum.perun.core.api.Resource) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 4 with MemberGroupMismatchException

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

the class AttributesManagerEntry method getResourceRequiredAttributes.

@Override
public List<Attribute> getResourceRequiredAttributes(PerunSession sess, Resource resourceToGetServicesFrom, Resource resource, Group group, Member member, boolean workWithUserAttributes) throws ResourceNotExistsException, GroupNotExistsException, GroupResourceMismatchException, MemberNotExistsException, MemberGroupMismatchException, UserNotExistsException, FacilityNotExistsException, MemberResourceMismatchException {
    Utils.checkPerunSession(sess);
    getPerunBl().getResourcesManagerBl().checkResourceExists(sess, resourceToGetServicesFrom);
    getPerunBl().getResourcesManagerBl().checkResourceExists(sess, resource);
    getPerunBl().getGroupsManagerBl().checkGroupExists(sess, group);
    getPerunBl().getMembersManagerBl().checkMemberExists(sess, member);
    if (group.getVoId() != resource.getVoId()) {
        throw new GroupResourceMismatchException("Group and resource are not in the same VO.");
    }
    if (member.getVoId() != group.getVoId()) {
        throw new MemberGroupMismatchException("Member and Group are not in the same VO.", member, group);
    }
    List<Attribute> attributes = getAttributesManagerBl().getResourceRequiredAttributes(sess, resourceToGetServicesFrom, member, resource, workWithUserAttributes);
    attributes.addAll(getAttributesManagerBl().getResourceRequiredAttributes(sess, resourceToGetServicesFrom, member, group));
    User user = getPerunBl().getUsersManagerBl().getUserById(sess, member.getUserId());
    Facility facility = getPerunBl().getFacilitiesManagerBl().getFacilityById(sess, resource.getFacilityId());
    Iterator<Attribute> attrIter = attributes.iterator();
    // Choose to which attributes has the principal access
    while (attrIter.hasNext()) {
        Attribute attrNext = attrIter.next();
        if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_MEMBER_ATTR)) {
            if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, member))
                attrIter.remove();
            else
                attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, member));
        } else if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_USER_ATTR)) {
            if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, user))
                attrIter.remove();
            else
                attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, user));
        } else if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_MEMBER_GROUP_ATTR)) {
            if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, member, group))
                attrIter.remove();
            else
                attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, member, group));
        } else if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_MEMBER_RESOURCE_ATTR)) {
            if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, member, resource))
                attrIter.remove();
            else
                attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, member, resource));
        } else if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_USER_FACILITY_ATTR)) {
            if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, user, facility))
                attrIter.remove();
            else
                attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, user, facility));
        } else {
            throw new ConsistencyErrorException("There is some attribute which is not of expected type (member, user, user_facility, member_group, member_resource).");
        }
    }
    return attributes;
}
Also used : 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) Facility(cz.metacentrum.perun.core.api.Facility) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)

Example 5 with MemberGroupMismatchException

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

the class MembersManagerBlImpl method getRichMembersWithAttributesByNames.

@Override
public List<RichMember> getRichMembersWithAttributesByNames(PerunSession sess, Group group, Resource resource, List<String> attrsNames) throws AttributeNotExistsException, GroupResourceMismatchException {
    getPerunBl().getAttributesManagerBl().checkGroupIsFromTheSameVoLikeResource(sess, group, resource);
    List<Member> members = new ArrayList<>(perunBl.getGroupsManagerBl().getGroupMembers(sess, group));
    List<RichMember> richMembers = this.convertMembersToRichMembers(sess, members);
    List<AttributeDefinition> attrsDef = new ArrayList<>();
    for (String atrrName : attrsNames) {
        AttributeDefinition attrDef = perunBl.getAttributesManagerBl().getAttributeDefinition(sess, atrrName);
        attrsDef.add(attrDef);
    }
    List<RichMember> richMembersWithAttributes;
    try {
        richMembersWithAttributes = this.convertMembersToRichMembersWithAttributes(sess, group, resource, richMembers, attrsDef);
    } catch (MemberResourceMismatchException | MemberGroupMismatchException ex) {
        throw new ConsistencyErrorException(ex);
    }
    return richMembersWithAttributes;
}
Also used : MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) RichMember(cz.metacentrum.perun.core.api.RichMember)

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