Search in sources :

Example 51 with UserExtSource

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

the class MembersManagerBlImpl method createMember.

/*
	 * This method 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, 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);
    // 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 52 with UserExtSource

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

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

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

the class urn_perun_user_attribute_def_virt_userCertDNs method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
    Attribute attribute = new Attribute(attributeDefinition);
    Map<String, String> userCertDNs = new LinkedHashMap<>();
    List<UserExtSource> userExtSources = sess.getPerunBl().getUsersManagerBl().getUserExtSources(sess, user);
    //Sort user ext sources by their ids (biggest id go last)
    Collections.sort(userExtSources, (ues1, ues2) -> ues1.getId() - ues2.getId());
    //Prepare also prefix number
    int i = 1;
    for (UserExtSource uES : userExtSources) {
        if (uES.getExtSource() != null) {
            String login = uES.getLogin();
            String type = uES.getExtSource().getType();
            String name = uES.getExtSource().getName();
            if (type != null && login != null && name != null && type.equals(ExtSourcesManager.EXTSOURCE_X509)) {
                userCertDNs.put(i + ":" + login, name);
                i++;
            }
        }
    }
    attribute.setValue(userCertDNs);
    return attribute;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource)

Example 55 with UserExtSource

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

the class AttributesManagerEntryIntegrationTest method getUserExtSourceAttributes.

@Test
public void getUserExtSourceAttributes() throws Exception {
    System.out.println(CLASS_NAME + "getUserExtSourceAttributes");
    UserExtSource ues = setUpUserExtSourceTest();
    attributes = setUpUserExtSourceAttribute();
    attributesManager.setAttribute(sess, ues, attributes.get(0));
    List<Attribute> retAttr = attributesManager.getAttributes(sess, ues);
    assertNotNull("unable to get ues attributes", retAttr);
    assertTrue("our attribute was not returned", retAttr.contains(attributes.get(0)));
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

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