Search in sources :

Example 6 with UserExtSource

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

the class urn_perun_user_attribute_def_virt_eduPersonPrincipalNames method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
    Attribute attribute = new Attribute(attributeDefinition);
    List<String> idpLogins = new ArrayList<String>();
    List<UserExtSource> userExtSources = sess.getPerunBl().getUsersManagerBl().getUserExtSources(sess, user);
    for (UserExtSource uES : userExtSources) {
        if (uES.getExtSource() != null) {
            String login = uES.getLogin();
            String type = uES.getExtSource().getType();
            if (type != null && login != null) {
                // insert only EPPN formatted data
                if (type.equals(ExtSourcesManager.EXTSOURCE_IDP) && login.matches("[^@]+@[^@]+")) {
                    idpLogins.add(login);
                }
            }
        }
    }
    attribute = new Attribute(attributeDefinition);
    attribute.setValue(idpLogins);
    return attribute;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ArrayList(java.util.ArrayList)

Example 7 with UserExtSource

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

the class AttributesManagerEntryIntegrationTest method getUserExtSourceAttributeByIdWhenAttributeNotExists.

@Test(expected = AttributeNotExistsException.class)
public void getUserExtSourceAttributeByIdWhenAttributeNotExists() throws Exception {
    System.out.println(CLASS_NAME + "getUserExtSourceAttributeByIdWhenAttributeNotExists");
    UserExtSource ues = setUpUserExtSourceTest();
    attributesManager.getAttributeById(sess, ues, 0);
// shouldn't find attribute
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 8 with UserExtSource

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

the class AttributesManagerEntryIntegrationTest method getUserExtSourceAttribute.

@Test
public void getUserExtSourceAttribute() throws Exception {
    System.out.println(CLASS_NAME + "getUserExtSourceAttribute");
    UserExtSource ues = setUpUserExtSourceTest();
    attributes = setUpUserExtSourceAttribute();
    attributesManager.setAttributes(sess, ues, attributes);
    Attribute retAttr = attributesManager.getAttribute(sess, ues, "urn:perun:ues:attribute-def:opt:userExtSource-test-attribute");
    assertNotNull("unable to get opt user external source attribute ", retAttr);
    assertEquals("returned opt attr value is not correct", retAttr.getValue(), attributes.get(0).getValue());
}
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)

Example 9 with UserExtSource

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

the class AttributesManagerEntryIntegrationTest method getUserExtSourceAttributeById.

@Test
public void getUserExtSourceAttributeById() throws Exception {
    System.out.println(CLASS_NAME + "getUserExtSourceAttributeById");
    UserExtSource ues = setUpUserExtSourceTest();
    attributes = setUpUserExtSourceAttribute();
    attributesManager.setAttributes(sess, ues, attributes);
    int id = attributes.get(0).getId();
    Attribute retAttr = attributesManager.getAttributeById(sess, ues, id);
    assertNotNull("unable to get userExtSource attribute by id", retAttr);
    assertEquals("returned attribute is not same as stored", retAttr, 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)

Example 10 with UserExtSource

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

the class AttributesManagerEntryIntegrationTest method setUserExtSourceAttributeWhenWrongAttrAssignment.

@Test(expected = WrongAttributeAssignmentException.class)
public void setUserExtSourceAttributeWhenWrongAttrAssignment() throws Exception {
    System.out.println(CLASS_NAME + "setUserExtSourceAttributeWhenWrongAttrAssignment");
    UserExtSource ues = setUpUserExtSourceTest();
    attributes = setUpVoAttribute();
    attributesManager.setAttribute(sess, ues, attributes.get(0));
// shouldn't add vo attribute into userExtSource
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) 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