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;
}
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);
}
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;
}
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;
}
Aggregations