Search in sources :

Example 21 with UserExtSource

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

the class UsersManagerEntryIntegrationTest method setUpUserExtSource.

private void setUpUserExtSource() throws Exception {
    ExtSource externalSource = perun.getExtSourcesManager().getExtSourceByName(sess, extSourceName);
    // gets real external source object from database
    userExtSource.setExtSource(externalSource);
    // put real external source into user's external source
    userExtSource.setLogin(extLogin);
    // set users login in his ext source
    assertNotNull(usersManager.addUserExtSource(sess, user, userExtSource));
// create new user ext source in database
}
Also used : ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource)

Example 22 with UserExtSource

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

the class ExtSourcePerun method covertRichUserToSubject.

private Map<String, String> covertRichUserToSubject(RichUser richUser) throws InternalErrorException {
    Map<String, String> richUserInMap = new HashMap<String, String>();
    String mapping = getAttributes().get("xmlMapping");
    String[] mappingArray = mapping.split(",\n");
    //Get user login
    String login = "";
    for (UserExtSource ues : richUser.getUserExtSources()) {
        if (ues.getExtSource() != null && ues.getExtSource().getName().equals(extSourceNameForLogin)) {
            login = ues.getLogin();
            break;
        }
    }
    //Null login is not allowed there
    if (login == null)
        throw new InternalErrorException("There is missing login for user " + richUser + " and extSource " + extSourceNameForLogin);
    for (int i = 0; i < mappingArray.length; i++) {
        String attr = mappingArray[i].trim();
        int index = attr.indexOf("=");
        if (index <= 0)
            throw new InternalErrorException("There is no text in xmlMapping attribute or there is no '=' character.");
        String name = attr.substring(0, index);
        String value = attr.substring(index + 1);
        Matcher attributeMatcher = attributePattern.matcher(value);
        //Try to find perun attributes in value part
        if (attributeMatcher.find()) {
            if (attributeMatcher.group(1).equals("login")) {
                value = attributeMatcher.replaceFirst(login);
            } else {
                String replacement = lookingForValueInRichUserAttributes(attributeMatcher.group(1), richUser);
                if (replacement == null)
                    replacement = "";
                value = attributeMatcher.replaceFirst(replacement);
                //If whole value is empty because of replacement, it means null for us
                if (value.isEmpty())
                    value = null;
            }
        } else if (value.startsWith("urn:perun:")) {
            //DEPRECATED, but need to be first removed from all settings of PerunExtSource in perun-extSource.xml file
            //It is probably old way how to use attribute (without {}) so try to find value for it
            value = lookingForValueInRichUserAttributes(value, richUser);
        }
        //If nothing found, let the value be the same, it is probably static value (without any attribute)
        richUserInMap.put(name.trim(), value);
    }
    return richUserInMap;
}
Also used : HashMap(java.util.HashMap) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Matcher(java.util.regex.Matcher) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 23 with UserExtSource

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

the class urn_perun_member_attribute_def_virt_loa method getAttributeValue.

public Attribute getAttributeValue(PerunSessionImpl sess, Member member, AttributeDefinition attributeDefinition) throws InternalErrorException {
    User user = null;
    try {
        user = sess.getPerunBl().getUsersManagerBl().getUserById(sess, member.getUserId());
    } catch (UserNotExistsException ex) {
        throw new InternalErrorException("There is no user for get member " + member, ex);
    }
    List<UserExtSource> extSources = sess.getPerunBl().getUsersManagerBl().getActiveUserExtSources(sess, user);
    Integer maxLoa = 0;
    for (UserExtSource e : extSources) {
        if (maxLoa < e.getLoa())
            maxLoa = e.getLoa();
    }
    Attribute attribute = new Attribute(attributeDefinition);
    attribute.setValue(maxLoa.toString());
    return attribute;
}
Also used : User(cz.metacentrum.perun.core.api.User) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Attribute(cz.metacentrum.perun.core.api.Attribute)

Example 24 with UserExtSource

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

the class MuPasswordManagerModule method getUcoFromSessionUser.

/**
	 * Return MU UCO of a pwdmanager method caller from his UserExtSource in MU IdP.
	 *
	 * @param session Session to get user and identity from
	 * @return Part of API call params like: "<zmenil>UČO</zmenil>" or empty string.
	 */
private String getUcoFromSessionUser(PerunSession session) {
    PerunBl perunBl = (PerunBl) session.getPerun();
    List<UserExtSource> ueses = null;
    try {
        if (session.getPerunPrincipal().getUser() != null) {
            ueses = perunBl.getUsersManagerBl().getUserExtSources(session, session.getPerunPrincipal().getUser());
        } else {
            return "";
        }
    } catch (Exception ex) {
        return "";
    }
    for (UserExtSource extSource : ueses) {
        if (extSource.getExtSource().getName().equals("https://idp2.ics.muni.cz/idp/shibboleth") && extSource.getExtSource().getType().equals(ExtSourcesManager.EXTSOURCE_IDP)) {
            String login = extSource.getLogin();
            if (login != null) {
                return "<zmenil>" + login.split("@")[0] + "</zmenil>\n";
            }
        }
    }
    return "";
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 25 with UserExtSource

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

the class AttributesManagerEntryIntegrationTest method getUserExtSourceAttributeWhenWrongAttrAssignment.

@Test(expected = WrongAttributeAssignmentException.class)
public void getUserExtSourceAttributeWhenWrongAttrAssignment() throws Exception {
    System.out.println(CLASS_NAME + "getUserExtSourceAttributeWhenWrongAttrAssignment");
    UserExtSource ues = setUpUserExtSourceTest();
    attributesManager.getAttribute(sess, ues, "urn:perun:vo:attribute-def:core:id");
// shouldn't find vo attribute on user external source
}
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