Search in sources :

Example 1 with MemberCandidate

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

the class VosManagerBlImplUnitTest method createMemberCandidatesReturnsOnlyOneMemberCandidateForDuplicateUsers.

@Test
public void createMemberCandidatesReturnsOnlyOneMemberCandidateForDuplicateUsers() throws Exception {
    User user = new User();
    RichUser richUser = new RichUser();
    when(vosManagerBlSpy.getPerunBl().getUsersManagerBl().getUserByUserExtSources(any(), any())).thenReturn(user);
    when(candidate1.getUserExtSources()).thenReturn(Collections.emptyList());
    when(candidate2.getUserExtSources()).thenReturn(Collections.emptyList());
    when(vosManagerBlSpy.getPerunBl().getUsersManagerBl().convertUserToRichUserWithAttributesByNames(any(), any(), any())).thenReturn(richUser);
    List<MemberCandidate> memberCandidates = vosManagerBlSpy.createMemberCandidates(sess, Collections.emptyList(), vo, group, Arrays.asList(candidate1, candidate2), Collections.emptyList());
    assertThat(memberCandidates).hasSize(1);
}
Also used : RichUser(cz.metacentrum.perun.core.api.RichUser) User(cz.metacentrum.perun.core.api.User) MemberCandidate(cz.metacentrum.perun.core.api.MemberCandidate) RichUser(cz.metacentrum.perun.core.api.RichUser) Test(org.junit.Test)

Example 2 with MemberCandidate

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

the class VosManagerBlImplUnitTest method createMemberCandidatesReturnsUser.

@Test
public void createMemberCandidatesReturnsUser() throws Exception {
    User user = new User();
    RichUser richUser = new RichUser();
    when(vosManagerBlSpy.getPerunBl().getUsersManagerBl().getUserByUserExtSources(any(), any())).thenReturn(user);
    when(candidate1.getUserExtSources()).thenReturn(Collections.emptyList());
    when(vosManagerBlSpy.getPerunBl().getUsersManagerBl().convertUserToRichUserWithAttributesByNames(any(), any(), any())).thenReturn(richUser);
    List<MemberCandidate> memberCandidates = vosManagerBlSpy.createMemberCandidates(sess, Collections.emptyList(), vo, group, Arrays.asList(candidate1), Collections.emptyList());
    assertThat(memberCandidates).hasSize(1);
    assertThat(memberCandidates.get(0).getRichUser()).isEqualTo(candidate1);
    assertThat(memberCandidates.get(0).getCandidate()).isNull();
}
Also used : RichUser(cz.metacentrum.perun.core.api.RichUser) User(cz.metacentrum.perun.core.api.User) MemberCandidate(cz.metacentrum.perun.core.api.MemberCandidate) RichUser(cz.metacentrum.perun.core.api.RichUser) Test(org.junit.Test)

Example 3 with MemberCandidate

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

the class VosManagerEntry method filterMemberCandidates.

/**
 * Filters member candidates which were found via extSource of given group / vo or principal has right to read them
 * @param sess session
 * @param candidates candidates
 * @param extSources extSources of group or vo where candidate is suggested
 * @return list of eligible candidates
 */
private List<MemberCandidate> filterMemberCandidates(PerunSession sess, List<MemberCandidate> candidates, List<ExtSource> extSources) {
    List<MemberCandidate> eligibleCandidates = new ArrayList<>();
    // check principal can see candidates
    for (MemberCandidate candidate : candidates) {
        if (candidate.getRichUser() == null) {
            if (candidate.getCandidate().getUserExtSources().stream().map(UserExtSource::getExtSource).anyMatch(extSources::contains)) {
                eligibleCandidates.add(candidate);
            }
            continue;
        }
        if (candidate.getRichUser().getUserExtSources().stream().map(UserExtSource::getExtSource).anyMatch(extSources::contains)) {
            // ext sources of candidate match some of vo's / group's ext sources
            eligibleCandidates.add(candidate);
            continue;
        }
        List<Vo> membersVos = perunBl.getUsersManagerBl().getVosWhereUserIsMember(sess, candidate.getRichUser());
        boolean isEligible = membersVos.stream().anyMatch(vo -> AuthzResolver.authorizedInternal(sess, "filter-getCompleteCandidates_policy", vo));
        if (isEligible) {
            eligibleCandidates.add(candidate);
        }
    }
    return eligibleCandidates;
}
Also used : MemberCandidate(cz.metacentrum.perun.core.api.MemberCandidate) ArrayList(java.util.ArrayList) BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) Vo(cz.metacentrum.perun.core.api.Vo)

Example 4 with MemberCandidate

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

the class VosManagerEntry method getCompleteCandidates.

@Override
public List<MemberCandidate> getCompleteCandidates(PerunSession sess, Group group, List<String> attrNames, String searchString) throws GroupNotExistsException, PrivilegeException {
    Utils.notNull(searchString, "searchString");
    Utils.notNull(sess, "sess");
    Utils.notNull(group, "group");
    Utils.notNull(attrNames, "attrNames");
    getPerunBl().getGroupsManagerBl().checkGroupExists(sess, group);
    List<ExtSource> extSources;
    Vo vo = getPerunBl().getGroupsManagerBl().getVo(sess, group);
    // Authorization
    if (AuthzResolver.authorizedInternal(sess, "getCompleteCandidates_Group_List<String>_String_policy", vo)) {
        extSources = getPerunBl().getExtSourcesManagerBl().getVoExtSources(sess, vo);
        // null the vo so users are searched in whole perun
        vo = null;
    } else if (AuthzResolver.authorizedInternal(sess, "groupExtSource-getCompleteCandidates_Group_List<String>_String_policy", group)) {
        extSources = getPerunBl().getExtSourcesManagerBl().getGroupExtSources(sess, group);
    } else {
        throw new PrivilegeException(sess, "getCompleteCandidates");
    }
    List<MemberCandidate> candidates = vosManagerBl.getCompleteCandidates(sess, vo, group, attrNames, searchString, extSources);
    return filterMemberCandidates(sess, candidates, extSources);
}
Also used : MemberCandidate(cz.metacentrum.perun.core.api.MemberCandidate) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) Vo(cz.metacentrum.perun.core.api.Vo) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource)

Example 5 with MemberCandidate

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

the class VosManagerEntryIntegrationTest method getCompleteCandidatesFromGroupWithNullVo.

@Test
public void getCompleteCandidatesFromGroupWithNullVo() throws Exception {
    System.out.println(CLASS_NAME + "getCompleteCandidatesFromGroupWithNullVo");
    // create group and vo
    myVo = perun.getVosManagerBl().createVo(sess, myVo);
    Group group = new Group("testGroup", "testingGroup");
    Group returnedGroup = perun.getGroupsManager().createGroup(sess, myVo, group);
    // prepare second extSource
    ExtSource extSource = new ExtSource("testExtSource", ExtSourcesManager.EXTSOURCE_INTERNAL);
    extSource = perun.getExtSourcesManagerBl().createExtSource(sess, extSource, null);
    // prepare users to be returned by getCompleteCandidates
    Candidate candidate = prepareCandidateWithExtSource("Jan", es);
    User userToContain1 = perun.getUsersManagerBl().getRichUser(sess, perun.getUsersManagerBl().createUser(sess, candidate));
    candidate = prepareCandidateWithExtSource("Josef", es);
    User userNotToContain1 = perun.getUsersManagerBl().getRichUser(sess, perun.getUsersManagerBl().createUser(sess, candidate));
    candidate = prepareCandidateWithExtSource("Jana", extSource);
    RichUser userToContain2 = perun.getUsersManagerBl().getRichUser(sess, perun.getUsersManagerBl().createUser(sess, candidate));
    List<MemberCandidate> completeCandidates = perun.getVosManagerBl().getCompleteCandidates(sess, null, returnedGroup, null, "jan", Arrays.asList(es));
    List<RichUser> usersOfCompleteCandidates = completeCandidates.stream().map(MemberCandidate::getRichUser).collect(Collectors.toList());
    assertEquals("Three users should have been returned.", 2, usersOfCompleteCandidates.size());
    assertTrue("User should've been returned.", usersOfCompleteCandidates.contains(userToContain1));
    assertTrue("User should've been returned.", usersOfCompleteCandidates.contains(userToContain2));
    assertFalse("User shouldn't have been returned.", usersOfCompleteCandidates.contains(userNotToContain1));
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) MemberCandidate(cz.metacentrum.perun.core.api.MemberCandidate) Group(cz.metacentrum.perun.core.api.Group) RichUser(cz.metacentrum.perun.core.api.RichUser) User(cz.metacentrum.perun.core.api.User) MemberCandidate(cz.metacentrum.perun.core.api.MemberCandidate) RichUser(cz.metacentrum.perun.core.api.RichUser) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

MemberCandidate (cz.metacentrum.perun.core.api.MemberCandidate)7 RichUser (cz.metacentrum.perun.core.api.RichUser)5 User (cz.metacentrum.perun.core.api.User)5 Test (org.junit.Test)4 Candidate (cz.metacentrum.perun.core.api.Candidate)3 ExtSource (cz.metacentrum.perun.core.api.ExtSource)3 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)3 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)2 BanOnVo (cz.metacentrum.perun.core.api.BanOnVo)2 Group (cz.metacentrum.perun.core.api.Group)2 Member (cz.metacentrum.perun.core.api.Member)2 Vo (cz.metacentrum.perun.core.api.Vo)2 ArrayList (java.util.ArrayList)2 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)1 NotGroupMemberException (cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException)1 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)1 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)1 HashSet (java.util.HashSet)1