use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.
the class MembersManagerBlImpl method createMember.
@Override
public Member createMember(PerunSession sess, Vo vo, ExtSource extSource, String login, List<Group> groups) throws WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, ExtendMembershipException {
// First of all get candidate from extSource directly
Candidate candidate = null;
try {
if (extSource instanceof ExtSourceApi) {
// get first subject, then create candidate
Map<String, String> subject = ((ExtSourceSimpleApi) extSource).getSubjectByLogin(login);
candidate = new Candidate(getPerunBl().getExtSourcesManagerBl().getCandidate(sess, subject, extSource, login));
} else if (extSource instanceof ExtSourceSimpleApi) {
// get candidates from external source by login
candidate = new Candidate(getPerunBl().getExtSourcesManagerBl().getCandidate(sess, extSource, login));
}
} catch (CandidateNotExistsException | SubjectNotExistsException ex) {
throw new InternalErrorException("Can't find candidate for login " + login + " in extSource " + extSource, ex);
} catch (ExtSourceUnsupportedOperationException ex) {
throw new InternalErrorException("Some operation is not allowed for extSource " + extSource, ex);
} finally {
if (extSource instanceof ExtSourceSimpleApi) {
try {
((ExtSourceSimpleApi) extSource).close();
} catch (ExtSourceUnsupportedOperationException e) {
// silently skip
} catch (Exception e) {
log.error("Failed to close connection to extsource", e);
}
}
}
return this.createMember(sess, vo, candidate, groups);
}
use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method setUpWorld.
/**
* How the world look: "->" means "have a binding, connection with"
*
* vo1 -> member1OfUser1, member2OfUser2, member1OfUser3 && group1InVo1, group2InVo1, membersGroupOfVo1 && resource1InVo1, resource2InVo1
* vo2 -> member2OfUser1, member1OfUser2, member2OfUser3 && group1InVo2, group2InVo2, membersGroupOfVo2 && resource1InVo2, resource2InVo2
*
* user1 -> member1OfUser1, member2OfUser1 && userExtSource1
* user2 -> member1OfUser2, member2OfUser2 && userExtSource2
* user3 -> member1OfUser3, member2OfUser3 && userExtSource3
*
* member1OfUser1 IS allowed
* member2OfUser1 IS disallowed
* member1OfUser2 IS allowed
* member2OfUser2 IS disallowed
* member1OfUser3 IS allowed
* member2OfUser3 IS allowed
*
* group1InVo1 -> member1OfUser1, member2OfUser2, member1OfUser3
* group2InVo1 -> member1OfUser1, member2OfUser2
* group1InVo2 -> member2OfUser1, member1OfUser2
* group2InVo2 -> member2OfUser1, member1OfUser2, member2OfUser3
*
* facility1 -> host1OnFacility1, host2OnFacility1
* facility2 -> host1OnFacility2, host2OnFacility2
* facility3 -> host1OnFacility3, host2OnFacility3
*
* resource1InVo1 -> facility1 && group1InVo1, group2InVo1
* resource2InVo1 -> facility2 && group2InVo1
* resource1InVo2 -> facility2 && group1InVo2, group2InVo2
* resource2InVo2 -> facility3 && group2InVo2
*/
public void setUpWorld() throws Exception {
// Create VO
vo1 = perun.getVosManagerBl().createVo(sess, new Vo(0, "vo1Test", "v1T"));
vo2 = perun.getVosManagerBl().createVo(sess, new Vo(0, "vo2Test", "v2T"));
// Create Groups(members groups in vos), Members and Users from Candidates
Candidate can1 = new Candidate();
can1.setFirstName("user1");
can1.setId(0);
can1.setMiddleName("");
can1.setLastName("Test");
can1.setTitleBefore("");
can1.setTitleAfter("");
userExtSource1 = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), "user1TestLogin");
userExtSource2 = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), "user2TestLogin");
userExtSource3 = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), "user3TestLogin");
can1.setUserExtSource(userExtSource1);
can1.setAttributes(new HashMap<>());
member1OfUser1 = perun.getMembersManagerBl().createMemberSync(sess, vo1, can1);
user1 = perun.getUsersManagerBl().getUserByMember(sess, member1OfUser1);
member2OfUser1 = perun.getMembersManagerBl().createMember(sess, vo2, user1);
can1.setFirstName("user2");
can1.setUserExtSource(userExtSource2);
member1OfUser2 = perun.getMembersManagerBl().createMemberSync(sess, vo2, can1);
user2 = perun.getUsersManagerBl().getUserByMember(sess, member1OfUser2);
member2OfUser2 = perun.getMembersManagerBl().createMember(sess, vo1, user2);
can1.setFirstName("user3");
can1.setUserExtSource(userExtSource3);
member1OfUser3 = perun.getMembersManagerBl().createMemberSync(sess, vo1, can1);
user3 = perun.getUsersManagerBl().getUserByMember(sess, member1OfUser3);
member2OfUser3 = perun.getMembersManagerBl().createMember(sess, vo2, user3);
// Validate members
member1OfUser1 = perun.getMembersManagerBl().validateMember(sess, member1OfUser1);
member2OfUser1 = perun.getMembersManagerBl().validateMember(sess, member2OfUser1);
member1OfUser2 = perun.getMembersManagerBl().validateMember(sess, member1OfUser2);
member2OfUser2 = perun.getMembersManagerBl().validateMember(sess, member2OfUser2);
member1OfUser3 = perun.getMembersManagerBl().validateMember(sess, member1OfUser3);
member2OfUser3 = perun.getMembersManagerBl().validateMember(sess, member2OfUser3);
// Invalidate some members to Disallowed them
perun.getMembersManagerBl().invalidateMember(sess, member2OfUser1);
perun.getMembersManagerBl().invalidateMember(sess, member2OfUser2);
// Create groups and add members to them
membersGroupOfVo1 = perun.getGroupsManagerBl().getGroupByName(sess, vo1, VosManager.MEMBERS_GROUP);
membersGroupOfVo2 = perun.getGroupsManagerBl().getGroupByName(sess, vo2, VosManager.MEMBERS_GROUP);
group1InVo1 = perun.getGroupsManagerBl().createGroup(sess, vo1, new Group("testGroup1InVo1", ""));
group2InVo1 = perun.getGroupsManagerBl().createGroup(sess, vo1, new Group("testGroup2InVo1", ""));
group1InVo2 = perun.getGroupsManagerBl().createGroup(sess, vo2, new Group("testGroup1InVo2", ""));
group2InVo2 = perun.getGroupsManagerBl().createGroup(sess, vo2, new Group("testGroup2InVo2", ""));
perun.getGroupsManagerBl().addMember(sess, group1InVo1, member1OfUser1);
perun.getGroupsManagerBl().addMember(sess, group2InVo1, member1OfUser1);
perun.getGroupsManagerBl().addMember(sess, group1InVo1, member2OfUser2);
perun.getGroupsManagerBl().addMember(sess, group2InVo1, member2OfUser2);
perun.getGroupsManagerBl().addMember(sess, group1InVo2, member2OfUser1);
perun.getGroupsManagerBl().addMember(sess, group2InVo2, member2OfUser1);
perun.getGroupsManagerBl().addMember(sess, group1InVo2, member1OfUser2);
perun.getGroupsManagerBl().addMember(sess, group2InVo2, member1OfUser2);
perun.getGroupsManagerBl().addMember(sess, group1InVo1, member1OfUser3);
perun.getGroupsManagerBl().addMember(sess, group2InVo2, member2OfUser3);
// Create Facility
facility1 = perun.getFacilitiesManagerBl().createFacility(sess, new Facility(0, "testFacility1"));
facility2 = perun.getFacilitiesManagerBl().createFacility(sess, new Facility(0, "testFacility2"));
facility3 = perun.getFacilitiesManagerBl().createFacility(sess, new Facility(0, "testFacility3"));
// Create Host on Facilities
host1OnFacility1 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "test.host1.on.facility1"), facility1);
host2OnFacility1 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "test.host2.on.facility1"), facility1);
host1OnFacility2 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "test.host1.on.facility2"), facility2);
host2OnFacility2 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "test.host2.on.facility2"), facility2);
host1OnFacility3 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "test.host1.on.facility3"), facility3);
host2OnFacility3 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "test.host2.on.facility3"), facility3);
// Create resources and assing group to them
resource1InVo1 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource1InVo1", "", facility1.getId(), vo1.getId()), vo1, facility1);
resource2InVo1 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource2InVo1", "", facility2.getId(), vo1.getId()), vo1, facility2);
resource1InVo2 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource1InVo2", "", facility2.getId(), vo2.getId()), vo2, facility2);
resource2InVo2 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource2InVo2", "", facility3.getId(), vo2.getId()), vo2, facility3);
perun.getResourcesManagerBl().assignGroupToResource(sess, group1InVo1, resource1InVo1, false, false, false);
perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo1, resource1InVo1, false, false, false);
perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo1, resource2InVo1, false, false, false);
perun.getResourcesManagerBl().assignGroupToResource(sess, group1InVo2, resource1InVo2, false, false, false);
perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo2, resource1InVo2, false, false, false);
perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo2, resource2InVo2, false, false, false);
}
use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.
the class MembersManagerEntryIntegrationTest method setSponsoredMember.
@Test
public void setSponsoredMember() throws Exception {
System.out.println(CLASS_NAME + "setSponsoredMember");
Candidate candidate = new Candidate();
candidate.setFirstName("Jan");
candidate.setLastName("Novák");
User sponsoredUser = perun.getUsersManagerBl().createUser(sess, candidate);
Member sponsorMember = setUpSponsor(createdVo);
User sponsor = perun.getUsersManagerBl().getUserByMember(sess, sponsorMember);
AuthzResolverBlImpl.setRole(sess, sponsor, createdVo, Role.SPONSOR);
// FIXME - we shouldn't call async validation from test
Member sponsoredMember = perun.getMembersManagerBl().setSponsoredMember(sess, createdVo, sponsoredUser, "dummy", "password", sponsor, Validation.ASYNC);
Member memberFromDb = perun.getMembersManagerBl().getMemberByUser(sess, createdVo, sponsoredUser);
assertTrue(memberFromDb.isSponsored());
}
use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.
the class MembersManagerEntryIntegrationTest method createMemberFromCandidateWithExtSourceAndLoaInGroup.
@Test
public void createMemberFromCandidateWithExtSourceAndLoaInGroup() throws Exception {
System.out.println(CLASS_NAME + "createMember");
// g3in1 - direct, g1 indirect
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(), 2, 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 setUpNotSponsor.
private Member setUpNotSponsor(Vo vo) throws Exception {
Candidate candidate = setUpCandidateNotSponsor();
// candidates.get(0)
Member member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
// set first candidate as member of test VO
assertNotNull("No member created", member);
usersForDeletion.add(perun.getUsersManager().getUserByMember(sess, member));
Attribute attrEmail = new Attribute(attributesManagerEntry.getAttributeDefinition(sess, AttributesManager.NS_MEMBER_ATTR_DEF + ":mail"));
attrEmail.setValue("petr@sponsored.cz");
attributesManagerEntry.setAttribute(sess, member, attrEmail);
return member;
}
Aggregations