Search in sources :

Example 16 with GroupResourceMismatchException

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

the class urn_perun_group_resource_attribute_def_def_systemUnixGroupName method checkAttributeSemantics.

@Override
public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    String groupName = attribute.valueAsString();
    Attribute isSystemGroup;
    if (groupName == null) {
        try {
            isSystemGroup = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, A_GR_systemIsUnixGroup);
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException("Not exist Attribute " + A_GR_systemIsUnixGroup + " for group " + group, ex);
        } catch (GroupResourceMismatchException ex) {
            throw new InternalErrorException(ex);
        }
        if (isSystemGroup.getValue() != null && isSystemGroup.valueAsInteger() == 1) {
            throw new WrongReferenceAttributeValueException(attribute, isSystemGroup, group, resource, "Attribute cant be null if " + group + " on " + resource + " is system unix group.");
        }
        return;
    }
    // Get facility for the resource
    Facility facility = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
    // List of pairs (group and resource) which has the attribute with the value
    List<Pair<Group, Resource>> listGroupPairsResource = sess.getPerunBl().getGroupsManagerBl().getGroupResourcePairsByAttribute(sess, attribute);
    // Searching through all pairs and if is not checking group/resource/attribute, then try for being on the same facility, if yes then throw exception but only if these groups have not the same GID too.
    for (Pair<Group, Resource> p : listGroupPairsResource) {
        if (!p.getLeft().equals(group) || !p.getRight().equals(resource)) {
            Facility facilityForTest = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, p.getRight());
            Attribute group1GID;
            Attribute group2GID;
            try {
                group1GID = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, A_GR_systemUnixGID);
            } catch (AttributeNotExistsException ex) {
                throw new ConsistencyErrorException("Attribute " + A_GR_systemUnixGID + " not exists for group " + group + " and resource " + resource, ex);
            } catch (GroupResourceMismatchException ex) {
                throw new InternalErrorException(ex);
            }
            try {
                group2GID = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, p.getRight(), p.getLeft(), A_GR_systemUnixGID);
            } catch (AttributeNotExistsException ex) {
                throw new ConsistencyErrorException("Attribute " + A_GR_systemUnixGID + " not exists for group " + p.getLeft() + " and resource " + p.getRight(), ex);
            } catch (GroupResourceMismatchException ex) {
                throw new InternalErrorException(ex);
            }
            if (facilityForTest.equals(facility) && (group1GID.getValue() != null ? (!group1GID.getValue().equals(group2GID.getValue())) : group2GID != null)) {
                throw new WrongReferenceAttributeValueException(attribute, attribute, group, resource, "Group name " + groupName + "is already used by another group-resource and these have not the same GID and GroupName.  " + p.getLeft() + " " + p.getRight());
            }
        }
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Facility(cz.metacentrum.perun.core.api.Facility) Pair(cz.metacentrum.perun.core.api.Pair)

Example 17 with GroupResourceMismatchException

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

the class GenDataProviderImpl method loadGroupsAttributes.

@Override
public void loadGroupsAttributes(Resource resource, List<Group> groups) {
    groupResourceAttrs = new HashMap<>();
    lastLoadedResource = resource;
    for (Group group : groups) {
        try {
            // FIXME - attributes could be loaded at once to get a better performance
            groupResourceAttrs.put(group, sess.getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource, group));
        } catch (GroupResourceMismatchException e) {
            throw new InternalErrorException(e);
        }
    }
    List<Group> notYetProcessedGroups = new ArrayList<>(groups);
    notYetProcessedGroups.removeAll(processedGroups);
    processedGroups.addAll(notYetProcessedGroups);
    groupAttrs.putAll(sess.getPerunBl().getAttributesManagerBl().getRequiredAttributesForGroups(sess, service, notYetProcessedGroups));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)

Example 18 with GroupResourceMismatchException

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

the class GroupsManagerBlImpl method autoassignMovedTree.

/**
 * Checks, if moved group and subgroups should be automatically assigned to any group
 * @param sess
 * @param destinationGroup
 * @param movingGroup
 * @throws WrongReferenceAttributeValueException
 * @throws WrongAttributeValueException
 */
private void autoassignMovedTree(PerunSession sess, Group destinationGroup, Group movingGroup) throws WrongReferenceAttributeValueException, WrongAttributeValueException {
    List<AssignedResource> resourcesToAutoassign = perunBl.getResourcesManagerBl().getResourceAssignments(sess, destinationGroup, List.of()).stream().filter(AssignedResource::isAutoAssignSubgroups).collect(toList());
    for (AssignedResource resourceToAutoassign : resourcesToAutoassign) {
        Group sourceGroup;
        try {
            sourceGroup = resourceToAutoassign.getSourceGroupId() == null ? destinationGroup : this.getGroupById(sess, resourceToAutoassign.getSourceGroupId());
        } catch (GroupNotExistsException e) {
            throw new ConsistencyErrorException(e);
        }
        List<Group> groupsToAutoAssign = perunBl.getGroupsManagerBl().getAllSubGroups(sess, movingGroup);
        groupsToAutoAssign.add(movingGroup);
        for (Group groupToAutoassign : groupsToAutoAssign) {
            try {
                perunBl.getResourcesManagerBl().assignAutomaticGroupToResource(sess, sourceGroup, groupToAutoassign, resourceToAutoassign.getEnrichedResource().getResource());
            } catch (GroupAlreadyAssignedException e) {
            // skip
            } catch (GroupResourceMismatchException e) {
                log.error("Could not autoassign group " + groupToAutoassign + " to resource " + resourceToAutoassign, e);
            }
        }
    }
}
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) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource)

Example 19 with GroupResourceMismatchException

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

the class AttributesManagerEntry method getRequiredAttributes.

@Override
public List<Attribute> getRequiredAttributes(PerunSession sess, Service service, Resource resource, Group group) throws ServiceNotExistsException, ResourceNotExistsException, GroupNotExistsException, GroupResourceMismatchException {
    Utils.checkPerunSession(sess);
    getPerunBl().getServicesManagerBl().checkServiceExists(sess, service);
    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().getRequiredAttributes(sess, service, 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, 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) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)

Example 20 with GroupResourceMismatchException

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

the class AttributesManagerEntry method checkAttributesSyntax.

public void checkAttributesSyntax(PerunSession sess, Resource resource, Group group, List<Attribute> attributes, boolean workWithGroupAttribute) throws PrivilegeException, AttributeNotExistsException, ResourceNotExistsException, GroupNotExistsException, WrongAttributeAssignmentException, WrongAttributeValueException, GroupResourceMismatchException {
    Utils.checkPerunSession(sess);
    getAttributesManagerBl().checkAttributesExists(sess, attributes);
    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");
    }
    // Choose to which attributes has the principal access
    for (Attribute attr : attributes) {
        if (getAttributesManagerBl().isFromNamespace(sess, attr, NS_GROUP_RESOURCE_ATTR)) {
            if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, new AttributeDefinition(attr), group, resource))
                throw new PrivilegeException("Principal has no access to check attribute = " + new AttributeDefinition(attr));
        } else if (getAttributesManagerBl().isFromNamespace(sess, attr, NS_GROUP_ATTR)) {
            if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, new AttributeDefinition(attr), group))
                throw new PrivilegeException("Principal has no access to check attribute = " + new AttributeDefinition(attr));
        }
    }
    getAttributesManagerBl().checkAttributesSyntax(sess, resource, group, attributes, workWithGroupAttribute);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) 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