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