Search in sources :

Example 86 with Facility

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

the class AttributesManagerBlImpl method removeAllUserFacilityAttributes.

public void removeAllUserFacilityAttributes(PerunSession sess, User user) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    List<RichAttribute<User, Facility>> userFacilitiesAttributes = getAttributesManagerImpl().getAllUserFacilityRichAttributes(sess, user);
    //remove all non-virtual attributes
    getAttributesManagerImpl().removeAllUserFacilityAttributes(sess, user);
    getPerunBl().getAuditer().log(sess, "All non-virtual user-facility attributes removed for all facilities and {}", user);
    for (RichAttribute<User, Facility> richAttribute : userFacilitiesAttributes) {
        try {
            checkAttributeValue(sess, richAttribute.getSecondaryHolder(), richAttribute.getPrimaryHolder(), new Attribute(richAttribute.getAttribute()));
            this.checkAttributeDependencies(sess, richAttribute);
        } catch (WrongAttributeAssignmentException ex) {
            throw new ConsistencyErrorException(ex);
        }
    }
    for (RichAttribute<User, Facility> attribute : userFacilitiesAttributes) {
        try {
            getAttributesManagerImpl().changedAttributeHook(sess, attribute.getSecondaryHolder(), attribute.getPrimaryHolder(), new Attribute(attribute.getAttribute()));
        } catch (WrongAttributeValueException ex) {
            //TODO better exception here
            throw new InternalErrorException(ex);
        } catch (WrongReferenceAttributeValueException ex) {
            //TODO better exception here
            throw new InternalErrorException(ex);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Facility(cz.metacentrum.perun.core.api.Facility) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 87 with Facility

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

the class AttributesManagerEntry method getRequiredAttributes.

@Override
public HashMap<Member, List<Attribute>> getRequiredAttributes(PerunSession sess, Service service, Resource resource, List<Member> members, boolean workWithUserAttributes) throws InternalErrorException, WrongAttributeAssignmentException, ServiceNotExistsException, ResourceNotExistsException, MemberNotExistsException, FacilityNotExistsException {
    Utils.checkPerunSession(sess);
    getPerunBl().getServicesManagerBl().checkServiceExists(sess, service);
    getPerunBl().getResourcesManagerBl().checkResourceExists(sess, resource);
    Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
    for (Member member : members) {
        getPerunBl().getMembersManagerBl().checkMemberExists(sess, member);
    }
    HashMap<Member, List<Attribute>> result = getAttributesManagerBl().getRequiredAttributes(sess, service, facility, resource, members, workWithUserAttributes);
    for (Member member : result.keySet()) {
        Iterator<Attribute> attrIter = result.get(member).iterator();
        //Choose to which attributes has the principal access
        User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
        while (attrIter.hasNext()) {
            Attribute attrNext = attrIter.next();
            if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_MEMBER_RESOURCE_ATTR)) {
                if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, resource, member))
                    attrIter.remove();
                else
                    attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, resource, member));
            } else if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_MEMBER_ATTR)) {
                if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, member, null))
                    attrIter.remove();
                else
                    attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, member, null));
            } else if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_USER_ATTR)) {
                if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, user, null))
                    attrIter.remove();
                else
                    attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, user, null));
            } 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 type of any possible choice.");
            }
        }
    }
    return result;
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) Facility(cz.metacentrum.perun.core.api.Facility) Member(cz.metacentrum.perun.core.api.Member)

Example 88 with Facility

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

the class AttributesManagerBlImpl method getResourceRequiredAttributes.

public List<Attribute> getResourceRequiredAttributes(PerunSession sess, Resource resourceToGetServicesFrom, Resource resource, Member member, boolean workWithUserAttributes) throws InternalErrorException, WrongAttributeAssignmentException {
    this.checkMemberIsFromTheSameVoLikeResource(sess, member, resource);
    List<Attribute> attributes = new ArrayList<Attribute>();
    attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, resourceToGetServicesFrom, resource, member));
    if (workWithUserAttributes) {
        User user;
        Facility facility;
        try {
            user = getPerunBl().getUsersManagerBl().getUserById(sess, member.getUserId());
            facility = getPerunBl().getFacilitiesManagerBl().getFacilityById(sess, resource.getFacilityId());
        } catch (UserNotExistsException e) {
            throw new ConsistencyErrorException("Member has non-existent user.", e);
        } catch (FacilityNotExistsException e) {
            throw new ConsistencyErrorException("Resource has non-existent facility.", e);
        }
        attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, resourceToGetServicesFrom, facility, user));
        attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, resourceToGetServicesFrom, user));
        attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, resourceToGetServicesFrom, member));
    }
    return attributes;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) ArrayList(java.util.ArrayList) FacilityNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException) Facility(cz.metacentrum.perun.core.api.Facility)

Example 89 with Facility

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

the class AttributesManagerBlImpl method isTrulyRequiredAttribute.

public boolean isTrulyRequiredAttribute(PerunSession sess, Facility facility, User user, AttributeDefinition attributeDefinition) throws InternalErrorException, WrongAttributeAssignmentException {
    this.checkNamespace(sess, attributeDefinition, NS_USER_FACILITY_ATTR);
    List<Facility> allowedFacilities = getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, user);
    if (!allowedFacilities.contains(facility)) {
        return false;
    } else {
        if (!getAttributesManagerImpl().isAttributeRequiredByFacility(sess, facility, attributeDefinition))
            return false;
        List<Resource> resources = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
        resources.retainAll(getPerunBl().getUsersManagerBl().getAllowedResources(sess, user));
        for (Resource resource : resources) {
            if (getAttributesManagerImpl().isAttributeRequiredByResource(sess, resource, attributeDefinition))
                return true;
        }
        return false;
    }
}
Also used : Resource(cz.metacentrum.perun.core.api.Resource) Facility(cz.metacentrum.perun.core.api.Facility)

Example 90 with Facility

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

the class AttributesManagerBlImpl method removeAttributes.

public void removeAttributes(PerunSession sess, Resource resource, Member member, List<? extends AttributeDefinition> attributes, boolean workWithUserAttributes) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    if (!(workWithUserAttributes)) {
        removeAttributes(sess, resource, member, attributes);
    } else {
        List<AttributeDefinition> attributesToCheck = new ArrayList<AttributeDefinition>();
        for (AttributeDefinition attribute : attributes) {
            if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
                Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
                User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
                if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, resource, member, attribute))
                        attributesToCheck.add(attribute);
                } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_FACILITY_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, facility, user, attribute))
                        attributesToCheck.add(attribute);
                } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, user, attribute))
                        attributesToCheck.add(attribute);
                } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, member, attribute))
                        attributesToCheck.add(attribute);
                } else {
                    throw new WrongAttributeAssignmentException(attribute);
                }
            }
        }
        checkAttributesValue(sess, resource, member, attributesFromDefinitions(attributesToCheck), workWithUserAttributes);
        this.checkAttributesDependencies(sess, resource, member, attributesFromDefinitions(attributesToCheck), workWithUserAttributes);
    }
}
Also used : User(cz.metacentrum.perun.core.api.User) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Facility(cz.metacentrum.perun.core.api.Facility)

Aggregations

Facility (cz.metacentrum.perun.core.api.Facility)188 Test (org.junit.Test)95 User (cz.metacentrum.perun.core.api.User)81 Attribute (cz.metacentrum.perun.core.api.Attribute)75 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)61 Resource (cz.metacentrum.perun.core.api.Resource)52 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)51 ArrayList (java.util.ArrayList)48 Group (cz.metacentrum.perun.core.api.Group)24 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)23 Member (cz.metacentrum.perun.core.api.Member)22 PerunSession (cz.metacentrum.perun.core.api.PerunSession)20 RichFacility (cz.metacentrum.perun.core.api.RichFacility)20 Host (cz.metacentrum.perun.core.api.Host)19 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)18 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)17 RichUser (cz.metacentrum.perun.core.api.RichUser)16 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)15 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)14 Vo (cz.metacentrum.perun.core.api.Vo)13