Search in sources :

Example 21 with ExtSourceNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException 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 22 with ExtSourceNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException 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 23 with ExtSourceNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException 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 24 with ExtSourceNotExistsException

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

Example 25 with ExtSourceNotExistsException

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

the class EinfraservicesPasswordManagerModule 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 {
            ExtSource extSource = ((PerunBl) sess.getPerun()).getExtSourcesManagerBl().getExtSourceByName(sess, "EINFRA-SERVICES");
            UserExtSource ues = new UserExtSource(extSource, userLogin + "@EINFRA-SERVICES");
            ues.setLoa(0);
            try {
                ((PerunBl) sess.getPerun()).getUsersManagerBl().addUserExtSource(sess, user, ues);
            } catch (UserExtSourceExistsException ex) {
            // this is OK
            }
            List<String> kerberosLogins = new ArrayList<>();
            // 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 + "@EINFRA-SERVICES") && kerberosLoginsAttr != null) {
                kerberosLogins.add(userLogin + "@EINFRA-SERVICES");
                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

ExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)30 ExtSource (cz.metacentrum.perun.core.api.ExtSource)27 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)24 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)23 UserExtSourceExistsException (cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException)21 ArrayList (java.util.ArrayList)12 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)11 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)10 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)10 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)10 Attribute (cz.metacentrum.perun.core.api.Attribute)9 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)9 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)9 UserExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException)8 Candidate (cz.metacentrum.perun.core.api.Candidate)5 CandidateNotExistsException (cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException)5 ExtSourceExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceExistsException)5 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)5 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)5 RichUserExtSource (cz.metacentrum.perun.core.api.RichUserExtSource)4