Search in sources :

Example 1 with SponsorshipEstablished

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

the class MembersManagerBlImpl method sponsorMember.

@Override
public Member sponsorMember(PerunSession session, Member sponsoredMember, User sponsor, LocalDate validityTo) throws MemberNotSponsoredException, AlreadySponsorException, UserNotInRoleException {
    // check that sponsoring user has role SPONSOR for the VO
    Vo vo = getMemberVo(session, sponsoredMember);
    if (!getPerunBl().getVosManagerBl().isUserInRoleForVo(session, sponsor, Role.SPONSOR, vo, true)) {
        throw new UserNotInRoleException("user " + sponsor.getId() + " is not in role SPONSOR for VO " + vo.getId());
    }
    if (!sponsoredMember.isSponsored()) {
        throw new MemberNotSponsoredException("member " + sponsoredMember.getId() + " is not marked as sponsored");
    }
    // check whether the user is already sponsor
    List<User> sponsors = getPerunBl().getUsersManagerBl().getSponsors(session, sponsoredMember);
    if (sponsors.stream().map(PerunBean::getId).anyMatch(id -> id == sponsor.getId())) {
        throw new AlreadySponsorException("member " + sponsoredMember.getId() + " is already sponsored by user " + sponsor.getId());
    }
    // add the sponsor
    getMembersManagerImpl().addSponsor(session, 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);
    }
    getPerunBl().getAuditer().log(session, new SponsorshipEstablished(sponsoredMember, sponsor, validityTo));
    return sponsoredMember;
}
Also used : User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) MemberNotSponsoredException(cz.metacentrum.perun.core.api.exceptions.MemberNotSponsoredException) UserNotInRoleException(cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException) AlreadySponsorException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsorException) 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 SponsorshipEstablished

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

the class AuditMessagesManagerEntryIntegrationTest method testLocalDate.

@Test
public void testLocalDate() throws Exception {
    System.out.println(CLASS_NAME + "testLocalDate");
    AuditMessagesManagerImpl auditMessagesManagerImpl = (AuditMessagesManagerImpl) ReflectionTestUtils.getField(perun.getAuditMessagesManagerBl(), "auditMessagesManagerImpl");
    assertThat(auditMessagesManagerImpl).isNotNull();
    ObjectMapper mapper = (ObjectMapper) ReflectionTestUtils.getField(auditMessagesManagerImpl, "mapper");
    assertThat(mapper).isNotNull();
    AuditEvent event = new SponsorshipEstablished(null, null, LocalDate.MIN);
    testAuditEventMapper(mapper, event);
    EnrichedSponsorship enrichedSponsorship = new EnrichedSponsorship();
    enrichedSponsorship.setValidityTo(LocalDate.MAX);
    AuditEvent event2 = new SponsorshipExpired();
    testAuditEventMapper(mapper, event2);
}
Also used : SponsorshipEstablished(cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsorshipEstablished) EnrichedSponsorship(cz.metacentrum.perun.core.api.EnrichedSponsorship) SponsorshipExpired(cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpired) AuditMessagesManagerImpl(cz.metacentrum.perun.core.impl.AuditMessagesManagerImpl) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 3 with SponsorshipEstablished

use of cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsorshipEstablished 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 4 with SponsorshipEstablished

use of cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsorshipEstablished 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

SponsorshipEstablished (cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsorshipEstablished)4 SponsoredMemberSet (cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsoredMemberSet)2 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)2 BanOnVo (cz.metacentrum.perun.core.api.BanOnVo)2 Vo (cz.metacentrum.perun.core.api.Vo)2 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)2 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 UserNotInRoleException (cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException)2 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)2 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)2 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AuditEvent (cz.metacentrum.perun.audit.events.AuditEvent)1 SponsorshipExpired (cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpired)1 MemberCreated (cz.metacentrum.perun.audit.events.MembersManagerEvents.MemberCreated)1 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)1 EnrichedSponsorship (cz.metacentrum.perun.core.api.EnrichedSponsorship)1 Member (cz.metacentrum.perun.core.api.Member)1 RichMember (cz.metacentrum.perun.core.api.RichMember)1 RichUser (cz.metacentrum.perun.core.api.RichUser)1