Search in sources :

Example 31 with MemberNotExistsException

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

the class urn_perun_member_resource_attribute_def_virt_isBanned method resolveBanChangedForResource.

private List<AuditEvent> resolveBanChangedForResource(PerunSessionImpl perunSession, int memberId, int resourceId) throws AttributeNotExistsException {
    List<AuditEvent> resolvingMessages = new ArrayList<>();
    try {
        Member member = perunSession.getPerunBl().getMembersManagerBl().getMemberById(perunSession, memberId);
        Resource resource = perunSession.getPerunBl().getResourcesManagerBl().getResourceById(perunSession, resourceId);
        AttributeDefinition attributeDefinition = perunSession.getPerunBl().getAttributesManagerBl().getAttributeDefinition(perunSession, A_MR_V_isBanned);
        resolvingMessages.add(new AttributeChangedForResourceAndMember(new Attribute(attributeDefinition), resource, member));
    } catch (MemberNotExistsException | ResourceNotExistsException e) {
        log.error("Can't resolve virtual attribute value change for " + this.getClass().getSimpleName() + " module because of exception.", e);
    }
    return resolvingMessages;
}
Also used : AttributeChangedForResourceAndMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForResourceAndMember) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) Resource(cz.metacentrum.perun.core.api.Resource) BanSetForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanSetForResource) BanUpdatedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanUpdatedForResource) BanRemovedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanRemovedForResource) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) ResourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceNotExistsException) AttributeChangedForResourceAndMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForResourceAndMember) Member(cz.metacentrum.perun.core.api.Member)

Example 32 with MemberNotExistsException

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

the class ExpirationNotifScheduler method expireSponsorship.

/**
 * Cancel given sponsorship and log the SponsorshipExpired audit event.
 *
 * @param sponsorship sponsorship to be cancelled
 */
private void expireSponsorship(Sponsorship sponsorship) {
    try {
        Member member = perun.getMembersManagerBl().getMemberById(sess, sponsorship.getSponsoredId());
        User sponsor = perun.getUsersManagerBl().getUserById(sess, sponsorship.getSponsorId());
        perun.getMembersManagerBl().removeSponsor(sess, member, sponsor);
        perun.getAuditer().log(sess, new SponsorshipExpired(convertSponsorshipToEnriched(sponsorship)));
    } catch (MemberNotExistsException | UserNotExistsException e) {
        log.error("Failed to expire sponsorship. Sponsorship: {}", sponsorship, e);
    }
}
Also used : User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) SponsorshipExpired(cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpired) Member(cz.metacentrum.perun.core.api.Member)

Example 33 with MemberNotExistsException

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

the class AttributesManagerBlImpl method setCoreAttributeWithoutCheck.

private void setCoreAttributeWithoutCheck(PerunSession sess, Member member, Attribute attribute) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
    if (!attribute.getName().equals("urn:perun:member:attribute-def:core:status")) {
        throw new InternalErrorException("We can set only urn:perun:member:attribute-def:core:status from member's core attributes. Others are not permitted.");
    }
    // defensive construction
    Member storedMember;
    try {
        storedMember = getPerunBl().getMembersManagerBl().getMemberById(sess, member.getId());
    } catch (MemberNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    }
    if (!member.equals(storedMember))
        throw new InternalErrorException("You wan't to store core attribute for member which is not equals to member from DB (with same Id)");
    String methodName = "set" + Character.toUpperCase(attribute.getFriendlyName().charAt(0)) + attribute.getFriendlyName().substring(1);
    Method method;
    try {
        method = member.getClass().getMethod(methodName, Class.forName(attribute.getType()));
    } catch (NoSuchMethodException ex) {
        throw new InternalErrorException("Bad core attribute definition. " + attribute, ex);
    } catch (ClassNotFoundException ex) {
        throw new InternalErrorException("Bad core attribute type. " + attribute, ex);
    }
    try {
        method.invoke(member, attribute.getValue());
    } catch (InvocationTargetException ex) {
        throw new WrongAttributeValueException(ex);
    } catch (IllegalArgumentException ex) {
        throw new WrongAttributeValueException(attribute, "Probably bad type of value", ex);
    } catch (IllegalAccessException | RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
    getPerunBl().getMembersManagerBl().updateMember(sess, member);
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) AttributeSetForResourceAndMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForResourceAndMember) AllAttributesRemovedForResourceAndMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForResourceAndMember) Member(cz.metacentrum.perun.core.api.Member) AttributeSetForMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForMember) AllAttributesRemovedForMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForMember) AttributeRemovedForMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForMember) AttributeRemovedForResourceAndMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForResourceAndMember)

Example 34 with MemberNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException 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 35 with MemberNotExistsException

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

the class VosManagerBlImpl method convertToSponsoredMemberWithNewSponsor.

/**
 * Sponsor given user by the given newSponsor in the given vo. If the newSponsor doesn't have
 * the SPONSOR role, it will be set to him.
 *
 * @param sess session
 * @param user user to be sponsored
 * @param newSponsor new sponsor
 * @param vo vo where the given user will be sponsored
 */
private void convertToSponsoredMemberWithNewSponsor(PerunSession sess, User user, User newSponsor, Vo vo) {
    try {
        Member member = perunBl.getMembersManagerBl().getMemberByUser(sess, vo, user);
        sponsorMemberByUser(sess, member, newSponsor, vo);
    } catch (MemberNotExistsException e) {
    // if the sponsored user is not member of the given vo, skip it
    }
}
Also used : MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) Member(cz.metacentrum.perun.core.api.Member)

Aggregations

MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)36 Member (cz.metacentrum.perun.core.api.Member)24 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)22 ArrayList (java.util.ArrayList)21 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)14 User (cz.metacentrum.perun.core.api.User)12 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)11 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)10 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)10 Attribute (cz.metacentrum.perun.core.api.Attribute)9 Group (cz.metacentrum.perun.core.api.Group)9 HashSet (java.util.HashSet)9 RichUser (cz.metacentrum.perun.core.api.RichUser)8 Vo (cz.metacentrum.perun.core.api.Vo)8 Map (java.util.Map)8 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)7 ExtSource (cz.metacentrum.perun.core.api.ExtSource)7 RichMember (cz.metacentrum.perun.core.api.RichMember)7 GroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException)7 VoNotExistsException (cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)7