Search in sources :

Example 21 with Candidate

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);
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) SubjectNotExistsException(cz.metacentrum.perun.core.api.exceptions.SubjectNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ExtSourceApi(cz.metacentrum.perun.core.implApi.ExtSourceApi) ExtSourceUnsupportedOperationException(cz.metacentrum.perun.core.api.exceptions.ExtSourceUnsupportedOperationException) NamespaceRulesNotExistsException(cz.metacentrum.perun.core.api.exceptions.NamespaceRulesNotExistsException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) MemberAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException) PasswordCreationFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordCreationFailedException) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) MemberNotSponsoredException(cz.metacentrum.perun.core.api.exceptions.MemberNotSponsoredException) AlreadySponsorException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsorException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) ExtSourceUnsupportedOperationException(cz.metacentrum.perun.core.api.exceptions.ExtSourceUnsupportedOperationException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) IllegalArgumentException(cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException) IOException(java.io.IOException) AlreadyMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException) ExtendMembershipException(cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) RoleManagementRulesNotExistsException(cz.metacentrum.perun.core.api.exceptions.RoleManagementRulesNotExistsException) BanAlreadyExistsException(cz.metacentrum.perun.core.api.exceptions.BanAlreadyExistsException) InvalidSponsoredUserDataException(cz.metacentrum.perun.core.api.exceptions.InvalidSponsoredUserDataException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) AlreadySponsoredMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsoredMemberException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) MemberNotValidYetException(cz.metacentrum.perun.core.api.exceptions.MemberNotValidYetException) SubjectNotExistsException(cz.metacentrum.perun.core.api.exceptions.SubjectNotExistsException) CandidateNotExistsException(cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) PasswordStrengthException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) SponsorshipDoesNotExistException(cz.metacentrum.perun.core.api.exceptions.SponsorshipDoesNotExistException) AttributeValueException(cz.metacentrum.perun.core.api.exceptions.AttributeValueException) UserNotInRoleException(cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) ExtSourceSimpleApi(cz.metacentrum.perun.core.implApi.ExtSourceSimpleApi) CandidateNotExistsException(cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException)

Example 22 with Candidate

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);
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) Group(cz.metacentrum.perun.core.api.Group) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Resource(cz.metacentrum.perun.core.api.Resource) Vo(cz.metacentrum.perun.core.api.Vo) Host(cz.metacentrum.perun.core.api.Host) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Facility(cz.metacentrum.perun.core.api.Facility)

Example 23 with Candidate

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());
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) User(cz.metacentrum.perun.core.api.User) 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 24 with Candidate

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));
}
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 25 with Candidate

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;
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) Attribute(cz.metacentrum.perun.core.api.Attribute) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

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