Search in sources :

Example 21 with GroupResourceMismatchException

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

the class AttributesManagerEntry method fillAttributes.

public List<Attribute> fillAttributes(PerunSession sess, Resource resource, Group group, List<Attribute> attributes, boolean workWithGroupAttributes) throws ResourceNotExistsException, GroupNotExistsException, AttributeNotExistsException, WrongAttributeAssignmentException, GroupResourceMismatchException {
    Utils.checkPerunSession(sess);
    getPerunBl().getResourcesManagerBl().checkResourceExists(sess, resource);
    getPerunBl().getGroupsManagerBl().checkGroupExists(sess, group);
    getAttributesManagerBl().checkAttributesExists(sess, attributes);
    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
    List<Attribute> listOfAttributes = getAttributesManagerBl().fillAttributes(sess, resource, group, attributes, workWithGroupAttributes);
    Iterator<Attribute> attrIter = listOfAttributes.iterator();
    while (attrIter.hasNext()) {
        Attribute attrNext = attrIter.next();
        if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_GROUP_ATTR)) {
            if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, new AttributeDefinition(attrNext), group)) {
                attrIter.remove();
            } else {
                attrNext.setWritable(true);
            }
        } else if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_GROUP_RESOURCE_ATTR)) {
            if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, new AttributeDefinition(attrNext), group, resource)) {
                attrIter.remove();
            } else {
                attrNext.setWritable(true);
            }
        } else {
            throw new ConsistencyErrorException("There is some attribute which is not type of any possible choice.");
        }
    }
    return listOfAttributes;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)

Example 22 with GroupResourceMismatchException

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

the class AttributesManagerEntry method checkAttributesSemantics.

@Override
public void checkAttributesSemantics(PerunSession sess, Resource resource, Group group, List<Attribute> attributes) throws PrivilegeException, AttributeNotExistsException, ResourceNotExistsException, GroupNotExistsException, WrongAttributeAssignmentException, GroupResourceMismatchException, WrongReferenceAttributeValueException {
    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 (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, new AttributeDefinition(attr), group, resource))
            throw new PrivilegeException("Principal has no access to check attribute = " + new AttributeDefinition(attr));
    }
    getAttributesManagerBl().checkAttributesSemantics(sess, resource, group, attributes);
}
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)

Example 23 with GroupResourceMismatchException

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

the class AttributesManagerEntry method getAttribute.

@Override
public Attribute getAttribute(PerunSession sess, Resource resource, Group group, String attributeName) throws PrivilegeException, AttributeNotExistsException, ResourceNotExistsException, GroupNotExistsException, WrongAttributeAssignmentException, GroupResourceMismatchException {
    Utils.checkPerunSession(sess);
    Utils.notNull(attributeName, "attributeName");
    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");
    }
    Attribute attr = getAttributesManagerBl().getAttribute(sess, resource, group, attributeName);
    // Choose to which attributes has the principal access
    if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attr, group, resource))
        throw new PrivilegeException("Principal has no access to get attribute = " + new AttributeDefinition(attr));
    else
        attr.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attr, group, resource));
    return attr;
}
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)

Example 24 with GroupResourceMismatchException

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

the class AttributesManagerEntry method setAttributes.

@Override
public void setAttributes(PerunSession sess, Resource resource, Group group, List<Attribute> attributes, boolean workWithGroupAttributes) throws ResourceNotExistsException, GroupNotExistsException, WrongAttributeAssignmentException, WrongAttributeValueException, AttributeNotExistsException, WrongReferenceAttributeValueException, PrivilegeException, GroupResourceMismatchException {
    Utils.checkPerunSession(sess);
    getPerunBl().getResourcesManagerBl().checkResourceExists(sess, resource);
    getPerunBl().getGroupsManagerBl().checkGroupExists(sess, group);
    getAttributesManagerBl().checkAttributesExists(sess, attributes);
    if (!getPerunBl().getGroupsManagerBl().getVo(sess, group).equals(getPerunBl().getResourcesManagerBl().getVo(sess, resource))) {
        throw new GroupResourceMismatchException("group and resource are not in the same VO");
    }
    for (Attribute attr : attributes) {
        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 set attribute = " + new AttributeDefinition(attr));
        } else 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 set attribute = " + new AttributeDefinition(attr));
        } else {
            throw new WrongAttributeAssignmentException("One of setting attribute has not correct type : " + new AttributeDefinition(attr));
        }
    }
    getAttributesManagerBl().setAttributes(sess, resource, group, attributes, workWithGroupAttributes);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)

Example 25 with GroupResourceMismatchException

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

the class AttributesManagerEntry method getAttributeById.

@Override
public Attribute getAttributeById(PerunSession sess, Resource resource, Group group, int id) throws PrivilegeException, AttributeNotExistsException, ResourceNotExistsException, GroupNotExistsException, WrongAttributeAssignmentException, 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");
    }
    Attribute attr = getAttributesManagerBl().getAttributeById(sess, resource, group, id);
    // Choose to which attributes has the principal access
    if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attr, group, resource))
        throw new PrivilegeException("Principal has no access to get attribute = " + new AttributeDefinition(attr));
    else
        attr.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attr, group, resource));
    return attr;
}
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