Search in sources :

Example 91 with Resource

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

the class FacilitiesManagerBlImpl method getAllowedUsers.

@Override
public List<User> getAllowedUsers(PerunSession sess, Facility facility, Vo specificVo, Service specificService) throws InternalErrorException {
    //Get all facilities resources
    List<Resource> resources = getAssignedResources(sess, facility, specificVo, specificService);
    List<User> users = new ArrayList<User>();
    for (Resource resource : resources) {
        users.addAll(getPerunBl().getResourcesManagerBl().getAllowedUsers(sess, resource));
    }
    return users;
}
Also used : User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) Resource(cz.metacentrum.perun.core.api.Resource) RichResource(cz.metacentrum.perun.core.api.RichResource) ArrayList(java.util.ArrayList)

Example 92 with Resource

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

the class AttributesManagerBlImpl method isTrulyRequiredAttribute.

public boolean isTrulyRequiredAttribute(PerunSession sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException, WrongAttributeAssignmentException {
    this.checkNamespace(sess, attributeDefinition, NS_USER_ATTR);
    List<Member> members = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
    for (Member member : members) {
        List<Resource> allowedResources = getPerunBl().getResourcesManagerBl().getAllowedResources(sess, member);
        for (Resource resource : allowedResources) {
            if (getAttributesManagerImpl().isAttributeRequiredByResource(sess, resource, attributeDefinition))
                return true;
        }
    }
    return false;
}
Also used : Resource(cz.metacentrum.perun.core.api.Resource) Member(cz.metacentrum.perun.core.api.Member)

Example 93 with Resource

use of cz.metacentrum.perun.core.api.Resource 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 94 with Resource

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

the class VosManagerBlImpl method deleteVo.

public void deleteVo(PerunSession sess, Vo vo, boolean forceDelete) throws InternalErrorException, RelationExistsException {
    log.debug("Deleting vo {}", vo);
    try {
        List<Member> members = getPerunBl().getMembersManagerBl().getMembers(sess, vo);
        log.debug("Deleting vo {} members", vo);
        // Check if there are some members left
        if (members != null && members.size() > 0) {
            if (forceDelete) {
                getPerunBl().getMembersManagerBl().deleteAllMembers(sess, vo);
            } else
                throw new RelationExistsException("Vo vo=" + vo + " contains members");
        }
        log.debug("Removing vo {} resources and theirs atributes", vo);
        // Delete resources
        List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
        if ((resources.size() == 0) || ((resources.size() > 0) && forceDelete)) {
            for (Resource resource : resources) {
                getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, resource);
                // Remove binding between service and resource
                List<Service> services = getPerunBl().getResourcesManagerBl().getAssignedServices(sess, resource);
                for (Service service : services) {
                    getPerunBl().getResourcesManagerBl().removeService(sess, resource, service);
                }
                getPerunBl().getResourcesManagerBl().deleteResource(sess, resource);
            }
        } else {
            throw new RelationExistsException("Vo vo=" + vo + " contains resources");
        }
        log.debug("Removing vo {} groups", vo);
        // Delete all groups
        List<Group> groups = getPerunBl().getGroupsManagerBl().getGroups(sess, vo);
        if (groups.size() != 1) {
            if (groups.size() < 1)
                throw new ConsistencyErrorException("'members' group is missing");
            if ((groups.size() > 1) && forceDelete) {
                getPerunBl().getGroupsManagerBl().deleteAllGroups(sess, vo);
            } else {
                throw new RelationExistsException("Vo vo=" + vo + " contains groups");
            }
        }
        // Finally delete binding between Vo and external source
        List<ExtSource> ess = getPerunBl().getExtSourcesManagerBl().getVoExtSources(sess, vo);
        log.debug("Deleting {} external sources binded to the vo {}", ess.size(), vo);
        for (ExtSource es : ess) {
            getPerunBl().getExtSourcesManagerBl().removeExtSource(sess, vo, es);
        }
        // Delete members group
        log.debug("Removing an administrators' group from the vo {}", vo);
        getPerunBl().getGroupsManagerBl().deleteMembersGroup(sess, vo);
        // delete all VO reserved logins from KDC
        List<Integer> list = getVosManagerImpl().getVoApplicationIds(sess, vo);
        for (Integer appId : list) {
            // for each application
            for (Pair<String, String> login : getVosManagerImpl().getApplicationReservedLogins(appId)) {
                // for all reserved logins - delete them in ext. system (e.g. KDC)
                try {
                    // !!! left = namespace / right = login !!!
                    getPerunBl().getUsersManagerBl().deletePassword(sess, login.getRight(), login.getLeft());
                } catch (LoginNotExistsException ex) {
                    log.error("Login: {} not exists in namespace {} while deleting passwords", login.getRight(), login.getLeft());
                }
            }
        }
        // delete all VO reserved logins from DB
        getVosManagerImpl().deleteVoReservedLogins(sess, vo);
        // VO applications, submitted data and app_form are deleted on cascade with "deleteVo()"
        // Delete VO attributes
        getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, vo);
        // Delete all Vo tags (for resources in Vo)
        getPerunBl().getResourcesManagerBl().deleteAllResourcesTagsForVo(sess, vo);
    } catch (Exception ex) {
        throw new InternalErrorException(ex);
    }
    // Finally delete the VO
    getVosManagerImpl().deleteVo(sess, vo);
    getPerunBl().getAuditer().log(sess, "{} deleted.", vo);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource) Service(cz.metacentrum.perun.core.api.Service) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ExtSourceUnsupportedOperationException(cz.metacentrum.perun.core.api.exceptions.ExtSourceUnsupportedOperationException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) GroupExistsException(cz.metacentrum.perun.core.api.exceptions.GroupExistsException) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException) CandidateNotExistsException(cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException) VoExistsException(cz.metacentrum.perun.core.api.exceptions.VoExistsException) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) ExtSource(cz.metacentrum.perun.core.api.ExtSource) Member(cz.metacentrum.perun.core.api.Member)

Example 95 with Resource

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

the class ServicesManagerBlImpl method getDataWithVos.

public ServiceAttributes getDataWithVos(PerunSession sess, Service service, Facility facility) throws InternalErrorException, VoNotExistsException {
    ServiceAttributes serviceAttributes = new ServiceAttributes();
    serviceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility));
    //Get resources only for facility and service
    List<Resource> resources = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
    resources.retainAll(getAssignedResources(sess, service));
    //Get all vos for these resources
    Set<Integer> vosIds = new HashSet<>();
    for (Resource resource : resources) {
        vosIds.add(resource.getVoId());
    }
    List<Vo> vos = new ArrayList<>();
    for (Integer voId : vosIds) {
        vos.add(getPerunBl().getVosManagerBl().getVoById(sess, voId));
    }
    for (Vo vo : vos) {
        List<Resource> voResources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
        voResources.retainAll(resources);
        ServiceAttributes voServiceAttributes = getDataWithVo(sess, service, facility, vo, voResources);
        serviceAttributes.addChildElement(voServiceAttributes);
    }
    return serviceAttributes;
}
Also used : ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) Resource(cz.metacentrum.perun.core.api.Resource) ArrayList(java.util.ArrayList) Vo(cz.metacentrum.perun.core.api.Vo) HashSet(java.util.HashSet)

Aggregations

Resource (cz.metacentrum.perun.core.api.Resource)176 Test (org.junit.Test)110 Attribute (cz.metacentrum.perun.core.api.Attribute)82 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)79 Facility (cz.metacentrum.perun.core.api.Facility)56 User (cz.metacentrum.perun.core.api.User)55 Group (cz.metacentrum.perun.core.api.Group)49 ArrayList (java.util.ArrayList)41 Vo (cz.metacentrum.perun.core.api.Vo)31 Member (cz.metacentrum.perun.core.api.Member)29 PerunSession (cz.metacentrum.perun.core.api.PerunSession)29 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)26 RichResource (cz.metacentrum.perun.core.api.RichResource)25 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)20 RichUser (cz.metacentrum.perun.core.api.RichUser)18 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)18 ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)17 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)17 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)15 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)14