Search in sources :

Example 16 with UserExtSourceExistsException

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

the class urn_perun_user_attribute_def_def_login_namespace_myaccessid_persistent_shadow method changedAttributeHook.

/**
 * ChangedAttributeHook() sets UserExtSource with following properties:
 *  - extSourceType is IdP
 *  - extSourceName is {getExtSourceName()}
 *  - user's extSource login is the same as his persistent attribute
 */
@Override
public void changedAttributeHook(PerunSessionImpl session, User user, Attribute attribute) {
    try {
        String userNamespace = attribute.getFriendlyNameParameter();
        if (userNamespace.equals(FRIENDLY_NAME_PARAMETER) && attribute.getValue() != null && !attribute.valueAsString().isEmpty()) {
            ExtSource extSource = session.getPerunBl().getExtSourcesManagerBl().getExtSourceByName(session, getExtSourceName());
            UserExtSource userExtSource = new UserExtSource(extSource, 0, attribute.getValue().toString());
            session.getPerunBl().getUsersManagerBl().addUserExtSource(session, user, userExtSource);
        }
    } catch (UserExtSourceExistsException ex) {
        log.warn("Attribute: {}, External source already exists for the user.", FRIENDLY_NAME_PARAMETER, ex);
    } catch (ExtSourceNotExistsException ex) {
        throw new InternalErrorException("Attribute: " + FRIENDLY_NAME_PARAMETER + ", IdP external source doesn't exist.", ex);
    }
}
Also used : UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)

Example 17 with UserExtSourceExistsException

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

the class urn_perun_user_attribute_def_def_login_namespace_vsup method changedAttributeHook.

/**
 * When login changes: first set / changed always change eduroam-vsup login too !!
 * When login is set add UserExtSource, since logins are generated in Perun.
 * When login is set, set also school mail u:d:vsupMail
 *
 * @param session
 * @param user
 * @param attribute
 * @throws InternalErrorException
 * @throws WrongReferenceAttributeValueException
 */
@Override
public void changedAttributeHook(PerunSessionImpl session, User user, Attribute attribute) throws WrongReferenceAttributeValueException {
    if (attribute.getValue() != null) {
        // add UES
        ExtSource es;
        try {
            es = session.getPerunBl().getExtSourcesManagerBl().getExtSourceByName(session, "AD");
        } catch (ExtSourceNotExistsException ex) {
            throw new InternalErrorException("AD ext source on VŠUP doesn't exists.", ex);
        }
        try {
            session.getPerunBl().getUsersManagerBl().getUserExtSourceByExtLogin(session, es, (String) attribute.getValue());
        } catch (UserExtSourceNotExistsException ex) {
            // add UES
            UserExtSource ues = new UserExtSource(es, 2, (String) attribute.getValue());
            try {
                session.getPerunBl().getUsersManagerBl().addUserExtSource(session, user, ues);
            } catch (UserExtSourceExistsException ex2) {
                throw new ConsistencyErrorException(ex2);
            }
        }
        // set eduroam-login
        Attribute eduroamLogin = null;
        try {
            eduroamLogin = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, EDUROAM_VSUP_NAMESPACE);
            if (!Objects.equals(attribute.getValue(), eduroamLogin.getValue())) {
                eduroamLogin.setValue(attribute.getValue());
                session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, eduroamLogin);
            }
        } catch (WrongAttributeAssignmentException ex) {
            throw new InternalErrorException(ex);
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException(ex);
        } catch (WrongAttributeValueException ex) {
            throw new WrongReferenceAttributeValueException(attribute, eduroamLogin, "Mismatch in checking of users VŠUP login and eduroam login.", ex);
        }
        // set všup school mail
        Attribute schoolMail = null;
        try {
            schoolMail = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, VSUP_MAIL_NAMESPACE);
            if (!Objects.equals(attribute.getValue(), schoolMail.getValue())) {
                schoolMail.setValue(attribute.getValue() + "@vsup.cz");
                session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, schoolMail);
            }
        } catch (WrongAttributeAssignmentException ex) {
            throw new InternalErrorException(ex);
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException(ex);
        } catch (WrongAttributeValueException ex) {
            throw new WrongReferenceAttributeValueException(attribute, schoolMail, "Mismatch in checking of users VŠUP login and schoolMail.", ex);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 18 with UserExtSourceExistsException

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

the class urn_perun_user_attribute_def_def_login_namespace_umbrellaid_persistent_shadow method changedAttributeHook.

/**
 * ChangedAttributeHook() sets UserExtSource with following properties:
 *  - extSourceType is IdP
 *  - extSourceName is {getExtSourceName()}
 *  - user's extSource login is the same as his persistent attribute
 */
@Override
public void changedAttributeHook(PerunSessionImpl session, User user, Attribute attribute) {
    try {
        String userNamespace = attribute.getFriendlyNameParameter();
        if (userNamespace.equals(FRIENDLY_NAME_PARAMETER) && attribute.getValue() != null && !attribute.valueAsString().isEmpty()) {
            ExtSource extSource = session.getPerunBl().getExtSourcesManagerBl().getExtSourceByName(session, getExtSourceName());
            UserExtSource userExtSource = new UserExtSource(extSource, 0, attribute.getValue().toString());
            session.getPerunBl().getUsersManagerBl().addUserExtSource(session, user, userExtSource);
        }
    } catch (UserExtSourceExistsException ex) {
        log.warn("Attribute: {}, External source already exists for the user.", FRIENDLY_NAME_PARAMETER, ex);
    } catch (ExtSourceNotExistsException ex) {
        throw new InternalErrorException("Attribute: " + FRIENDLY_NAME_PARAMETER + ", IdP external source doesn't exist.", ex);
    }
}
Also used : UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)

Example 19 with UserExtSourceExistsException

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

the class urn_perun_user_attribute_def_virt_studentIdentifiers method processAddUserExtSource.

/**
 * Set userExtSource with attributes for member's user if not exists.
 *
 * @param sess Perun session
 * @param group from which appropriate attributes will be obtained
 * @param member for which the xtSource with attributes will be processed
 */
private void processAddUserExtSource(PerunSessionImpl sess, Group group, Member member) {
    User user = sess.getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
    Attribute organizationScope = tryGetAttribute(sess, group, A_G_D_organizationScopeFriendlyName);
    if (organizationScope == null || organizationScope.getValue() == null) {
        return;
    }
    Attribute organizationNamespace = this.tryGetAttribute(sess, group, A_G_D_organizationNamespaceFriendlyName);
    if (organizationNamespace == null || organizationNamespace.getValue() == null) {
        return;
    }
    Attribute userLoginID = tryGetAttribute(sess, user, A_U_D_loginNamespaceFriendlyNamePrefix + organizationNamespace.valueAsString());
    if (userLoginID == null || userLoginID.getValue() == null) {
        return;
    }
    ExtSource extSource = tryGetExtSource(sess, organizationScope.valueAsString());
    // Create and set userExtSource if not exists
    try {
        sess.getPerunBl().getUsersManagerBl().getUserExtSourceByExtLogin(sess, extSource, userLoginID.valueAsString());
    } catch (UserExtSourceNotExistsException e) {
        UserExtSource ues = new UserExtSource(extSource, userLoginID.valueAsString());
        try {
            ues = sess.getPerunBl().getUsersManagerBl().addUserExtSource(sess, user, ues);
        } catch (UserExtSourceExistsException userExtSourceExistsException) {
            // Should not happened
            throw new InternalErrorException(e);
        }
        Attribute schacHomeOrganization = tryGetAttribute(sess, ues, A_UES_D_schacHomeOrganizationFriendlyName);
        Attribute eduPersonScopedAffiliation = tryGetAttribute(sess, ues, A_UES_D_eduPersonScopedAffiliationFriendlyName);
        Attribute schacPersonalUniqueCode = tryGetAttribute(sess, ues, A_UES_D_schacPersonalUniqueCodeFriendlyName);
        schacHomeOrganization.setValue(organizationScope.valueAsString());
        eduPersonScopedAffiliation.setValue(affiliationPrefix + organizationScope.valueAsString());
        List<String> spucValue = new ArrayList<>();
        spucValue.add(studentIdentifiersValuePrefix + organizationScope.valueAsString() + ":" + userLoginID.valueAsString());
        schacPersonalUniqueCode.setValue(spucValue);
        try {
            sess.getPerunBl().getAttributesManagerBl().setAttributes(sess, ues, Arrays.asList(schacHomeOrganization, eduPersonScopedAffiliation, schacPersonalUniqueCode));
        } catch (WrongAttributeValueException | WrongAttributeAssignmentException | WrongReferenceAttributeValueException ex) {
            // Should not happened
            throw new InternalErrorException(ex);
        }
    }
}
Also used : UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) ArrayList(java.util.ArrayList) List(java.util.List) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 20 with UserExtSourceExistsException

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

the class EgiuiPasswordManagerModule method validatePassword.

@Override
public void validatePassword(PerunSession sess, String userLogin, User user) throws InvalidLoginException {
    if (user == null) {
        user = ((PerunBl) sess.getPerun()).getModulesUtilsBl().getUserByLoginInNamespace(sess, userLogin, actualLoginNamespace);
    }
    if (user == null) {
        log.warn("No user was found by login '{}' in {} namespace.", userLogin, actualLoginNamespace);
    } else {
        // set extSources and extSource related attributes
        try {
            List<String> kerberosLogins = new ArrayList<>();
            ExtSource extSource = ((PerunBl) sess.getPerun()).getExtSourcesManagerBl().getExtSourceByName(sess, "EGI");
            UserExtSource ues = new UserExtSource(extSource, userLogin + "@EGI");
            ues.setLoa(0);
            try {
                ((PerunBl) sess.getPerun()).getUsersManagerBl().addUserExtSource(sess, user, ues);
            } catch (UserExtSourceExistsException ex) {
            // this is OK
            }
            // Store also Kerberos logins
            Attribute kerberosLoginsAttr = ((PerunBl) sess.getPerun()).getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":" + "kerberosLogins");
            if (kerberosLoginsAttr != null && kerberosLoginsAttr.getValue() != null) {
                kerberosLogins.addAll((List<String>) kerberosLoginsAttr.getValue());
            }
            if (!kerberosLogins.contains(userLogin + "@EGI") && kerberosLoginsAttr != null) {
                kerberosLogins.add(userLogin + "@EGI");
                kerberosLoginsAttr.setValue(kerberosLogins);
                ((PerunBl) sess.getPerun()).getAttributesManagerBl().setAttribute(sess, user, kerberosLoginsAttr);
            }
        } catch (WrongAttributeAssignmentException | AttributeNotExistsException | ExtSourceNotExistsException | WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
            throw new InternalErrorException(ex);
        }
    }
    // validate password
    super.validatePassword(sess, userLogin, user);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

UserExtSourceExistsException (cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException)30 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)28 ExtSource (cz.metacentrum.perun.core.api.ExtSource)27 ExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)22 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)21 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)16 Attribute (cz.metacentrum.perun.core.api.Attribute)15 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)11 User (cz.metacentrum.perun.core.api.User)10 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)10 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)10 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)10 ArrayList (java.util.ArrayList)10 UserExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException)9 Member (cz.metacentrum.perun.core.api.Member)6 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)5 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)5 Vo (cz.metacentrum.perun.core.api.Vo)4 RichUser (cz.metacentrum.perun.core.api.RichUser)3 RichUserExtSource (cz.metacentrum.perun.core.api.RichUserExtSource)3