Search in sources :

Example 1 with Sponsor

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

the class MembersManagerBlImpl method convertUserToSponsor.

@Override
public Sponsor convertUserToSponsor(PerunSession sess, User user, Member sponsoredMember) {
    Sponsor sponsor = new Sponsor(user);
    Sponsorship sponsorship;
    try {
        sponsorship = perunBl.getMembersManagerBl().getSponsorship(sess, sponsoredMember, user);
    } catch (SponsorshipDoesNotExistException e) {
        throw new InternalErrorException(e);
    }
    sponsor.setActive(sponsorship.isActive());
    sponsor.setValidityTo(sponsorship.getValidityTo());
    if (user instanceof RichUser) {
        sponsor.setUserAttributes(((RichUser) user).getUserAttributes());
        sponsor.setUserExtSources(((RichUser) user).getUserExtSources());
    }
    return sponsor;
}
Also used : Sponsorship(cz.metacentrum.perun.core.api.Sponsorship) RichUser(cz.metacentrum.perun.core.api.RichUser) Sponsor(cz.metacentrum.perun.core.api.Sponsor) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) SponsorshipDoesNotExistException(cz.metacentrum.perun.core.api.exceptions.SponsorshipDoesNotExistException)

Example 2 with Sponsor

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

the class MembersManagerEntry method convertMemberToMemberWithSponsors.

/**
 * Converts member to member with sponsors and sets all his sponsors.
 *
 * @param sess perun session
 * @param member sponsored member
 * @return member with sponsors
 */
private MemberWithSponsors convertMemberToMemberWithSponsors(PerunSession sess, RichMember member) {
    MemberWithSponsors memberWithSponsors = new MemberWithSponsors(member);
    List<Sponsor> sponsors = getPerunBl().getUsersManagerBl().getSponsors(sess, member).stream().map(user -> membersManagerBl.convertUserToSponsor(sess, user, member)).collect(Collectors.toList());
    memberWithSponsors.setSponsors(sponsors);
    return memberWithSponsors;
}
Also used : InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Arrays(java.util.Arrays) Validation(cz.metacentrum.perun.core.api.Validation) Candidate(cz.metacentrum.perun.core.api.Candidate) AuthzResolver(cz.metacentrum.perun.core.api.AuthzResolver) Vo(cz.metacentrum.perun.core.api.Vo) Date(java.util.Date) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) LoggerFactory(org.slf4j.LoggerFactory) SpecificUserType(cz.metacentrum.perun.core.api.SpecificUserType) MembersManager(cz.metacentrum.perun.core.api.MembersManager) ExtSource(cz.metacentrum.perun.core.api.ExtSource) MembersManagerBl(cz.metacentrum.perun.core.bl.MembersManagerBl) AlreadySponsoredMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsoredMemberException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) NamespaceRulesNotExistsException(cz.metacentrum.perun.core.api.exceptions.NamespaceRulesNotExistsException) Map(java.util.Map) Role(cz.metacentrum.perun.core.api.Role) MemberNotValidYetException(cz.metacentrum.perun.core.api.exceptions.MemberNotValidYetException) Attribute(cz.metacentrum.perun.core.api.Attribute) MembersPageQuery(cz.metacentrum.perun.core.api.MembersPageQuery) MemberAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException) MemberWithSponsors(cz.metacentrum.perun.core.api.MemberWithSponsors) PasswordCreationFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordCreationFailedException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Collectors(java.util.stream.Collectors) User(cz.metacentrum.perun.core.api.User) Sponsor(cz.metacentrum.perun.core.api.Sponsor) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) List(java.util.List) MemberNotSponsoredException(cz.metacentrum.perun.core.api.exceptions.MemberNotSponsoredException) LocalDate(java.time.LocalDate) AlreadySponsorException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsorException) RichMember(cz.metacentrum.perun.core.api.RichMember) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) PasswordStrengthException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) SponsoredUserData(cz.metacentrum.perun.core.api.SponsoredUserData) Resource(cz.metacentrum.perun.core.api.Resource) PerunSession(cz.metacentrum.perun.core.api.PerunSession) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) NamespaceRules(cz.metacentrum.perun.core.api.NamespaceRules) Paginated(cz.metacentrum.perun.core.api.Paginated) Group(cz.metacentrum.perun.core.api.Group) ArrayList(java.util.ArrayList) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) MemberNotSuspendedException(cz.metacentrum.perun.core.api.exceptions.MemberNotSuspendedException) SponsorshipDoesNotExistException(cz.metacentrum.perun.core.api.exceptions.SponsorshipDoesNotExistException) PasswordResetMailNotExistsException(cz.metacentrum.perun.core.api.exceptions.PasswordResetMailNotExistsException) Member(cz.metacentrum.perun.core.api.Member) Logger(org.slf4j.Logger) UserNotInRoleException(cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException) Iterator(java.util.Iterator) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) ResourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceNotExistsException) AlreadyMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) ExtendMembershipException(cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) Utils(cz.metacentrum.perun.core.impl.Utils) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) InvalidSponsoredUserDataException(cz.metacentrum.perun.core.api.exceptions.InvalidSponsoredUserDataException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) Collections(java.util.Collections) Status(cz.metacentrum.perun.core.api.Status) Sponsor(cz.metacentrum.perun.core.api.Sponsor) MemberWithSponsors(cz.metacentrum.perun.core.api.MemberWithSponsors)

Example 3 with Sponsor

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

the class VosManagerEntryIntegrationTest method convertSponsoredUsers.

@Test
public void convertSponsoredUsers() throws Exception {
    System.out.println(CLASS_NAME + "convertSponsoredUsers");
    myVo = vosManagerEntry.createVo(sess, myVo);
    User user = new User(-1, "Sponsored", "User", "", "", "");
    user.setSponsoredUser(true);
    User sponsor1 = new User(-1, "Sponsor 1", "", "", "", "");
    User sponsor2 = new User(-1, "Sponsor 2", "", "", "", "");
    user = perun.getUsersManagerBl().createUser(sess, user);
    sponsor1 = perun.getUsersManagerBl().createUser(sess, sponsor1);
    sponsor2 = perun.getUsersManagerBl().createUser(sess, sponsor2);
    perun.getUsersManagerBl().addSpecificUserOwner(sess, sponsor1, user);
    perun.getUsersManagerBl().addSpecificUserOwner(sess, sponsor2, user);
    Member member = perun.getMembersManagerBl().createMember(sess, myVo, user);
    perun.getVosManager().convertSponsoredUsers(sess, myVo);
    List<MemberWithSponsors> sponsoredMembersAndTheirSponsors = perun.getMembersManager().getSponsoredMembersAndTheirSponsors(sess, myVo, Collections.emptyList());
    assertThat(sponsoredMembersAndTheirSponsors).hasSize(1);
    Member sponsoredMember = sponsoredMembersAndTheirSponsors.get(0).getMember();
    List<Sponsor> sponsors = sponsoredMembersAndTheirSponsors.get(0).getSponsors();
    assertThat(sponsoredMember).isEqualTo(member);
    assertThat(sponsors).contains(new Sponsor(new RichUser(sponsor1, Collections.emptyList())));
    assertThat(sponsors).contains(new Sponsor(new RichUser(sponsor2, Collections.emptyList())));
}
Also used : RichUser(cz.metacentrum.perun.core.api.RichUser) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) Sponsor(cz.metacentrum.perun.core.api.Sponsor) MemberWithSponsors(cz.metacentrum.perun.core.api.MemberWithSponsors) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 4 with Sponsor

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

the class UsersManagerEntryIntegrationTest method getSponsors.

@Test
public void getSponsors() throws Exception {
    System.out.println(CLASS_NAME + "getSponsors");
    setUpNamespaceAttribute();
    String email = "email@sdf.sd";
    AttributeDefinition emailAD = perun.getAttributesManagerBl().getAttributeDefinition(sess, URN_ATTR_USER_PREFERRED_MAIL);
    Attribute emailAttribute = new Attribute(emailAD);
    emailAttribute.setValue(email);
    perun.getAttributesManagerBl().setAttribute(sess, user, emailAttribute);
    Member member = perun.getMembersManagerBl().getMemberByUser(sess, vo, sponsoredUser);
    LocalDate validity = LocalDate.now();
    perun.getMembersManagerBl().updateSponsorshipValidity(sess, member, user, validity);
    Member sponsoredMember = perun.getMembersManagerBl().getMemberByUser(sess, vo, sponsoredUser);
    List<Sponsor> sponsors = usersManager.getSponsorsForMember(sess, sponsoredMember, Collections.singletonList(URN_ATTR_USER_PREFERRED_MAIL));
    assertThat(sponsors).hasSize(1);
    assertThat(sponsors.get(0).getUser()).isEqualTo(user);
    assertThat(sponsors.get(0).getValidityTo()).isEqualTo(validity);
    assertThat(sponsors.get(0).getUserAttributes()).hasSize(1);
    assertThat(sponsors.get(0).getUserAttributes().get(0).getName()).isEqualTo(URN_ATTR_USER_PREFERRED_MAIL);
    assertThat(sponsors.get(0).getUserAttributes().get(0).valueAsString()).isEqualTo(email);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Sponsor(cz.metacentrum.perun.core.api.Sponsor) Member(cz.metacentrum.perun.core.api.Member) LocalDate(java.time.LocalDate) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 5 with Sponsor

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

the class MembersManagerEntryIntegrationTest method addSponsor.

@Test
public void addSponsor() throws Exception {
    System.out.println(CLASS_NAME + "addSponsor");
    // create user which can sponsor
    User sponsorUser = perun.getUsersManagerBl().getUserByMember(sess, setUpSponsor(createdVo));
    AuthzResolverBlImpl.setRole(sess, sponsorUser, createdVo, Role.SPONSOR);
    assertTrue("user must have SPONSOR role", perun.getVosManagerBl().isUserInRoleForVo(sess, sponsorUser, Role.SPONSOR, createdVo, true));
    // create another user which can sponsor
    User sponsorUser2 = perun.getUsersManagerBl().getUserByMember(sess, setUpSponsor2(createdVo));
    AuthzResolverBlImpl.setRole(sess, sponsorUser2, createdVo, Role.SPONSOR);
    assertTrue("user must have SPONSOR role", perun.getVosManagerBl().isUserInRoleForVo(sess, sponsorUser2, Role.SPONSOR, createdVo, true));
    // create user that cannot sponsor
    User notsponsorUser = perun.getUsersManagerBl().getUserByMember(sess, setUpNotSponsor(createdVo));
    assertFalse("user must not have SPONSOR role", perun.getVosManagerBl().isUserInRoleForVo(sess, notsponsorUser, Role.SPONSOR, createdVo, true));
    // create sponsored member
    Map<String, String> nameOfUser1 = new HashMap<>();
    nameOfUser1.put("guestName", "Ing. Jiří Novák, CSc.");
    Member sponsoredMember = createSponsoredMember(sess, createdVo, "dummy", nameOfUser1, "secret", null, sponsorUser);
    assertNotNull("sponsored member must not be null", sponsoredMember);
    assertTrue("sponsored memer must have flag 'sponsored' set", sponsoredMember.isSponsored());
    assertTrue("sponsored member should have status VALID", sponsoredMember.getStatus() == Status.VALID);
    // try add user that cannot sponsor, should fail
    try {
        perun.getMembersManager().sponsorMember(sess, sponsoredMember, notsponsorUser, null);
        fail("user cannot sponsor but was added as sponsor");
    } catch (UserNotInRoleException ex) {
    // expected
    }
    // try to add user that already is sponsor, should fail
    try {
        perun.getMembersManager().sponsorMember(sess, sponsoredMember, sponsorUser, null);
        fail("user cannot sponsor twice a single member");
    } catch (AlreadySponsorException ex) {
    // expected
    }
    // try to add sponsor, should succeed
    perun.getMembersManager().sponsorMember(sess, sponsoredMember, sponsorUser2, null);
    List<User> sponsors = perun.getUsersManagerBl().getSponsors(sess, sponsoredMember);
    assertTrue("sponsor 1 is not reported as sponsor", sponsors.contains(sponsorUser));
    assertTrue("sponsor 2 is not reported as sponsor", sponsors.contains(sponsorUser2));
    assertTrue("unexpected sponsors", sponsors.size() == 2);
    // check that it is reported
    List<RichMember> sponsoredMembers1 = perun.getMembersManager().getSponsoredMembers(sess, createdVo, sponsorUser);
    assertTrue("member is not in list of sponsored members for sponsor 1", sponsoredMembers1.stream().map(PerunBean::getId).anyMatch(id -> id == sponsoredMember.getId()));
    List<RichMember> sponsoredMembers2 = perun.getMembersManager().getSponsoredMembers(sess, createdVo, sponsorUser2);
    assertTrue("member is not in list of sponsored members for sponsor 2", sponsoredMembers2.stream().map(PerunBean::getId).anyMatch(id -> id == sponsoredMember.getId()));
    // remove sponsor and add him again, sponsorship should reactivate
    Sponsorship sponsorship = perun.getMembersManagerBl().getSponsorship(sess, sponsoredMember, sponsorUser);
    assertTrue(sponsorship.isActive());
    perun.getMembersManager().removeSponsor(sess, sponsoredMember, sponsorUser);
    sponsorship = perun.getMembersManagerBl().getSponsorship(sess, sponsoredMember, sponsorUser);
    assertFalse(sponsorship.isActive());
    perun.getMembersManager().sponsorMember(sess, sponsoredMember, sponsorUser, null);
    sponsorship = perun.getMembersManagerBl().getSponsorship(sess, sponsoredMember, sponsorUser);
    assertTrue(sponsorship.isActive());
}
Also used : InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Arrays(java.util.Arrays) Validation(cz.metacentrum.perun.core.api.Validation) Candidate(cz.metacentrum.perun.core.api.Candidate) Vo(cz.metacentrum.perun.core.api.Vo) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) SpecificUserType(cz.metacentrum.perun.core.api.SpecificUserType) MembersManager(cz.metacentrum.perun.core.api.MembersManager) ExtSource(cz.metacentrum.perun.core.api.ExtSource) AlreadySponsoredMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsoredMemberException) cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_vo_attribute_def_def_membershipExpirationRules.expireSponsoredMembers(cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_vo_attribute_def_def_membershipExpirationRules.expireSponsoredMembers) NamespaceRulesNotExistsException(cz.metacentrum.perun.core.api.exceptions.NamespaceRulesNotExistsException) ExtSourcesManager(cz.metacentrum.perun.core.api.ExtSourcesManager) PerunBean(cz.metacentrum.perun.core.api.PerunBean) Map(java.util.Map) Role(cz.metacentrum.perun.core.api.Role) GroupsManager(cz.metacentrum.perun.core.api.GroupsManager) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) Attribute(cz.metacentrum.perun.core.api.Attribute) Facility(cz.metacentrum.perun.core.api.Facility) MembersPageQuery(cz.metacentrum.perun.core.api.MembersPageQuery) MemberWithSponsors(cz.metacentrum.perun.core.api.MemberWithSponsors) Sponsorship(cz.metacentrum.perun.core.api.Sponsorship) BeansUtils(cz.metacentrum.perun.core.api.BeansUtils) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) ZoneId(java.time.ZoneId) User(cz.metacentrum.perun.core.api.User) ParseUserNameException(cz.metacentrum.perun.core.api.exceptions.ParseUserNameException) VosManager(cz.metacentrum.perun.core.api.VosManager) Sponsor(cz.metacentrum.perun.core.api.Sponsor) List(java.util.List) LocalDate(java.time.LocalDate) AlreadySponsorException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsorException) RichMember(cz.metacentrum.perun.core.api.RichMember) VO_EXPIRATION_RULES_ATTR(cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_vo_attribute_def_def_membershipExpirationRules.VO_EXPIRATION_RULES_ATTR) SortingOrder(cz.metacentrum.perun.core.api.SortingOrder) SponsoredUserData(cz.metacentrum.perun.core.api.SponsoredUserData) Resource(cz.metacentrum.perun.core.api.Resource) AssertionsForClassTypes.assertThatExceptionOfType(org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType) BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) PerunSession(cz.metacentrum.perun.core.api.PerunSession) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) NamespaceRules(cz.metacentrum.perun.core.api.NamespaceRules) Paginated(cz.metacentrum.perun.core.api.Paginated) HashMap(java.util.HashMap) Group(cz.metacentrum.perun.core.api.Group) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) MembersOrderColumn(cz.metacentrum.perun.core.api.MembersOrderColumn) AuthzResolverBlImpl(cz.metacentrum.perun.core.blImpl.AuthzResolverBlImpl) UsersManager(cz.metacentrum.perun.core.api.UsersManager) SponsorshipDoesNotExistException(cz.metacentrum.perun.core.api.exceptions.SponsorshipDoesNotExistException) Before(org.junit.Before) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) Member(cz.metacentrum.perun.core.api.Member) UserNotInRoleException(cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException) AbstractMembershipExpirationRulesModule(cz.metacentrum.perun.core.implApi.modules.attributes.AbstractMembershipExpirationRulesModule) Test(org.junit.Test) AlreadyMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException) AttributesManager(cz.metacentrum.perun.core.api.AttributesManager) MembershipType(cz.metacentrum.perun.core.api.MembershipType) ExtendMembershipException(cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) Collectors.toList(java.util.stream.Collectors.toList) Ignore(org.junit.Ignore) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) Assert(org.junit.Assert) Collections(java.util.Collections) Status(cz.metacentrum.perun.core.api.Status) Assert.assertEquals(org.junit.Assert.assertEquals) User(cz.metacentrum.perun.core.api.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RichMember(cz.metacentrum.perun.core.api.RichMember) UserNotInRoleException(cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException) AlreadySponsorException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsorException) Sponsorship(cz.metacentrum.perun.core.api.Sponsorship) PerunBean(cz.metacentrum.perun.core.api.PerunBean) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

Sponsor (cz.metacentrum.perun.core.api.Sponsor)8 Member (cz.metacentrum.perun.core.api.Member)7 User (cz.metacentrum.perun.core.api.User)6 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)5 MemberWithSponsors (cz.metacentrum.perun.core.api.MemberWithSponsors)5 Attribute (cz.metacentrum.perun.core.api.Attribute)4 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)4 RichUser (cz.metacentrum.perun.core.api.RichUser)4 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)4 Test (org.junit.Test)4 Candidate (cz.metacentrum.perun.core.api.Candidate)3 ExtSource (cz.metacentrum.perun.core.api.ExtSource)3 Group (cz.metacentrum.perun.core.api.Group)3 Paginated (cz.metacentrum.perun.core.api.Paginated)3 PerunSession (cz.metacentrum.perun.core.api.PerunSession)3 Resource (cz.metacentrum.perun.core.api.Resource)3 RichMember (cz.metacentrum.perun.core.api.RichMember)3 Role (cz.metacentrum.perun.core.api.Role)3 SpecificUserType (cz.metacentrum.perun.core.api.SpecificUserType)3 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)3