Search in sources :

Example 1 with GroupResourceMismatchException

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

the class ResourcesManagerBlImpl method assignServices.

@Override
public void assignServices(PerunSession sess, Resource resource, List<Service> services) throws ServiceAlreadyAssignedException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    for (Service service : services) {
        getResourcesManagerImpl().assignService(sess, resource, service);
        getPerunBl().getAuditer().log(sess, new ServiceAssignedToResource(service, resource));
    }
    boolean requiresAttributes = services.stream().anyMatch(s -> !getPerunBl().getAttributesManagerBl().getRequiredAttributesDefinition(sess, s).isEmpty());
    if (!requiresAttributes) {
        // there are new no attributes to check or add
        return;
    }
    try {
        fillAndSetRequiredAttributesForGroups(sess, services, resource);
        checkSemanticsOfFacilityAndResourceRequiredAttributes(sess, resource);
        updateAllRequiredAttributesForAllowedMembers(sess, resource, services);
    } catch (WrongAttributeAssignmentException | GroupResourceMismatchException | MemberResourceMismatchException | AttributeNotExistsException e) {
        throw new ConsistencyErrorException(e);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) ServiceAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Service(cz.metacentrum.perun.core.api.Service) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)

Example 2 with GroupResourceMismatchException

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

the class ResourcesManagerBlImpl method processGroupResourceActivation.

/**
 * Sets assignment status of given group and resource to ACTIVE. Check if attributes for each member
 * from group are valid. Fill members' attributes with missing values.
 *
 * @param sess session
 * @param group group
 * @param resource resource
 * @throws WrongAttributeValueException when an attribute value has wrong/illegal syntax
 * @throws WrongReferenceAttributeValueException when an attribute value has wrong/illegal semantics
 * @throws GroupResourceMismatchException when the given group and resource are not from the same VO
 * @throws GroupNotDefinedOnResourceException when there is no such group-resource assignment
 */
private void processGroupResourceActivation(PerunSession sess, Group group, Resource resource) throws GroupResourceMismatchException, WrongReferenceAttributeValueException, WrongAttributeValueException, GroupNotDefinedOnResourceException {
    getPerunBl().getAttributesManagerBl().checkGroupIsFromTheSameVoLikeResource(sess, group, resource);
    // set status as ACTIVE first because methods checkAttributesSemantics and fillAttribute need active state to work correctly
    getResourcesManagerImpl().setGroupResourceStatus(sess, group, resource, GroupResourceStatus.ACTIVE);
    // reset assignment failure cause
    getResourcesManagerImpl().setFailedGroupResourceAssignmentCause(sess, group, resource, null);
    // if there are no services, the members are empty and there is nothing more to process
    if (getAssignedServices(sess, resource).isEmpty()) {
        getPerunBl().getAuditer().log(sess, new GroupAssignedToResource(group, resource));
        return;
    }
    // get/fill/set all required group and group-resource attributes
    try {
        List<Attribute> attributes = getPerunBl().getAttributesManagerBl().getResourceRequiredAttributes(sess, resource, resource, group, true);
        attributes = getPerunBl().getAttributesManagerBl().fillAttributes(sess, resource, group, attributes, true);
        getPerunBl().getAttributesManagerBl().setAttributes(sess, resource, group, attributes, true);
    } catch (WrongAttributeAssignmentException | GroupResourceMismatchException ex) {
        throw new ConsistencyErrorException(ex);
    }
    List<Member> members = getPerunBl().getGroupsManagerBl().getGroupMembersExceptInvalidAndDisabled(sess, group);
    // get all "allowed" group members and get/fill/set required attributes for them
    Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
    for (Member member : members) {
        User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
        try {
            getPerunBl().getAttributesManagerBl().setRequiredAttributes(sess, facility, resource, user, member, true);
        } catch (WrongAttributeAssignmentException | MemberResourceMismatchException | AttributeNotExistsException ex) {
            throw new ConsistencyErrorException(ex);
        }
    }
    getPerunBl().getAuditer().log(sess, new GroupAssignedToResource(group, resource));
// TODO: set and check member-group attributes
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) ResourceSelfServiceRemovedForUser(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceSelfServiceRemovedForUser) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) GroupAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupAssignedToResource) Facility(cz.metacentrum.perun.core.api.Facility) RichMember(cz.metacentrum.perun.core.api.RichMember) AssignedMember(cz.metacentrum.perun.core.api.AssignedMember) Member(cz.metacentrum.perun.core.api.Member)

Example 3 with GroupResourceMismatchException

use of cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException 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 4 with GroupResourceMismatchException

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

the class ResourcesManagerBlImpl method assignGroupsToResource.

@Override
public void assignGroupsToResource(PerunSession perunSession, Iterable<Group> groups, Resource resource, boolean async, boolean assignInactive, boolean autoAssignSubgroups) throws WrongAttributeValueException, WrongReferenceAttributeValueException, GroupResourceMismatchException {
    for (Group g : groups) {
        getPerunBl().getAttributesManagerBl().checkGroupIsFromTheSameVoLikeResource(perunSession, g, resource);
        // assign source group
        try {
            getResourcesManagerImpl().assignGroupToResource(perunSession, g, resource, autoAssignSubgroups);
            setAssignedGroupStatusAndActivate(perunSession, resource, async, assignInactive, g);
        } catch (GroupAlreadyAssignedException e) {
        // silently skip
        }
        if (autoAssignSubgroups) {
            GroupsManagerBl groupsManager = getPerunBl().getGroupsManagerBl();
            List<Group> subgroups;
            // If it is 'members' group, use all groups from corresponding VO (except for members, they've been assigned already)
            if (g.getName().equals(VosManager.MEMBERS_GROUP)) {
                subgroups = groupsManager.getAllGroups(perunSession, groupsManager.getVo(perunSession, g));
                subgroups.removeIf((group -> group.getName().equals(VosManager.MEMBERS_GROUP)));
            } else {
                subgroups = groupsManager.getAllSubGroups(perunSession, g);
            }
            for (Group subgroup : subgroups) {
                try {
                    assignAutomaticGroupToResource(perunSession, g, subgroup, resource);
                } catch (GroupAlreadyAssignedException e) {
                // silently skip
                }
            }
        }
    }
}
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) 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) GroupsManagerBl(cz.metacentrum.perun.core.bl.GroupsManagerBl) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException)

Example 5 with GroupResourceMismatchException

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

the class AttributesManagerEntry method getAttributes.

@Override
public List<Attribute> getAttributes(PerunSession sess, Resource resource, Group group) throws ResourceNotExistsException, GroupNotExistsException, GroupResourceMismatchException {
    Utils.checkPerunSession(sess);
    getPerunBl().getResourcesManagerBl().checkResourceExists(sess, resource);
    getPerunBl().getGroupsManagerBl().checkGroupExists(sess, group);
    if (!getPerunBl().getGroupsManagerBl().getVo(sess, group).equals(getPerunBl().getResourcesManagerBl().getVo(sess, resource))) {
        throw new GroupResourceMismatchException("group and resource are not in the same VO");
    }
    List<Attribute> attributes = getAttributesManagerBl().getAttributes(sess, resource, group);
    Iterator<Attribute> attrIter = attributes.iterator();
    // Choose to which attributes has the principal access
    while (attrIter.hasNext()) {
        Attribute attrNext = attrIter.next();
        if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, new AttributeDefinition(attrNext), group, resource))
            attrIter.remove();
        else
            attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, group, resource));
    }
    return attributes;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)

Aggregations

GroupResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)43 Attribute (cz.metacentrum.perun.core.api.Attribute)29 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)20 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)18 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)15 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)13 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)12 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)12 Group (cz.metacentrum.perun.core.api.Group)11 Facility (cz.metacentrum.perun.core.api.Facility)9 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)8 Resource (cz.metacentrum.perun.core.api.Resource)7 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)6 AssignedGroup (cz.metacentrum.perun.core.api.AssignedGroup)5 AssignedResource (cz.metacentrum.perun.core.api.AssignedResource)5 Member (cz.metacentrum.perun.core.api.Member)5 Service (cz.metacentrum.perun.core.api.Service)5 ArrayList (java.util.ArrayList)5 GroupAssignedToResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupAssignedToResource)4 User (cz.metacentrum.perun.core.api.User)4