Search in sources :

Example 1 with SponsoredMemberSet

use of cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsoredMemberSet in project perun by CESNET.

the class MembersManagerBlImpl method setSponsorshipForMember.

@Override
public Member setSponsorshipForMember(PerunSession session, Member sponsoredMember, User sponsor, LocalDate validityTo) throws AlreadySponsoredMemberException, UserNotInRoleException, AlreadySponsorException {
    if (sponsoredMember.isSponsored()) {
        throw new AlreadySponsoredMemberException(sponsoredMember + " is already sponsored member!");
    }
    // Test if Vo exists and sponsor has the right role in it
    Vo membersVo;
    try {
        membersVo = getPerunBl().getVosManagerBl().getVoById(session, sponsoredMember.getVoId());
    } catch (VoNotExistsException ex) {
        throw new ConsistencyErrorException("Vo for " + sponsoredMember + " not exists!");
    }
    if (!getPerunBl().getVosManagerBl().isUserInRoleForVo(session, sponsor, Role.SPONSOR, membersVo, true)) {
        throw new UserNotInRoleException("User " + sponsor.getId() + " is not in role SPONSOR for VO " + membersVo.getId());
    }
    // set member to be sponsored
    sponsoredMember = getMembersManagerImpl().setSponsorshipForMember(session, sponsoredMember, sponsor, validityTo);
    getPerunBl().getAuditer().log(session, new SponsoredMemberSet(sponsoredMember));
    getPerunBl().getAuditer().log(session, new SponsorshipEstablished(sponsoredMember, sponsor, validityTo));
    // remove expiration and validate member
    try {
        AttributeDefinition expiration = getPerunBl().getAttributesManagerBl().getAttributeDefinition(session, EXPIRATION);
        getPerunBl().getAttributesManagerBl().removeAttribute(session, sponsoredMember, expiration);
    } catch (WrongAttributeAssignmentException | AttributeNotExistsException | WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
        throw new InternalErrorException("cannot remove expiration date for sponsored member " + sponsoredMember.getId(), ex);
    }
    try {
        validateMember(session, sponsoredMember);
    } catch (WrongReferenceAttributeValueException | WrongAttributeValueException ex) {
        throw new InternalErrorException("cannot validate sponsored member " + sponsoredMember.getId(), ex);
    }
    return sponsoredMember;
}
Also used : SponsoredMemberSet(cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsoredMemberSet) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) AlreadySponsoredMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsoredMemberException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) UserNotInRoleException(cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException) SponsorshipEstablished(cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsorshipEstablished) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Vo(cz.metacentrum.perun.core.api.Vo) BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 2 with SponsoredMemberSet

use of cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsoredMemberSet in project perun by CESNET.

the class MembersManagerBlImpl method setSponsoredMember.

@Override
public Member setSponsoredMember(PerunSession session, SponsoredUserData data, Vo vo, User userToBeSponsored, User sponsor, LocalDate validityTo, Validation validation) throws AlreadyMemberException, ExtendMembershipException, UserNotInRoleException, WrongAttributeValueException, WrongReferenceAttributeValueException, LoginNotExistsException, PasswordCreationFailedException, InvalidLoginException, ExtSourceNotExistsException, AlreadySponsorException, InvalidSponsoredUserDataException, NamespaceRulesNotExistsException, PasswordStrengthException {
    checkOrSetSponsorRole(session, sponsor, vo);
    if (isNotBlank(data.getNamespace())) {
        handleSponsorshipInNamespace(session, userToBeSponsored, data);
    }
    // create the member in Perun
    Member sponsoredMember = getMembersManagerImpl().createSponsoredMember(session, vo, userToBeSponsored, sponsor, validityTo);
    getPerunBl().getAuditer().log(session, new MemberCreated(sponsoredMember));
    getPerunBl().getAuditer().log(session, new SponsoredMemberSet(sponsoredMember));
    getPerunBl().getAuditer().log(session, new SponsorshipEstablished(sponsoredMember, sponsor, validityTo));
    extendMembership(session, sponsoredMember);
    insertToMemberGroup(session, sponsoredMember, vo);
    if (Validation.ASYNC.equals(validation)) {
        validateMemberAsync(session, sponsoredMember);
    } else if (Validation.SYNC.equals(validation)) {
        // for unit tests
        validateMember(session, sponsoredMember);
    }
    if (isNotBlank(data.getNamespace())) {
        getPerunBl().getUsersManagerBl().validatePassword(session, userToBeSponsored, data.getNamespace());
    }
    return sponsoredMember;
}
Also used : SponsoredMemberSet(cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsoredMemberSet) SponsorshipEstablished(cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsorshipEstablished) MemberCreated(cz.metacentrum.perun.audit.events.MembersManagerEvents.MemberCreated) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Aggregations

SponsoredMemberSet (cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsoredMemberSet)2 SponsorshipEstablished (cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsorshipEstablished)2 MemberCreated (cz.metacentrum.perun.audit.events.MembersManagerEvents.MemberCreated)1 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)1 BanOnVo (cz.metacentrum.perun.core.api.BanOnVo)1 Member (cz.metacentrum.perun.core.api.Member)1 RichMember (cz.metacentrum.perun.core.api.RichMember)1 Vo (cz.metacentrum.perun.core.api.Vo)1 AlreadySponsoredMemberException (cz.metacentrum.perun.core.api.exceptions.AlreadySponsoredMemberException)1 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 UserNotInRoleException (cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException)1 VoNotExistsException (cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)1 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)1 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)1 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)1