Search in sources :

Example 61 with UserExtSource

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

the class AttributesManagerEntryIntegrationTest 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<String, String>());
    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 62 with UserExtSource

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

the class AttributesManagerEntryIntegrationTest method setUpUserExtSource.

private UserExtSource setUpUserExtSource() throws Exception {
    String extSourceName = "AttributesManagerEntryIntegrationTest";
    ExtSource extSource = new ExtSource(extSourceName, ExtSourcesManager.EXTSOURCE_INTERNAL);
    extSource = perun.getExtSourcesManager().createExtSource(sess, extSource, new HashMap<String, String>());
    UserExtSource userExtSource = new UserExtSource(0, extSource, "let's fake it");
    return userExtSource;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource)

Example 63 with UserExtSource

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

the class Utils method generateAllUsersToWriter.

/**
	 * Method generate all Users to the text for using in LDIF.
	 * Write all these information to writer in perunInitializer object.
	 *
	 * @param perunInitializer need to be loaded to get all needed dependencies
	 *
	 * @throws InternalErrorException if some problem with initializer or objects in perun-core
	 * @throws IOException if some problem with writer
	 * @throws AttributeNotExistsException
	 * @throws WrongAttributeAssignmentException
	 */
public static void generateAllUsersToWriter(PerunInitializer perunInitializer) throws IOException, InternalErrorException, AttributeNotExistsException, WrongAttributeAssignmentException {
    //Load basic variables
    if (perunInitializer == null)
        throw new InternalErrorException("PerunInitializer must be loaded before using in generating methods!");
    PerunSession perunSession = perunInitializer.getPerunSession();
    PerunBl perun = perunInitializer.getPerunBl();
    BufferedWriter writer = perunInitializer.getOutputWriter();
    List<User> users = perun.getUsersManagerBl().getUsers(perunSession);
    for (User user : users) {
        String dn = "dn: ";
        String entryStatus = "entryStatus: active";
        String oc1 = "objectclass: top";
        String oc2 = "objectclass: person";
        String oc3 = "objectclass: organizationalPerson";
        String oc4 = "objectclass: inetOrgPerson";
        String oc5 = "objectclass: perunUser";
        String oc6 = "objectclass: tenOperEntry";
        String oc7 = "objectclass: inetUser";
        String sn = "sn: ";
        String cn = "cn: ";
        String givenName = "givenName: ";
        String perunUserId = "perunUserId: ";
        String mail = "mail: ";
        String preferredMail = "preferredMail: ";
        String o = "o: ";
        String isServiceUser = "isServiceUser: ";
        String isSponsoredUser = "isSponsoredUser: ";
        String userPassword = "userPassword: ";
        List<String> membersOf = new ArrayList<>();
        List<Member> members;
        Set<String> membersOfPerunVo = new HashSet<>();
        members = perun.getMembersManagerBl().getMembersByUser(perunSession, user);
        for (Member member : members) {
            if (member.getStatus().equals(Status.VALID)) {
                membersOfPerunVo.add("memberOfPerunVo: " + member.getVoId());
                List<Group> groups;
                groups = perun.getGroupsManagerBl().getAllMemberGroups(perunSession, member);
                for (Group group : groups) {
                    membersOf.add("memberOf: " + "perunGroupId=" + group.getId() + ",perunVoId=" + group.getVoId() + ",dc=perun,dc=cesnet,dc=cz");
                }
            }
        }
        //Attribute attrMail = perun.getAttributesManagerBl().getAttribute(perunSession, u, AttributesManager.NS_USER_ATTR_DEF + ":mail");
        Attribute attrPreferredMail = perun.getAttributesManagerBl().getAttribute(perunSession, user, AttributesManager.NS_USER_ATTR_DEF + ":preferredMail");
        Attribute attrOrganization = perun.getAttributesManagerBl().getAttribute(perunSession, user, AttributesManager.NS_USER_ATTR_DEF + ":organization");
        Attribute attrVirtCertDNs = perun.getAttributesManagerBl().getAttribute(perunSession, user, AttributesManager.NS_USER_ATTR_VIRT + ":userCertDNs");
        Attribute attrLibraryIDs = perun.getAttributesManagerBl().getAttribute(perunSession, user, AttributesManager.NS_USER_ATTR_DEF + ":libraryIDs");
        perunUserId += String.valueOf(user.getId());
        dn += "perunUserId=" + user.getId() + ",ou=People,dc=perun,dc=cesnet,dc=cz";
        String firstName = user.getFirstName();
        String lastName = user.getLastName();
        if (firstName == null)
            firstName = "";
        if (lastName == null || lastName.isEmpty())
            lastName = "N/A";
        sn += lastName;
        cn += firstName + " " + lastName;
        if (user.isServiceUser())
            isServiceUser += "1";
        else
            isServiceUser += "0";
        if (user.isSponsoredUser())
            isSponsoredUser += "1";
        else
            isSponsoredUser += "0";
        if (firstName.isEmpty())
            givenName = null;
        else
            givenName += firstName;
        if (attrPreferredMail == null || attrPreferredMail.getValue() == null)
            mail = null;
        else
            mail += (String) attrPreferredMail.getValue();
        if (attrPreferredMail == null || attrPreferredMail.getValue() == null)
            preferredMail = null;
        else
            preferredMail += (String) attrPreferredMail.getValue();
        if (attrOrganization == null || attrOrganization.getValue() == null)
            o = null;
        else
            o += (String) attrOrganization.getValue();
        Map<String, String> certDNs = null;
        Set<String> certSubjectsWithPrefix = null;
        Set<String> certSubjectsWithoutPrefix = new HashSet<>();
        if (attrVirtCertDNs != null && attrVirtCertDNs.getValue() != null) {
            certDNs = (Map) attrVirtCertDNs.getValue();
            certSubjectsWithPrefix = certDNs.keySet();
            for (String certSubject : certSubjectsWithPrefix) {
                certSubjectsWithoutPrefix.add(certSubject.replaceFirst("^[0-9]+[:]", ""));
            }
        }
        writer.write(dn + '\n');
        writer.write(oc1 + '\n');
        writer.write(oc2 + '\n');
        writer.write(oc3 + '\n');
        writer.write(oc4 + '\n');
        writer.write(oc5 + '\n');
        writer.write(oc6 + '\n');
        writer.write(oc7 + '\n');
        writer.write(entryStatus + '\n');
        writer.write(sn + '\n');
        writer.write(cn + '\n');
        if (givenName != null)
            writer.write(givenName + '\n');
        writer.write(perunUserId + '\n');
        writer.write(isServiceUser + '\n');
        writer.write(isSponsoredUser + '\n');
        if (mail != null)
            writer.write(mail + '\n');
        if (preferredMail != null)
            writer.write(preferredMail + '\n');
        if (o != null)
            writer.write(o + '\n');
        if (certSubjectsWithoutPrefix != null && !certSubjectsWithoutPrefix.isEmpty()) {
            for (String s : certSubjectsWithoutPrefix) {
                writer.write("userCertificateSubject: " + s + '\n');
            }
        }
        List<String> libraryIDs = new ArrayList<>();
        if (attrLibraryIDs.getValue() != null) {
            libraryIDs = (ArrayList) attrLibraryIDs.getValue();
        }
        if (libraryIDs != null && !libraryIDs.isEmpty()) {
            for (String id : libraryIDs) {
                writer.write("libraryIDs: " + id + '\n');
            }
        }
        //GET ALL USERS UIDs
        List<String> similarUids = perun.getAttributesManagerBl().getAllSimilarAttributeNames(perunSession, AttributesManager.NS_USER_ATTR_DEF + ":uid-namespace:");
        if (similarUids != null && !similarUids.isEmpty()) {
            for (String s : similarUids) {
                Attribute uidNamespace = perun.getAttributesManagerBl().getAttribute(perunSession, user, s);
                if (uidNamespace != null && uidNamespace.getValue() != null) {
                    writer.write("uidNumber;x-ns-" + uidNamespace.getFriendlyNameParameter() + ": " + uidNamespace.getValue().toString() + '\n');
                }
            }
        }
        //GET ALL USERS LOGINs
        List<String> similarLogins = perun.getAttributesManagerBl().getAllSimilarAttributeNames(perunSession, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:");
        if (similarLogins != null && !similarLogins.isEmpty()) {
            for (String s : similarLogins) {
                Attribute loginNamespace = perun.getAttributesManagerBl().getAttribute(perunSession, user, s);
                if (loginNamespace != null && loginNamespace.getValue() != null) {
                    writer.write("login;x-ns-" + loginNamespace.getFriendlyNameParameter() + ": " + loginNamespace.getValue().toString() + '\n');
                    if (loginNamespace.getFriendlyNameParameter().equals("einfra")) {
                        writer.write(userPassword + "{SASL}" + loginNamespace.getValue().toString() + '@' + loginNamespace.getFriendlyNameParameter().toUpperCase() + '\n');
                    }
                }
            }
        }
        //GET ALL USERS EXTlogins FOR EVERY EXTSOURCE WITH TYPE EQUALS IDP
        List<UserExtSource> userExtSources = perun.getUsersManagerBl().getUserExtSources(perunSession, user);
        List<String> extLogins = new ArrayList<>();
        for (UserExtSource ues : userExtSources) {
            if (ues != null && ues.getExtSource() != null) {
                String type = ues.getExtSource().getType();
                if (type != null) {
                    if (type.equals(ExtSourcesManager.EXTSOURCE_IDP)) {
                        String extLogin;
                        extLogin = ues.getLogin();
                        if (extLogin == null)
                            extLogin = "";
                        writer.write("eduPersonPrincipalNames: " + extLogin + '\n');
                    }
                }
            }
        }
        //ADD MEMBEROF ATTRIBUTE TO WRITER
        for (String s : membersOf) {
            writer.write(s + '\n');
        }
        //ADD MEMBEROFPERUNVO ATTRIBUTE TO WRITER
        for (String s : membersOfPerunVo) {
            writer.write(s + '\n');
        }
        writer.write('\n');
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) PerunSession(cz.metacentrum.perun.core.api.PerunSession) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) BufferedWriter(java.io.BufferedWriter) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Member(cz.metacentrum.perun.core.api.Member) HashSet(java.util.HashSet)

Example 64 with UserExtSource

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

the class ServicesManagerEntryIntegrationTest 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()));
    Candidate candidate;
    //Mockito.mock(Candidate.class);
    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.setUserExtSource(ues);
    candidate.setAttributes(new HashMap<String, String>());
    Member createdMember = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
    assertNotNull("No member created", createdMember);
    usersForDeletion.add(perun.getUsersManager().getUserByMember(sess, createdMember));
    // save user for deletion after test
    return createdMember;
}
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 65 with UserExtSource

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

the class Candidate method serializeToString.

@Override
public String serializeToString() {
    StringBuilder str = new StringBuilder();
    String attrNew = BeansUtils.serializeMapToString(attributes);
    List<String> userESNew = new ArrayList<String>();
    List<UserExtSource> userESOld = getAdditionalUserExtSources();
    String sUserESNew;
    if (getAdditionalUserExtSources() == null)
        sUserESNew = "\\0";
    else {
        for (UserExtSource u : userESOld) {
            userESNew.add(u.serializeToString());
        }
        sUserESNew = userESNew.toString();
    }
    return str.append(this.getClass().getSimpleName()).append(":[" + "userExtSource=<").append(getUserExtSource() == null ? "\\0" : getUserExtSource().serializeToString()).append(">" + ", attributes=<").append(attrNew).append(">" + ", additionalUserExtSources=<").append(sUserESNew).append(">" + ']').toString();
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ArrayList(java.util.ArrayList)

Aggregations

UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)79 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)34 Test (org.junit.Test)34 ExtSource (cz.metacentrum.perun.core.api.ExtSource)28 Attribute (cz.metacentrum.perun.core.api.Attribute)19 Candidate (cz.metacentrum.perun.core.api.Candidate)18 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)14 User (cz.metacentrum.perun.core.api.User)12 Member (cz.metacentrum.perun.core.api.Member)11 ArrayList (java.util.ArrayList)11 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)8 Group (cz.metacentrum.perun.core.api.Group)7 ExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)6 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)5 HashMap (java.util.HashMap)5 RichUser (cz.metacentrum.perun.core.api.RichUser)4 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)4 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)4 Matcher (java.util.regex.Matcher)4 RichMember (cz.metacentrum.perun.core.api.RichMember)3