Search in sources :

Example 61 with Attribute

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

the class AttributesManagerBlImpl method setAttributeWithoutCheck.

@Override
public boolean setAttributeWithoutCheck(PerunSession sess, Resource resource, Group group, Attribute attribute) throws WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException, GroupResourceMismatchException {
    this.checkGroupIsFromTheSameVoLikeResource(sess, group, resource);
    getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_GROUP_RESOURCE_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed;
    if (isVirtAttribute(sess, attribute)) {
        // FIXME Zatim je zakazane nastavovani virtualnich atributu group_resource
        Attribute storedAttribute;
        try {
            storedAttribute = getAttribute(sess, resource, group, attribute.getName());
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException(ex);
        }
        if (!(storedAttribute.getValue() == null ? attribute.getValue() == null : storedAttribute.getValue().equals(attribute.getValue()))) {
            // FIXME
            if (attribute.getName().equals(AttributesManager.NS_GROUP_RESOURCE_ATTR_VIRT + ":unixGID") || attribute.getName().equals(AttributesManager.NS_GROUP_RESOURCE_ATTR_VIRT + ":unixGroupName")) {
                return getAttributesManagerImpl().setVirtualAttribute(sess, resource, group, attribute);
            } else {
                throw new InternalErrorException("Virtual attribute can't be set this way yet. Please set physical attribute. " + attribute);
            }
        } else {
            return false;
        }
    } else {
        changed = getAttributesManagerImpl().setAttribute(sess, resource, group, attribute);
    }
    if (changed) {
        getPerunBl().getAuditer().log(sess, new AttributeSetForGroupAndResource(attribute, group, resource));
        getAttributesManagerImpl().changedAttributeHook(sess, resource, group, attribute);
    }
    return changed;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) AttributeSetForGroupAndResource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForGroupAndResource)

Example 62 with Attribute

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

the class AttributesManagerBlImpl method getAttributeById.

@Override
public Attribute getAttributeById(PerunSession sess, Group group, int id) throws WrongAttributeAssignmentException, AttributeNotExistsException {
    Attribute attribute = getAttributesManagerImpl().getAttributeById(sess, group, id);
    getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_GROUP_ATTR);
    return attribute;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute)

Example 63 with Attribute

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

the class AttributesManagerBlImpl method getUserFacilityAttributes.

/**
 * Returns all relevant UserFacility RichAttributes for given group and member.
 * That means, returns all UserFacility rich attributes for user of the given member and for facilities this member
 * can access via the given group.
 * If the given member is not allowed, returns an empty list.
 * Each rich attribute is returned only once.
 *
 * @param sess    session
 * @param member  member
 * @param group   group
 * @param attrDef type of attribute that will be returned
 * @return List of RichAttribute
 */
private List<RichAttribute> getUserFacilityAttributes(PerunSession sess, Member member, Group group, AttributeDefinition attrDef) throws AttributeNotExistsException, WrongAttributeAssignmentException {
    List<RichAttribute> listOfRichAttributes = new ArrayList<>();
    if (getPerunBl().getMembersManagerBl().isMemberAllowed(sess, member)) {
        List<Resource> resourcesFromGroup = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
        List<Facility> facilitiesFromResources = new ArrayList<>();
        for (Resource resourceElement : resourcesFromGroup) {
            facilitiesFromResources.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElement));
        }
        facilitiesFromResources = new ArrayList<>(new HashSet<>(facilitiesFromResources));
        User userFromMember = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
        for (Facility facilityElement : facilitiesFromResources) {
            Attribute attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facilityElement, userFromMember, attrDef.getName());
            listOfRichAttributes.add(new RichAttribute<>(facilityElement, userFromMember, attribute));
        }
    }
    listOfRichAttributes = new ArrayList<>(new HashSet<>(listOfRichAttributes));
    return listOfRichAttributes;
}
Also used : User(cz.metacentrum.perun.core.api.User) AllUserFacilityAttributesRemovedForFacilitiesAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllUserFacilityAttributesRemovedForFacilitiesAndUser) AttributeRemovedForFacilityAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForFacilityAndUser) AttributeSetForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser) AllAttributesRemovedForFacilityAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForFacilityAndUser) AttributeSetForFacilityAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForFacilityAndUser) AttributeRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForUser) AllAttributesRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUser) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) AttributeSetForGroupAndResource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForGroupAndResource) AttributeRemovedForGroupAndResource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForGroupAndResource) AllAttributesRemovedForResource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForResource) AttributeRemovedForResource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForResource) Resource(cz.metacentrum.perun.core.api.Resource) AttributeSetForResource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForResource) AllAttributesRemovedForGroupAndResource(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForGroupAndResource) AttributeRemovedForFacility(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForFacility) Facility(cz.metacentrum.perun.core.api.Facility) AttributeSetForFacility(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForFacility) HashSet(java.util.HashSet)

Example 64 with Attribute

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

the class AttributesManagerBlImpl method removeAttributeWithoutCheck.

private boolean removeAttributeWithoutCheck(PerunSession sess, UserExtSource ues, AttributeDefinition attribute) throws WrongAttributeAssignmentException {
    getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_UES_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed = getAttributesManagerImpl().removeAttribute(sess, ues, attribute);
    if (changed) {
        getAttributesManagerImpl().changedAttributeHook(sess, ues, new Attribute(attribute));
        log.info("{} removed attribute {} from user external source {}.", sess.getLogId(), attribute.getName(), ues.getId());
        getPerunBl().getAuditer().log(sess, new AttributeRemovedForUes(new AttributeDefinition(attribute), ues));
    }
    return changed;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeRemovedForUes(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForUes) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Example 65 with Attribute

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

the class AttributesManagerBlImpl method getMemberGroupAttributes.

/**
 * Returns all relevant MemberGroup RichAttributes for given member and resource.
 * That means, returns all MemberGroup rich attributes for the given member and groups that can access the given resource.
 * If the member is not allowed, an empty list is returned.
 * Each rich attribute is returned only once.
 *
 * @param sess     session
 * @param member   member
 * @param resource resource
 * @param attrDef  type of attribute that will be returned
 * @return List of RichAttribute
 */
private List<RichAttribute> getMemberGroupAttributes(PerunSession sess, Member member, Resource resource, AttributeDefinition attrDef) throws AttributeNotExistsException, WrongAttributeAssignmentException, MemberGroupMismatchException {
    List<RichAttribute> listOfRichAttributes = new ArrayList<>();
    // If member is not allowed, skip whole process
    if (!getPerunBl().getMembersManagerBl().isMemberAllowed(sess, member))
        return listOfRichAttributes;
    List<Group> groupFromMembers = new ArrayList<>();
    if (getPerunBl().getMembersManagerBl().isMemberAllowed(sess, member)) {
        groupFromMembers = getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, member);
    }
    List<Group> groupsFromResources = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resource);
    groupsFromResources.retainAll(groupFromMembers);
    groupsFromResources = new ArrayList<>(new HashSet<>(groupsFromResources));
    for (Group groupElement : groupsFromResources) {
        Attribute attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, member, groupElement, attrDef.getName());
        listOfRichAttributes.add(new RichAttribute<>(member, groupElement, attribute));
    }
    listOfRichAttributes = new ArrayList<>(new HashSet<>(listOfRichAttributes));
    return listOfRichAttributes;
}
Also used : AllAttributesRemovedForMemberAndGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForMemberAndGroup) AttributeRemovedForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForGroup) AllAttributesRemovedForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForGroup) AttributeSetForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForGroup) Group(cz.metacentrum.perun.core.api.Group) AttributeSetForMemberAndGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForMemberAndGroup) AttributeRemovedForMemberAndGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForMemberAndGroup) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

Attribute (cz.metacentrum.perun.core.api.Attribute)1689 Test (org.junit.Test)615 ArrayList (java.util.ArrayList)492 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)489 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)478 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)313 User (cz.metacentrum.perun.core.api.User)301 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)280 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)231 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)221 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)218 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)197 Facility (cz.metacentrum.perun.core.api.Facility)190 Resource (cz.metacentrum.perun.core.api.Resource)187 PerunSessionImpl (cz.metacentrum.perun.core.impl.PerunSessionImpl)180 List (java.util.List)177 LinkedHashMap (java.util.LinkedHashMap)158 Before (org.junit.Before)156 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)145 Method (java.lang.reflect.Method)140