Search in sources :

Example 21 with VoNotExistsException

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

the class ServicesManagerBlImpl method getDataWithGroups.

private ServiceAttributes getDataWithGroups(PerunSession sess, Service service, Facility facility, Resource resource, boolean filterExpiredMembers) {
    // append resource attributes
    ServiceAttributes resourceServiceAttributes = new ServiceAttributes();
    resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource));
    // append also vo attributes to resource object
    try {
        Vo resourceVo = getPerunBl().getVosManagerBl().getVoById(sess, resource.getVoId());
        resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resourceVo));
    } catch (VoNotExistsException ex) {
        throw new ConsistencyErrorException("There is missing Vo for existing resource " + resource);
    }
    ServiceAttributes membersAbstractSA = new ServiceAttributes();
    Map<Member, ServiceAttributes> memberAttributes = new HashMap<>();
    List<Member> members;
    if (filterExpiredMembers) {
        members = getPerunBl().getResourcesManagerBl().getAllowedMembersNotExpiredInGroups(sess, resource);
    } else {
        members = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
    }
    HashMap<Member, List<Attribute>> attributes;
    try {
        // append all member/member_resource/user/user_facility attributes
        attributes = getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility, resource, members, true);
    } catch (MemberResourceMismatchException ex) {
        throw new InternalErrorException(ex);
    }
    for (Member mem : attributes.keySet()) {
        ServiceAttributes tmpAttributes = new ServiceAttributes();
        tmpAttributes.addAttributes(attributes.get(mem));
        memberAttributes.put(mem, tmpAttributes);
        membersAbstractSA.addChildElement(tmpAttributes);
    }
    // get all groups and append their sub structure
    ServiceAttributes groupsAbstractSA = new ServiceAttributes();
    List<Group> groups = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resource);
    for (Group group : groups) {
        groupsAbstractSA.addChildElement(getData(sess, service, facility, resource, group, memberAttributes, filterExpiredMembers));
    }
    // assign abstract services attributes to resource service attributes
    resourceServiceAttributes.addChildElement(groupsAbstractSA);
    resourceServiceAttributes.addChildElement(membersAbstractSA);
    return resourceServiceAttributes;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) HashMap(java.util.HashMap) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) Vo(cz.metacentrum.perun.core.api.Vo) List(java.util.List) ArrayList(java.util.ArrayList) Member(cz.metacentrum.perun.core.api.Member)

Example 22 with VoNotExistsException

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

the class GenDataProviderImpl method loadVoSpecificAttributes.

private void loadVoSpecificAttributes(Resource resource) {
    // create incomplete vo object with only vo id
    Vo vo = new Vo();
    vo.setId(resource.getVoId());
    lastLoadedResource = resource;
    if (!voAttrs.containsKey(vo)) {
        Vo dbVo;
        try {
            dbVo = sess.getPerunBl().getVosManagerBl().getVoById(sess, resource.getVoId());
        } catch (VoNotExistsException e) {
            throw new InternalErrorException(e);
        }
        voAttrs.put(vo, sess.getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, dbVo));
    }
}
Also used : Vo(cz.metacentrum.perun.core.api.Vo) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)

Example 23 with VoNotExistsException

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

the class MembersManagerEntry method setSponsorshipForMember.

@Override
public RichMember setSponsorshipForMember(PerunSession session, Member sponsoredMember, User sponsor, LocalDate validityTo) throws MemberNotExistsException, AlreadySponsoredMemberException, UserNotInRoleException, PrivilegeException, AlreadySponsorException {
    Utils.checkPerunSession(session);
    getPerunBl().getMembersManagerBl().checkMemberExists(session, sponsoredMember);
    if (sponsor == null) {
        // sponsor is the caller
        sponsor = session.getPerunPrincipal().getUser();
    }
    Vo memberVo;
    try {
        memberVo = perunBl.getVosManagerBl().getVoById(session, sponsoredMember.getVoId());
    } catch (VoNotExistsException e) {
        throw new InternalErrorException(e);
    }
    // Authorization
    if (!AuthzResolver.authorizedInternal(session, "setSponsorshipForMember_Member_User_LocalDate_policy", memberVo, sponsor)) {
        throw new PrivilegeException(session, "setSponsorshipForMember");
    }
    // set member to be sponsored
    return membersManagerBl.getRichMember(session, membersManagerBl.setSponsorshipForMember(session, sponsoredMember, sponsor, validityTo));
}
Also used : PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) Vo(cz.metacentrum.perun.core.api.Vo) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)

Example 24 with VoNotExistsException

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

the class VosManagerBlImpl method findCandidates.

public List<Candidate> findCandidates(PerunSession sess, Group group, String searchString, List<ExtSource> extSources, boolean filterExistingMembers) {
    List<Candidate> candidates = new ArrayList<>();
    try {
        // Iterate through given extSources
        for (ExtSource source : extSources) {
            try {
                // Info if this is only simple ext source, change behavior if not
                boolean simpleExtSource = true;
                // Get potential subjects from the extSource
                List<Map<String, String>> subjects;
                try {
                    if (source instanceof ExtSourceApi) {
                        // find subjects with all their properties
                        subjects = ((ExtSourceApi) source).findSubjects(searchString);
                        simpleExtSource = false;
                    } else {
                        // find subjects only with logins - they then must be retrieved by login
                        subjects = ((ExtSourceSimpleApi) source).findSubjectsLogins(searchString);
                    }
                } catch (ExtSourceUnsupportedOperationException e1) {
                    log.warn("ExtSource {} doesn't support findSubjects", source.getName());
                    continue;
                } catch (InternalErrorException e) {
                    log.error("Error occurred on ExtSource {},  Exception {}.", source.getName(), e);
                    continue;
                } finally {
                    try {
                        ((ExtSourceSimpleApi) source).close();
                    } catch (ExtSourceUnsupportedOperationException e) {
                    // ExtSource doesn't support that functionality, so silently skip it.
                    } catch (InternalErrorException e) {
                        log.error("Can't close extSource connection.", e);
                    }
                }
                Set<String> uniqueLogins = new HashSet<>();
                for (Map<String, String> s : subjects) {
                    // Check if the user has unique identifier within extSource
                    if ((s.get("login") == null) || (s.get("login") != null && s.get("login").isEmpty())) {
                        log.error("User '{}' cannot be added, because he/she doesn't have a unique identifier (login)", s);
                        // Skip to another user
                        continue;
                    }
                    String extLogin = s.get("login");
                    // check uniqueness of every login in extSource
                    if (uniqueLogins.contains(extLogin)) {
                        throw new InternalErrorException("There are more than 1 login '" + extLogin + "' getting from extSource '" + source + "'");
                    } else {
                        uniqueLogins.add(extLogin);
                    }
                    // Get Candidate
                    Candidate candidate;
                    try {
                        if (simpleExtSource) {
                            // retrieve data about subjects from ext source based on ext. login
                            candidate = new Candidate(getPerunBl().getExtSourcesManagerBl().getCandidate(sess, source, extLogin));
                        } else {
                            // retrieve data about subjects from subjects we already have locally
                            candidate = new Candidate(getPerunBl().getExtSourcesManagerBl().getCandidate(sess, s, source, extLogin));
                        }
                    } catch (CandidateNotExistsException e) {
                        throw new ConsistencyErrorException("findSubjects returned that candidate, but getCandidate cannot find him using login " + extLogin, e);
                    } catch (ExtSourceUnsupportedOperationException e) {
                        throw new InternalErrorException("extSource supports findSubjects but not getCandidate???", e);
                    }
                    if (filterExistingMembers) {
                        try {
                            Vo vo = getPerunBl().getVosManagerBl().getVoById(sess, group.getVoId());
                            getPerunBl().getMembersManagerBl().getMemberByUserExtSources(sess, vo, candidate.getUserExtSources());
                            // Candidate is already a member of the VO, so do not add him to the list of candidates
                            continue;
                        } catch (VoNotExistsException e) {
                            throw new InternalErrorException(e);
                        } catch (MemberNotExistsException e) {
                        // This is OK
                        }
                    }
                    // Add candidate to the list of candidates
                    log.debug("findCandidates: returning candidate: {}", candidate);
                    candidates.add(candidate);
                }
            } catch (InternalErrorException e) {
                log.error("Failed to get candidates from ExtSource: {}", source);
            } finally {
                if (source instanceof ExtSourceSimpleApi) {
                    try {
                        ((ExtSourceSimpleApi) source).close();
                    } catch (ExtSourceUnsupportedOperationException e) {
                    // silently skip
                    } catch (Exception e) {
                        log.error("Failed to close connection to extsource", e);
                    }
                }
            }
        }
        log.debug("Returning {} potential members for group {}", candidates.size(), group);
        return candidates;
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) MemberCandidate(cz.metacentrum.perun.core.api.MemberCandidate) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ExtSourceApi(cz.metacentrum.perun.core.implApi.ExtSourceApi) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) 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) CandidateNotExistsException(cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException) VoExistsException(cz.metacentrum.perun.core.api.exceptions.VoExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) MemberNotSponsoredException(cz.metacentrum.perun.core.api.exceptions.MemberNotSponsoredException) AlreadySponsorException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsorException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) ExtSourceUnsupportedOperationException(cz.metacentrum.perun.core.api.exceptions.ExtSourceUnsupportedOperationException) NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException) UserNotInRoleException(cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) PerunException(cz.metacentrum.perun.core.api.exceptions.PerunException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) Vo(cz.metacentrum.perun.core.api.Vo) BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSourceUnsupportedOperationException(cz.metacentrum.perun.core.api.exceptions.ExtSourceUnsupportedOperationException) Map(java.util.Map) HashMap(java.util.HashMap) ExtSourceSimpleApi(cz.metacentrum.perun.core.implApi.ExtSourceSimpleApi) HashSet(java.util.HashSet) CandidateNotExistsException(cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException)

Example 25 with VoNotExistsException

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

the class urn_perun_group_attribute_def_def_groupExtSource method checkAttributeSemantics.

@Override
public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Attribute attribute) throws WrongReferenceAttributeValueException {
    // prepare groupName value variable
    String extSourceName = null;
    if (attribute.getValue() != null)
        extSourceName = attribute.valueAsString();
    // if extSourceName is null, attribute can be removed
    if (extSourceName != null) {
        try {
            Vo groupVo = sess.getPerunBl().getVosManagerBl().getVoById(sess, group.getVoId());
            List<ExtSource> allowedExtSources = sess.getPerunBl().getExtSourcesManagerBl().getVoExtSources(sess, groupVo);
            for (ExtSource es : allowedExtSources) {
                if (extSourceName.equals(es.getName()))
                    return;
            }
            throw new WrongReferenceAttributeValueException(attribute, null, group, null, "ExtSourceName " + extSourceName + " is not valid, because VO " + groupVo + " of this group has no such extSource assigned.");
        } catch (VoNotExistsException ex) {
            throw new ConsistencyErrorException("Vo of this group " + group + " not exists!");
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Vo(cz.metacentrum.perun.core.api.Vo) ExtSource(cz.metacentrum.perun.core.api.ExtSource) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)

Aggregations

VoNotExistsException (cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)26 Vo (cz.metacentrum.perun.core.api.Vo)24 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)18 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)14 Member (cz.metacentrum.perun.core.api.Member)10 ArrayList (java.util.ArrayList)9 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)8 Attribute (cz.metacentrum.perun.core.api.Attribute)7 ExtSource (cz.metacentrum.perun.core.api.ExtSource)7 User (cz.metacentrum.perun.core.api.User)7 ExtendMembershipException (cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException)7 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)7 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)7 Group (cz.metacentrum.perun.core.api.Group)6 AlreadyMemberException (cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException)6 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)6 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)5 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)5 Map (java.util.Map)5 BanOnVo (cz.metacentrum.perun.core.api.BanOnVo)4