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