Search in sources :

Example 26 with Candidate

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

the class MembersManagerEntryIntegrationTest method canExtendMembershipForDefinedLoaNotAllowedAndServiceUser.

@Test
public void canExtendMembershipForDefinedLoaNotAllowedAndServiceUser() throws Exception {
    System.out.println(CLASS_NAME + "extendMembershipForDefinedLoaNotAllowedAndServiceUser");
    // Set membershipExpirationRules attribute
    HashMap<String, String> extendMembershipRules = new LinkedHashMap<>();
    extendMembershipRules.put(AbstractMembershipExpirationRulesModule.membershipPeriodKeyName, "1.1.");
    extendMembershipRules.put(AbstractMembershipExpirationRulesModule.membershipDoNotExtendLoaKeyName, "0");
    extendMembershipRules.put(AbstractMembershipExpirationRulesModule.membershipPeriodLoaKeyName, "1|+1m.");
    Attribute extendMembershipRulesAttribute = new Attribute(attributesManagerEntry.getAttributeDefinition(sess, AttributesManager.NS_VO_ATTR_DEF + ":membershipExpirationRules"));
    extendMembershipRulesAttribute.setValue(extendMembershipRules);
    attributesManagerEntry.setAttribute(sess, createdVo, extendMembershipRulesAttribute);
    // Set LOA 1 for member
    ExtSource es = perun.getExtSourcesManagerBl().getExtSourceByName(sess, EXT_SOURCE_NAME);
    UserExtSource uesService = new UserExtSource(es, "abc");
    uesService.setLoa(0);
    User user = usersManagerEntry.getUserByMember(sess, createdMember);
    // usersManagerEntry.addUserExtSource(sess, user, ues);
    Candidate serviceCandidate = new Candidate();
    serviceCandidate.setServiceUser(true);
    serviceCandidate.setFirstName("");
    serviceCandidate.setLastName("");
    serviceCandidate.setId(0);
    serviceCandidate.setUserExtSource(uesService);
    serviceCandidate.setAttributes(new HashMap<>());
    Member serviceMember = perun.getMembersManager().createSpecificMember(sess, createdVo, serviceCandidate, Collections.singletonList(user), SpecificUserType.SERVICE);
    // Try to extend membership
    membersManagerEntry.extendMembership(sess, serviceMember);
    Attribute membershipAttributeFirst = attributesManagerEntry.getAttribute(sess, serviceMember, AttributesManager.NS_MEMBER_ATTR_DEF + ":membershipExpiration");
    assertNotNull("membership attribute must be set", membershipAttributeFirst);
    assertNotNull("membership attribute value must be set", membershipAttributeFirst.getValue());
    // Try to extend membership - must pass since user is service user
    assertTrue(membersManagerEntry.canExtendMembership(sess, serviceMember));
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) LinkedHashMap(java.util.LinkedHashMap) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 27 with Candidate

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

the class MembersManagerEntryIntegrationTest method setUpCandidateSponsor.

private Candidate setUpCandidateSponsor() {
    String userFirstName = "Jan";
    String userLastName = "Sponzor";
    String extLogin = "aaaaaaa";
    // Mockito.mock(Candidate.class);
    Candidate candidate = new Candidate();
    candidate.setFirstName(userFirstName);
    candidate.setId(0);
    candidate.setMiddleName("");
    candidate.setLastName(userLastName);
    candidate.setTitleBefore("");
    candidate.setTitleAfter("");
    final UserExtSource userExtSource = new UserExtSource(extSource, extLogin);
    candidate.setUserExtSource(userExtSource);
    candidate.setAttributes(new HashMap<>());
    return candidate;
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource)

Example 28 with Candidate

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

the class MembersManagerEntryIntegrationTest method canBeMemberLoaNotAllowedServiceUser.

@Test
public // It checks if service user can be member independent of his LoA
void canBeMemberLoaNotAllowedServiceUser() throws Exception {
    System.out.println(CLASS_NAME + "canBeMemberLoaNotAllowedServiceUser");
    String loa = "1";
    // Set membershipExpirationRules attribute
    HashMap<String, String> extendMembershipRules = new LinkedHashMap<>();
    extendMembershipRules.put(AbstractMembershipExpirationRulesModule.membershipDoNotAllowLoaKeyName, loa);
    Attribute extendMembershipRulesAttribute = new Attribute(attributesManagerEntry.getAttributeDefinition(sess, AttributesManager.NS_VO_ATTR_DEF + ":membershipExpirationRules"));
    extendMembershipRulesAttribute.setValue(extendMembershipRules);
    attributesManagerEntry.setAttribute(sess, createdVo, extendMembershipRulesAttribute);
    User user = usersManagerEntry.getUserByMember(sess, createdMember);
    // Set LOA 1 for member
    ExtSource es = perun.getExtSourcesManagerBl().getExtSourceByName(sess, EXT_SOURCE_NAME);
    UserExtSource uesService = new UserExtSource(es, "abc");
    uesService.setLoa(1);
    Candidate serviceCandidate = new Candidate();
    serviceCandidate.setServiceUser(true);
    serviceCandidate.setFirstName("");
    serviceCandidate.setLastName("");
    serviceCandidate.setId(0);
    serviceCandidate.setUserExtSource(uesService);
    serviceCandidate.setAttributes(new HashMap<>());
    Member serviceMember = perun.getMembersManager().createSpecificMember(sess, createdVo, serviceCandidate, Collections.singletonList(user), SpecificUserType.SERVICE);
    User serviceUser = usersManagerEntry.getUserByMember(sess, serviceMember);
    // Must return true even if loa is not allowed
    assertTrue(membersManagerEntry.canBeMember(sess, createdVo, serviceUser, loa));
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) LinkedHashMap(java.util.LinkedHashMap) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 29 with Candidate

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

the class MembersManagerEntryIntegrationTest method createMemberFromCandidateWithExtSourceInGroup.

@Test
public void createMemberFromCandidateWithExtSourceInGroup() throws Exception {
    System.out.println(CLASS_NAME + "createMember");
    List<Group> groups = new ArrayList<>(Collections.singletonList(g3ing1));
    // Create new locale member for puprose of this method
    String userFirstName = Long.toHexString(Double.doubleToLongBits(Math.random()));
    String userLastName = Long.toHexString(Double.doubleToLongBits(Math.random()));
    String extLogin = Long.toHexString(Double.doubleToLongBits(Math.random()));
    Candidate candidate = new Candidate();
    candidate.setFirstName(userFirstName);
    candidate.setId(0);
    candidate.setMiddleName("");
    candidate.setLastName(userLastName);
    candidate.setTitleBefore("");
    candidate.setTitleAfter("");
    UserExtSource ues = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), extLogin);
    candidate.setAttributes(new HashMap<>());
    Member member = perun.getMembersManager().createMember(sess, createdVo, ues.getExtSource().getName(), ues.getExtSource().getType(), ues.getLogin(), candidate, groups);
    // test if member is in vo and also in defined groups
    assertTrue(perun.getMembersManagerBl().getMembers(sess, createdVo).contains(member));
    List<Group> returnedGroups = perun.getGroupsManagerBl().getMemberGroups(sess, member);
    assertTrue(returnedGroups.contains(g1));
    assertTrue(!returnedGroups.contains(g2));
    assertTrue(returnedGroups.contains(g3ing1));
    // save user for deletion after test
    usersForDeletion.add(perun.getUsersManager().getUserByMember(sess, member));
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) Group(cz.metacentrum.perun.core.api.Group) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ArrayList(java.util.ArrayList) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 30 with Candidate

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

the class MembersManagerEntryIntegrationTest method getCompleteRichMembersWithAllowedGroupStatuses.

@Test
public void getCompleteRichMembersWithAllowedGroupStatuses() throws Exception {
    System.out.println(CLASS_NAME + "getCompleteRichMembersWithAllowedGroupStatuses");
    Group group = perun.getGroupsManagerBl().createGroup(sess, createdVo, new Group("TestGroup", "TestGroupDescription"));
    Candidate candidate1 = new Candidate();
    candidate1.setFirstName("first1");
    candidate1.setId(1);
    candidate1.setMiddleName("");
    candidate1.setLastName("last1");
    candidate1.setTitleBefore("");
    candidate1.setTitleAfter("");
    ues = new UserExtSource(extSource, "login1");
    candidate1.setUserExtSource(ues);
    candidate1.setAttributes(new HashMap<>());
    Member createdMember1 = perun.getMembersManagerBl().createMemberSync(sess, createdVo, candidate1);
    Candidate candidate2 = new Candidate();
    candidate2.setFirstName("first2");
    candidate2.setId(2);
    candidate2.setMiddleName("");
    candidate2.setLastName("last2");
    candidate2.setTitleBefore("");
    candidate2.setTitleAfter("");
    ues = new UserExtSource(extSource, "login2");
    candidate2.setUserExtSource(ues);
    candidate2.setAttributes(new HashMap<>());
    Member createdMember2 = perun.getMembersManagerBl().createMemberSync(sess, createdVo, candidate2);
    perun.getGroupsManagerBl().addMember(sess, group, createdMember1);
    perun.getGroupsManagerBl().addMember(sess, group, createdMember2);
    List<RichMember> richMembers = membersManagerEntry.getCompleteRichMembers(sess, group, Collections.emptyList(), Arrays.asList("INVALID", "DISABLED", "EXPIRED"), Collections.singletonList("EXPIRED"), false);
    assertEquals(0, richMembers.size());
    richMembers = membersManagerEntry.getCompleteRichMembers(sess, group, Collections.emptyList(), Collections.singletonList("VALID"), Collections.singletonList("VALID"), false);
    assertEquals(2, richMembers.size());
    perun.getGroupsManagerBl().expireMemberInGroup(sess, createdMember1, group);
    richMembers = membersManagerEntry.getCompleteRichMembers(sess, group, Collections.emptyList(), Arrays.asList("VALID", "INVALID", "DISABLED", "EXPIRED"), Collections.singletonList("EXPIRED"), false);
    assertEquals(1, richMembers.size());
    richMembers = membersManagerEntry.getCompleteRichMembers(sess, group, Collections.emptyList(), Collections.singletonList("EXPIRED"), Collections.singletonList("EXPIRED"), false);
    assertEquals(0, richMembers.size());
    richMembers = membersManagerEntry.getCompleteRichMembers(sess, group, Collections.emptyList(), Arrays.asList("VALID", "INVALID", "DISABLED", "EXPIRED"), Collections.emptyList(), false);
    assertEquals(2, richMembers.size());
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) Group(cz.metacentrum.perun.core.api.Group) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) RichMember(cz.metacentrum.perun.core.api.RichMember) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

Candidate (cz.metacentrum.perun.core.api.Candidate)100 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)52 Test (org.junit.Test)41 Member (cz.metacentrum.perun.core.api.Member)37 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)30 ExtSource (cz.metacentrum.perun.core.api.ExtSource)25 RichMember (cz.metacentrum.perun.core.api.RichMember)24 User (cz.metacentrum.perun.core.api.User)23 HashMap (java.util.HashMap)23 ArrayList (java.util.ArrayList)21 Group (cz.metacentrum.perun.core.api.Group)15 Attribute (cz.metacentrum.perun.core.api.Attribute)14 Map (java.util.Map)12 MemberCandidate (cz.metacentrum.perun.core.api.MemberCandidate)11 RichUser (cz.metacentrum.perun.core.api.RichUser)11 Vo (cz.metacentrum.perun.core.api.Vo)11 LinkedHashMap (java.util.LinkedHashMap)11 RichUserExtSource (cz.metacentrum.perun.core.api.RichUserExtSource)9 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)9 CandidateNotExistsException (cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException)8