Search in sources :

Example 41 with ExtSource

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

the class MembersManagerBlImpl method createMember.

/*
	 * This method with support of LoA finally has to call this.createMember(PerunSession sess, Vo vo, UserExtSource userExtSource)
	 * @see cz.metacentrum.perun.core.api.MembersManager#createMember(cz.metacentrum.perun.core.api.PerunSession, cz.metacentrum.perun.core.api.Vo, java.lang.String, java.lang.String, java.lang.String, cz.metacentrum.perun.core.api.Candidate)
	 */
public Member createMember(PerunSession sess, Vo vo, String extSourceName, String extSourceType, int loa, String login, Candidate candidate, List<Group> groups) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, ExtendMembershipException, GroupOperationsException {
    // Create ExtSource object
    ExtSource extSource = new ExtSource();
    extSource.setName(extSourceName);
    extSource.setType(extSourceType);
    // Create UserExtSource object
    UserExtSource userExtSource = new UserExtSource();
    userExtSource.setLogin(login);
    userExtSource.setExtSource(extSource);
    userExtSource.setLoa(loa);
    // Set all above data to the candidate's userExtSource
    candidate.setUserExtSource(userExtSource);
    return this.createMember(sess, vo, candidate, groups);
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource)

Example 42 with ExtSource

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

the class urn_perun_user_attribute_def_virt_optionalLogin_namespace_mu method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
    Attribute attribute = new Attribute(attributeDefinition);
    try {
        Attribute loginInMU = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:mu");
        attribute = Utils.copyAttributeToVirtualAttributeWithValue(loginInMU, attribute);
    } catch (AttributeNotExistsException ex) {
    //That means that mu login attribute not exists at all
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException(ex);
    }
    //if attribute is still null (empty login in mu or not existing attribute), try to find uco in user ext sources
    if (attribute.getValue() == null) {
        List<UserExtSource> userExtSources = sess.getPerunBl().getUsersManagerBl().getUserExtSources(sess, user);
        for (UserExtSource userExtSource : userExtSources) {
            ExtSource extSource = userExtSource.getExtSource();
            //Skip if extSource is not the one we are looking for
            if (userExtSource.getLogin() == null || extSource == null)
                continue;
            if (!ExtSourcesManager.EXTSOURCE_IDP.equals(extSource.getType()))
                continue;
            if (!EXTSOURCE_MUNI_IDP2.equals(extSource.getName()))
                continue;
            //Get login from this extSource and get only UCO from it
            String login = userExtSource.getLogin();
            Matcher loginMUMatcher = loginMUPattern.matcher(login);
            //This user has login in mu, but in weird format so skip this one
            if (!loginMUMatcher.find())
                continue;
            //It is ok, take UCO from login and set it to attribute value
            String UCO = loginMUMatcher.group(1);
            attribute.setValue(UCO);
            break;
        }
    }
    return attribute;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Matcher(java.util.regex.Matcher) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource)

Example 43 with ExtSource

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

the class ExtSourcesManagerImpl method createExtSource.

public ExtSource createExtSource(PerunSession sess, ExtSource extSource, Map<String, String> attributes) throws InternalErrorException, ExtSourceExistsException {
    Utils.notNull(extSource.getName(), "extSource.getName()");
    Utils.notNull(extSource.getType(), "extSource.getType()");
    try {
        // Check if the extSources already exists
        if (0 < jdbc.queryForInt("select count(id) from ext_sources where name=? and type=?", extSource.getName(), extSource.getType())) {
            throw new ExtSourceExistsException(extSource);
        }
        // Get a new Id
        int newId = Utils.getNewId(jdbc, "ext_sources_id_seq");
        jdbc.update("insert into ext_sources (id, name, type, created_by,created_at,modified_by,modified_at,created_by_uid,modified_by_uid) " + "values (?,?,?,?," + Compatibility.getSysdate() + ",?," + Compatibility.getSysdate() + ",?,?)", newId, extSource.getName(), extSource.getType(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), sess.getPerunPrincipal().getUserId());
        extSource.setId(newId);
        ExtSource es;
        // Get the instance by the type of the extSource
        try {
            Class<?> extSourceClass = Class.forName((String) extSource.getType());
            es = (ExtSource) extSourceClass.newInstance();
        } catch (ClassNotFoundException e) {
            throw new InternalErrorException(e);
        } catch (InstantiationException e) {
            throw new InternalErrorRuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new InternalErrorRuntimeException(e);
        }
        // Set the properties
        es.setId(extSource.getId());
        es.setName(extSource.getName());
        es.setType(extSource.getType());
        // Now store the attributes
        if (attributes != null) {
            Iterator<String> i = attributes.keySet().iterator();
            while (i.hasNext()) {
                String attr_name = i.next();
                jdbc.update("insert into ext_sources_attributes (attr_name, attr_value, ext_sources_id,created_by, created_at, modified_by, modified_at, created_by_uid, modified_by_uid) " + "values (?,?,?,?," + Compatibility.getSysdate() + ",?," + Compatibility.getSysdate() + ",?,?)", attr_name, attributes.get(attr_name), extSource.getId(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), sess.getPerunPrincipal().getUserId());
            }
        }
        // Assign newly created extSource
        extSource = es;
        return extSource;
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) ExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceExistsException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) ExtSource(cz.metacentrum.perun.core.api.ExtSource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 44 with ExtSource

use of cz.metacentrum.perun.core.api.ExtSource 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 45 with ExtSource

use of cz.metacentrum.perun.core.api.ExtSource 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)

Aggregations

ExtSource (cz.metacentrum.perun.core.api.ExtSource)58 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)36 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)24 Test (org.junit.Test)24 Vo (cz.metacentrum.perun.core.api.Vo)16 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)13 Candidate (cz.metacentrum.perun.core.api.Candidate)12 Group (cz.metacentrum.perun.core.api.Group)11 ExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)10 Member (cz.metacentrum.perun.core.api.Member)8 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)8 ArrayList (java.util.ArrayList)5 Attribute (cz.metacentrum.perun.core.api.Attribute)4 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)4 CandidateNotExistsException (cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException)4 ExtSourceExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceExistsException)4 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)4 HashMap (java.util.HashMap)4 User (cz.metacentrum.perun.core.api.User)3 ExtSourceUnsupportedOperationException (cz.metacentrum.perun.core.api.exceptions.ExtSourceUnsupportedOperationException)3