Search in sources :

Example 46 with ExtSource

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

the class GroupsManagerEntryIntegrationTest method getGroupsWithAssignedExtSourceInVo.

@Test
public void getGroupsWithAssignedExtSourceInVo() throws Exception {
    System.out.println(CLASS_NAME + "getGroupsWithAssignedExtSourceInVo");
    vo = setUpVo();
    groupsManagerBl.createGroup(sess, vo, group);
    groupsManagerBl.createGroup(sess, vo, group2);
    ExtSource newExtSource = new ExtSource("ExtSourcesManagerEntryIntegrationTest1", ExtSourcesManager.EXTSOURCE_INTERNAL);
    newExtSource = perun.getExtSourcesManager().createExtSource(sess, newExtSource, null);
    perun.getExtSourcesManagerBl().addExtSource(sess, vo, newExtSource);
    perun.getExtSourcesManagerBl().addExtSource(sess, group, newExtSource);
    perun.getExtSourcesManagerBl().addExtSource(sess, group2, newExtSource);
    final List<Group> groups = groupsManagerBl.getGroupsWithAssignedExtSourceInVo(sess, newExtSource, vo);
    assertTrue(groups.contains(group));
    assertTrue(groups.contains(group2));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) RichGroup(cz.metacentrum.perun.core.api.RichGroup) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 47 with ExtSource

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

the class GroupsManagerEntryIntegrationTest method getGroupToSynchronize.

@Test
public void getGroupToSynchronize() throws Exception {
    System.out.println(CLASS_NAME + "getGroupToSynchronize");
    vo = setUpVo();
    setUpGroup(vo);
    ExtSource es = perun.getExtSourcesManagerBl().createExtSource(sess, extSource, null);
    perun.getExtSourcesManagerBl().addExtSource(sess, vo, es);
    perun.getGroupsManager().createGroup(sess, vo, group2);
    Attribute synchroAttr1 = new Attribute(perun.getAttributesManager().getAttributeDefinition(sess, GroupsManager.GROUPSYNCHROINTERVAL_ATTRNAME));
    synchroAttr1.setValue("5");
    perun.getAttributesManager().setAttribute(sess, group, synchroAttr1);
    perun.getAttributesManager().setAttribute(sess, group2, synchroAttr1);
    Attribute synchroAttr2 = new Attribute(perun.getAttributesManager().getAttributeDefinition(sess, GroupsManager.GROUPEXTSOURCE_ATTRNAME));
    synchroAttr2.setValue(es.getName());
    perun.getAttributesManager().setAttribute(sess, group, synchroAttr2);
    perun.getAttributesManager().setAttribute(sess, group2, synchroAttr2);
    Attribute synchroAttr3 = new Attribute(perun.getAttributesManager().getAttributeDefinition(sess, GroupsManager.GROUPMEMBERSQUERY_ATTRNAME));
    synchroAttr3.setValue("testVal");
    perun.getAttributesManager().setAttribute(sess, group, synchroAttr3);
    perun.getAttributesManager().setAttribute(sess, group2, synchroAttr3);
    Attribute synchroAttr4 = new Attribute(perun.getAttributesManager().getAttributeDefinition(sess, GroupsManager.GROUPSYNCHROENABLED_ATTRNAME));
    synchroAttr4.setValue("true");
    perun.getAttributesManager().setAttribute(sess, group, synchroAttr4);
    perun.getAttributesManager().setAttribute(sess, group2, synchroAttr4);
    List<Group> groups = groupsManagerBl.getGroupsToSynchronize(sess);
    assertTrue("List of groups to synchronize contain group.", groups.contains(group));
    assertTrue("List of groups to synchronize contain group2.", groups.contains(group2));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) RichGroup(cz.metacentrum.perun.core.api.RichGroup) Attribute(cz.metacentrum.perun.core.api.Attribute) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 48 with ExtSource

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

the class ModulesUtilsEntryIntegrationTest method setUpMember.

private Member setUpMember() throws Exception {
    String userFirstName = Long.toHexString(Double.doubleToLongBits(Math.random()));
    String userLastName = Long.toHexString(Double.doubleToLongBits(Math.random()));
    // his login in external source
    String extLogin = Long.toHexString(Double.doubleToLongBits(Math.random()));
    // Mockito.mock(Candidate.class);
    Candidate candidate = new Candidate();
    candidate.setFirstName(userFirstName);
    candidate.setId(0);
    candidate.setMiddleName("");
    candidate.setLastName(userLastName);
    candidate.setTitleBefore("");
    candidate.setTitleAfter("");
    UserExtSource userExtSource = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), extLogin);
    candidate.setUserExtSource(userExtSource);
    candidate.setAttributes(new HashMap<>());
    Member member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
    assertNotNull("No member created", member);
    usersForDeletion.add(perun.getUsersManager().getUserByMember(sess, member));
    // save user for deletion after test
    return member;
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Member(cz.metacentrum.perun.core.api.Member)

Example 49 with ExtSource

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

the class urn_perun_user_attribute_def_virt_studentIdentifiers method processRemoveUserExtSource.

/**
 * Remove userExtSource with attributes for member's user if exists.
 *
 * @param sess Perun session
 * @param group from which appropriate attributes will be obtained
 * @param member for which the xtSource with attributes will be processed
 */
private void processRemoveUserExtSource(PerunSessionImpl sess, Group group, Member member) {
    User user = sess.getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
    Attribute organizationScope = tryGetAttribute(sess, group, A_G_D_organizationScopeFriendlyName);
    if (organizationScope == null || organizationScope.getValue() == null) {
        return;
    }
    Attribute organizationNamespace = this.tryGetAttribute(sess, group, A_G_D_organizationNamespaceFriendlyName);
    if (organizationNamespace == null || organizationNamespace.getValue() == null) {
        return;
    }
    Attribute userLoginID = tryGetAttribute(sess, user, A_U_D_loginNamespaceFriendlyNamePrefix + organizationNamespace.valueAsString());
    if (userLoginID == null || userLoginID.getValue() == null) {
        return;
    }
    ExtSource extSource = tryGetExtSource(sess, organizationScope.valueAsString());
    // Remove userExtSource if exists
    try {
        UserExtSource ues = sess.getPerunBl().getUsersManagerBl().getUserExtSourceByExtLogin(sess, extSource, userLoginID.valueAsString());
        sess.getPerunBl().getUsersManagerBl().removeUserExtSource(sess, user, ues);
    } catch (UserExtSourceNotExistsException e) {
    // Means that the ues was already removed, which is ok
    } catch (UserExtSourceAlreadyRemovedException e) {
        // Should not happened
        throw new InternalErrorException(e);
    }
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) UserExtSourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceAlreadyRemovedException) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 50 with ExtSource

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

the class VosManagerEntryIntegrationTest method prepareCandidate.

private Candidate prepareCandidate() {
    String userFirstName = Long.toHexString(Double.doubleToLongBits(Math.random()));
    String userLastName = Long.toHexString(Double.doubleToLongBits(Math.random()));
    // his login in external source
    String extLogin = Long.toHexString(Double.doubleToLongBits(Math.random()));
    // Mockito.mock(Candidate.class);
    final Candidate candidate = new Candidate();
    candidate.setFirstName(userFirstName);
    candidate.setId(0);
    candidate.setMiddleName("");
    candidate.setLastName(userLastName);
    candidate.setTitleBefore("");
    candidate.setTitleAfter("");
    final ExtSource extSource = new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal");
    final UserExtSource userExtSource = new UserExtSource(extSource, extLogin);
    candidate.setUserExtSource(userExtSource);
    candidate.setAttributes(new HashMap<>());
    return candidate;
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) MemberCandidate(cz.metacentrum.perun.core.api.MemberCandidate) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource)

Aggregations

ExtSource (cz.metacentrum.perun.core.api.ExtSource)135 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)110 Test (org.junit.Test)57 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)52 Attribute (cz.metacentrum.perun.core.api.Attribute)40 User (cz.metacentrum.perun.core.api.User)40 Vo (cz.metacentrum.perun.core.api.Vo)38 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)35 Member (cz.metacentrum.perun.core.api.Member)31 ExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)30 UserExtSourceExistsException (cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException)28 Candidate (cz.metacentrum.perun.core.api.Candidate)27 RichUserExtSource (cz.metacentrum.perun.core.api.RichUserExtSource)27 ArrayList (java.util.ArrayList)25 Group (cz.metacentrum.perun.core.api.Group)23 LinkedHashMap (java.util.LinkedHashMap)20 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)19 RichMember (cz.metacentrum.perun.core.api.RichMember)17 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)17 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)16