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