Search in sources :

Example 26 with UserExtSourceExistsException

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

the class UsersManagerBlImpl method checkThatCandidateUesesDontExist.

/**
 * Check that none of the given userExtSources exist. If so, the UserExtSourceExistsException
 * is thrown.
 *
 * @param sess session
 * @param candidate candidate
 * @throws UserExtSourceExistsException if some of the given userExtSources already exist.
 */
private void checkThatCandidateUesesDontExist(PerunSession sess, Candidate candidate) throws UserExtSourceExistsException {
    if (candidate.getUserExtSources() != null) {
        for (UserExtSource ues : candidate.getUserExtSources()) {
            // Check if the extSource exists
            ExtSource tmpExtSource = getPerunBl().getExtSourcesManagerBl().checkOrCreateExtSource(sess, ues.getExtSource().getName(), ues.getExtSource().getType());
            // Set the extSource ID
            ues.getExtSource().setId(tmpExtSource.getId());
            try {
                // Try to find the user by userExtSource
                User user = getPerunBl().getUsersManagerBl().getUserByExtSourceNameAndExtLogin(sess, ues.getExtSource().getName(), ues.getLogin());
                if (user != null) {
                    throw new UserExtSourceExistsException(ues);
                }
            } catch (UserExtSourceNotExistsException | UserNotExistsException | ExtSourceNotExistsException e) {
            // This is OK, we don't want it to exist
            }
        }
    }
}
Also used : UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) OwnershipRemovedForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipRemovedForSpecificUser) User(cz.metacentrum.perun.core.api.User) OwnershipEnabledForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipEnabledForSpecificUser) UserAddedToOwnersOfSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserAddedToOwnersOfSpecificUser) UserExtSourceRemovedFromUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceRemovedFromUser) RichUser(cz.metacentrum.perun.core.api.RichUser) OwnershipDisabledForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipDisabledForSpecificUser) UserExtSourceAddedToUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser) AllUserExtSourcesDeletedForUser(cz.metacentrum.perun.audit.events.UserManagerEvents.AllUserExtSourcesDeletedForUser) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException)

Example 27 with UserExtSourceExistsException

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

the class UsersManagerBlImpl method addMissingCandidatesUes.

/**
 * For given user, set user extsources from candiate, which have not been set before.
 *
 * @param sess session
 * @param user user
 * @param candidate candidate to take userExtSources
 */
private void addMissingCandidatesUes(PerunSession sess, User user, Candidate candidate) {
    if (candidate.getUserExtSources() != null) {
        for (UserExtSource userExtSource : candidate.getUserExtSources()) {
            try {
                UserExtSource currentUserExtSource = getPerunBl().getUsersManagerBl().getUserExtSourceByExtLogin(sess, userExtSource.getExtSource(), userExtSource.getLogin());
                // Update LoA
                currentUserExtSource.setLoa(userExtSource.getLoa());
                getPerunBl().getUsersManagerBl().updateUserExtSource(sess, currentUserExtSource);
            } catch (UserExtSourceNotExistsException e) {
                // Create userExtSource
                try {
                    getPerunBl().getUsersManagerBl().addUserExtSource(sess, user, userExtSource);
                } catch (UserExtSourceExistsException e1) {
                    throw new ConsistencyErrorException("Adding userExtSource which already exists: " + userExtSource, e1);
                }
            } catch (UserExtSourceExistsException e1) {
                throw new ConsistencyErrorException("Updating login of userExtSource to value which already" + " exists: " + userExtSource, e1);
            }
        }
    }
}
Also used : UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException)

Example 28 with UserExtSourceExistsException

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

the class ElixirPasswordManagerModule 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, "ELIXIR-EUROPE.ORG");
            UserExtSource ues = new UserExtSource(extSource, userLogin + "@ELIXIR-EUROPE.ORG");
            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 + "@ELIXIR-EUROPE.ORG") && kerberosLoginsAttr != null) {
                kerberosLogins.add(userLogin + "@ELIXIR-EUROPE.ORG");
                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 29 with UserExtSourceExistsException

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

the class MuPasswordManagerModule 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, "mu");
    }
    if (user == null) {
        log.warn("No user was found by login '{}' in {} namespace.", userLogin, "mu");
    } else {
        // set extSources and extSource related attributes
        try {
            ExtSource extSource = ((PerunBl) sess.getPerun()).getExtSourcesManagerBl().getExtSourceByName(sess, "https://idp2.ics.muni.cz/idp/shibboleth");
            UserExtSource ues = new UserExtSource(extSource, userLogin + "@muni.cz");
            ues.setLoa(2);
            try {
                ((PerunBl) sess.getPerun()).getUsersManagerBl().addUserExtSource(sess, user, ues);
            } catch (UserExtSourceExistsException ex) {
            // this is OK
            }
        } catch (ExtSourceNotExistsException ex) {
            throw new InternalErrorException(ex);
        }
    }
// MU doesn't validate password
}
Also used : UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)

Example 30 with UserExtSourceExistsException

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

the class UsersManagerBlImpl method createUser.

@Override
public User createUser(PerunSession sess, User user) {
    // trim input
    if (user.getFirstName() != null)
        user.setFirstName(user.getFirstName().trim());
    if (user.getLastName() != null)
        user.setLastName(user.getLastName().trim());
    if (user.getMiddleName() != null)
        user.setMiddleName(user.getMiddleName().trim());
    if (user.getTitleBefore() != null)
        user.setTitleBefore(user.getTitleBefore().trim());
    if (user.getTitleAfter() != null)
        user.setTitleAfter(user.getTitleAfter().trim());
    // Convert empty strings to null
    if (user.getFirstName() != null && user.getFirstName().isEmpty())
        user.setFirstName(null);
    if (user.getLastName() != null && user.getLastName().isEmpty())
        user.setLastName(null);
    if (user.getMiddleName() != null && user.getMiddleName().isEmpty())
        user.setMiddleName(null);
    if (user.getTitleBefore() != null && user.getTitleBefore().isEmpty())
        user.setTitleBefore(null);
    if (user.getTitleAfter() != null && user.getTitleAfter().isEmpty())
        user.setTitleAfter(null);
    user = getUsersManagerImpl().createUser(sess, user);
    getPerunBl().getAuditer().log(sess, new UserCreated(user));
    // Add default userExtSource
    ExtSource es;
    try {
        es = getPerunBl().getExtSourcesManagerBl().getExtSourceByName(sess, ExtSourcesManager.EXTSOURCE_NAME_PERUN);
    } catch (ExtSourceNotExistsException e1) {
        throw new ConsistencyErrorException("Default extSource PERUN must exists! It is created in ExtSourcesManagerImpl.init function.", e1);
    }
    UserExtSource ues = new UserExtSource(es, 0, String.valueOf(user.getId()));
    try {
        this.addUserExtSource(sess, user, ues);
    } catch (UserExtSourceExistsException e) {
        throw new ConsistencyErrorException(e);
    }
    return user;
}
Also used : UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) UserCreated(cz.metacentrum.perun.audit.events.UserManagerEvents.UserCreated) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException)

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