Search in sources :

Example 1 with InvalidLoginException

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

the class ModulesUtilsBlImpl method checkLoginNamespaceRegex.

@Override
public void checkLoginNamespaceRegex(String namespace, String login, Pattern defaultRegex) throws InvalidLoginException {
    Utils.notNull(namespace, "namespace to check login syntax");
    Utils.notNull(login, "login to check syntax for");
    checkPerunNamespacesMap();
    String regex = perunNamespaces.get("login-namespace:" + namespace + ":regex");
    if (regex != null) {
        // Check if regex is valid
        try {
            Pattern.compile(regex);
        } catch (PatternSyntaxException e) {
            log.error("Regex pattern \"{}\" from \"login-namespace:{}:regex\" property of perun-namespaces.properties file is invalid.", regex, namespace);
            throw new InternalErrorException("Regex pattern \"" + regex + "\" from \"login-namespace:" + namespace + ":regex\" property of perun-namespaces.properties file is invalid.");
        }
        // check syntax or if its between exceptions
        if (!login.matches(regex) && !isLoginExceptionallyAllowed(namespace, login)) {
            log.warn("Login '{}' in {} namespace doesn't match regex: {}", login, namespace, regex);
            throw new InvalidLoginException("Login doesn't matches expected regex: \"" + regex + "\"");
        }
    } else {
        // check syntax or if its between exceptions
        if (!defaultRegex.matcher(login).matches() && !isLoginExceptionallyAllowed(namespace, login)) {
            log.warn("Login '{}' in {} namespace doesn't match regex: {}", login, namespace, regex);
            throw new InvalidLoginException("Login doesn't matches expected regex: \"" + defaultRegex + "\"");
        }
    }
}
Also used : InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 2 with InvalidLoginException

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

the class EinfraPasswordManagerModule 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 {
        PerunBl perunBl = ((PerunBl) sess.getPerun());
        // FIXME - find out more convenient place and support other namespaces
        try {
            Attribute attribute = perunBl.getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":lastPwdChangeTimestamp:einfra");
            LocalDateTime now = LocalDateTime.now();
            String value = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            attribute.setValue(value);
            perunBl.getAttributesManagerBl().setAttribute(sess, user, attribute);
        } catch (AttributeNotExistsException ignore) {
        // not supported by namespace
        } catch (Exception ex) {
            log.warn("Unable to set last password change timestamp for {} in {}", userLogin, actualLoginNamespace, ex);
        }
        // set extSources and extSource related attributes
        try {
            List<String> kerberosLogins = new ArrayList<>();
            // Set META and EINFRA userExtSources
            ExtSource extSource = perunBl.getExtSourcesManagerBl().getExtSourceByName(sess, "META");
            UserExtSource ues = new UserExtSource(extSource, userLogin + "@META");
            ues.setLoa(0);
            try {
                perunBl.getUsersManagerBl().addUserExtSource(sess, user, ues);
            } catch (UserExtSourceExistsException ex) {
            // this is OK
            }
            extSource = perunBl.getExtSourcesManagerBl().getExtSourceByName(sess, "EINFRA");
            ues = new UserExtSource(extSource, userLogin + "@EINFRA");
            ues.setLoa(0);
            try {
                perunBl.getUsersManagerBl().addUserExtSource(sess, user, ues);
            } catch (UserExtSourceExistsException ex) {
            // this is OK
            }
            extSource = perunBl.getExtSourcesManagerBl().getExtSourceByName(sess, "https://login.ics.muni.cz/idp/shibboleth");
            ues = new UserExtSource(extSource, userLogin + "@meta.cesnet.cz");
            ues.setLoa(0);
            try {
                perunBl.getUsersManagerBl().addUserExtSource(sess, user, ues);
            } catch (UserExtSourceExistsException ex) {
            // this is OK
            }
            // Store E-INFRA IdP UES
            extSource = perunBl.getExtSourcesManagerBl().getExtSourceByName(sess, "https://idp.e-infra.cz/idp/");
            ues = new UserExtSource(extSource, userLogin + "@idp.e-infra.cz");
            ues.setLoa(0);
            try {
                perunBl.getUsersManagerBl().addUserExtSource(sess, user, ues);
            } catch (UserExtSourceExistsException ex) {
            // this is OK
            }
            // Store E-INFRA CERT IdP UES
            extSource = perunBl.getExtSourcesManagerBl().getExtSourceByName(sess, "https://idp-cert.e-infra.cz/idp/");
            ues = new UserExtSource(extSource, userLogin + "@idp-cert.e-infra.cz");
            ues.setLoa(0);
            try {
                perunBl.getUsersManagerBl().addUserExtSource(sess, user, ues);
            } catch (UserExtSourceExistsException ex) {
            // this is OK
            }
            // Store also Kerberos logins
            Attribute kerberosLoginsAttr = perunBl.getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":" + "kerberosLogins");
            if (kerberosLoginsAttr != null && kerberosLoginsAttr.getValue() != null) {
                kerberosLogins.addAll(kerberosLoginsAttr.valueAsList());
            }
            boolean someChange = false;
            if (!kerberosLogins.contains(userLogin + "@EINFRA")) {
                kerberosLogins.add(userLogin + "@EINFRA");
                someChange = true;
            }
            if (!kerberosLogins.contains(userLogin + "@META")) {
                kerberosLogins.add(userLogin + "@META");
                someChange = true;
            }
            if (someChange && kerberosLoginsAttr != null) {
                kerberosLoginsAttr.setValue(kerberosLogins);
                perunBl.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 : LocalDateTime(java.time.LocalDateTime) 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) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) PasswordCreationFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) PerunRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PerunRuntimeException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) IOException(java.io.IOException) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) PasswordDeletionFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordDeletionFailedRuntimeException) PasswordStrengthException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException) LoginNotExistsRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.LoginNotExistsRuntimeException) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 3 with InvalidLoginException

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

the class UsersManagerBlImpl method reserveRandomPassword.

@Override
public void reserveRandomPassword(PerunSession sess, User user, String loginNamespace) throws PasswordCreationFailedException, LoginNotExistsException, PasswordOperationTimeoutException, PasswordStrengthFailedException, InvalidLoginException {
    log.info("Reserving password for {} in login-namespace {}.", user, loginNamespace);
    // Get login.
    try {
        Attribute attr = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":" + AttributesManager.LOGIN_NAMESPACE + ":" + loginNamespace);
        if (attr.getValue() == null) {
            throw new LoginNotExistsException("Attribute containing login has empty value. Namespace: " + loginNamespace);
        }
        // Create the password
        PasswordManagerModule module = getPasswordManagerModule(sess, loginNamespace);
        try {
            module.reserveRandomPassword(sess, attr.valueAsString());
        } catch (PasswordCreationFailedRuntimeException e) {
            throw new PasswordCreationFailedException(e);
        } catch (PasswordOperationTimeoutRuntimeException e) {
            throw new PasswordOperationTimeoutException(e);
        } catch (PasswordStrengthFailedRuntimeException e) {
            throw new PasswordStrengthFailedException(e);
        } catch (InvalidLoginException e) {
            throw e;
        } catch (Exception ex) {
            // fallback for exception compatibility
            throw new PasswordCreationFailedException("Password creation failed for " + loginNamespace + ":" + attr.valueAsString() + ".", ex);
        }
    } catch (AttributeNotExistsException e) {
        throw new LoginNotExistsException(e);
    } catch (WrongAttributeAssignmentException e) {
        throw new InternalErrorException(e);
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) PasswordOperationTimeoutRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordOperationTimeoutRuntimeException) PasswordCreationFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordCreationFailedException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) PasswordOperationTimeoutRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordOperationTimeoutRuntimeException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) MemberAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException) PasswordCreationFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordCreationFailedException) UserExtSourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceAlreadyRemovedException) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) PasswordDoesntMatchRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordDoesntMatchRuntimeException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) LoginNotExistsRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.LoginNotExistsRuntimeException) PasswordStrengthFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthFailedException) PasswordCreationFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException) SpecificUserAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.SpecificUserAlreadyRemovedException) AlreadyReservedLoginException(cz.metacentrum.perun.core.api.exceptions.AlreadyReservedLoginException) SpecificUserOwnerAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.SpecificUserOwnerAlreadyRemovedException) IllegalArgumentException(cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException) PasswordChangeFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordChangeFailedException) PasswordResetLinkExpiredException(cz.metacentrum.perun.core.api.exceptions.PasswordResetLinkExpiredException) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) PasswordChangeFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordChangeFailedRuntimeException) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) PasswordStrengthFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordStrengthFailedRuntimeException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) PasswordStrengthException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException) PasswordDeletionFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordDeletionFailedException) UserAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.UserAlreadyRemovedException) PasswordOperationTimeoutException(cz.metacentrum.perun.core.api.exceptions.PasswordOperationTimeoutException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) RelationNotExistsException(cz.metacentrum.perun.core.api.exceptions.RelationNotExistsException) PasswordDoesntMatchException(cz.metacentrum.perun.core.api.exceptions.PasswordDoesntMatchException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException) PasswordResetLinkNotValidException(cz.metacentrum.perun.core.api.exceptions.PasswordResetLinkNotValidException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) PasswordDeletionFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordDeletionFailedRuntimeException) AnonymizationNotSupportedException(cz.metacentrum.perun.core.api.exceptions.AnonymizationNotSupportedException) PasswordOperationTimeoutException(cz.metacentrum.perun.core.api.exceptions.PasswordOperationTimeoutException) PasswordStrengthFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordStrengthFailedRuntimeException) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) PasswordManagerModule(cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule) GenericPasswordManagerModule(cz.metacentrum.perun.core.impl.modules.pwdmgr.GenericPasswordManagerModule) PasswordCreationFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException) PasswordStrengthFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthFailedException)

Example 4 with InvalidLoginException

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

the class UsersManagerBlImpl method reservePassword.

@Override
public void reservePassword(PerunSession sess, User user, String loginNamespace, String password) throws PasswordCreationFailedException, LoginNotExistsException, PasswordOperationTimeoutException, PasswordStrengthFailedException, InvalidLoginException, PasswordStrengthException {
    log.info("Reserving password for {} in login-namespace {}.", user, loginNamespace);
    // Get login.
    try {
        Attribute attr = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":" + AttributesManager.LOGIN_NAMESPACE + ":" + loginNamespace);
        if (attr.getValue() == null) {
            throw new LoginNotExistsException("Attribute containing login has empty value. Namespace: " + loginNamespace);
        }
        // Create the password
        PasswordManagerModule module = getPasswordManagerModule(sess, loginNamespace);
        try {
            module.reservePassword(sess, attr.valueAsString(), password);
        } catch (PasswordCreationFailedRuntimeException e) {
            throw new PasswordCreationFailedException(e);
        } catch (PasswordOperationTimeoutRuntimeException e) {
            throw new PasswordOperationTimeoutException(e);
        } catch (PasswordStrengthFailedRuntimeException e) {
            throw new PasswordStrengthFailedException(e);
        } catch (InvalidLoginException | PasswordStrengthException e) {
            throw e;
        } catch (Exception ex) {
            // fallback for exception compatibility
            throw new PasswordCreationFailedException("Password creation failed for " + loginNamespace + ":" + attr.valueAsString() + ".", ex);
        }
    } catch (AttributeNotExistsException e) {
        throw new LoginNotExistsException(e);
    } catch (WrongAttributeAssignmentException e) {
        throw new InternalErrorException(e);
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) PasswordOperationTimeoutRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordOperationTimeoutRuntimeException) PasswordCreationFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordCreationFailedException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) PasswordOperationTimeoutRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordOperationTimeoutRuntimeException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) MemberAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException) PasswordCreationFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordCreationFailedException) UserExtSourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceAlreadyRemovedException) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) PasswordDoesntMatchRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordDoesntMatchRuntimeException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) LoginNotExistsRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.LoginNotExistsRuntimeException) PasswordStrengthFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthFailedException) PasswordCreationFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException) SpecificUserAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.SpecificUserAlreadyRemovedException) AlreadyReservedLoginException(cz.metacentrum.perun.core.api.exceptions.AlreadyReservedLoginException) SpecificUserOwnerAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.SpecificUserOwnerAlreadyRemovedException) IllegalArgumentException(cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException) PasswordChangeFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordChangeFailedException) PasswordResetLinkExpiredException(cz.metacentrum.perun.core.api.exceptions.PasswordResetLinkExpiredException) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) PasswordChangeFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordChangeFailedRuntimeException) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) PasswordStrengthFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordStrengthFailedRuntimeException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) PasswordStrengthException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException) PasswordDeletionFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordDeletionFailedException) UserAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.UserAlreadyRemovedException) PasswordOperationTimeoutException(cz.metacentrum.perun.core.api.exceptions.PasswordOperationTimeoutException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) RelationNotExistsException(cz.metacentrum.perun.core.api.exceptions.RelationNotExistsException) PasswordDoesntMatchException(cz.metacentrum.perun.core.api.exceptions.PasswordDoesntMatchException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException) PasswordResetLinkNotValidException(cz.metacentrum.perun.core.api.exceptions.PasswordResetLinkNotValidException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) PasswordDeletionFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordDeletionFailedRuntimeException) AnonymizationNotSupportedException(cz.metacentrum.perun.core.api.exceptions.AnonymizationNotSupportedException) PasswordOperationTimeoutException(cz.metacentrum.perun.core.api.exceptions.PasswordOperationTimeoutException) PasswordStrengthFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordStrengthFailedRuntimeException) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) PasswordManagerModule(cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule) GenericPasswordManagerModule(cz.metacentrum.perun.core.impl.modules.pwdmgr.GenericPasswordManagerModule) PasswordCreationFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException) PasswordStrengthFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthFailedException) PasswordStrengthException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException)

Example 5 with InvalidLoginException

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

the class GroupsManagerBlImpl method deleteAnyGroup.

/**
 * If forceDelete is false, delete only group which has no subgroup and no member.
 * If forceDelete is true, delete group with all subgroups and members.
 *
 * @param sess
 * @param group
 * @param forceDelete if false, delete only empty group without subgroups. If true, delete group including subgroups and members.
 * @throws InternalErrorException
 * @throws RelationExistsException Raise only if forceDelete is false and the group has any subgroup or member.
 * @throws GroupAlreadyRemovedException if there are 0 rows affected by deleting from DB
 */
private void deleteAnyGroup(PerunSession sess, Group group, boolean forceDelete) throws RelationExistsException, GroupAlreadyRemovedException, GroupAlreadyRemovedFromResourceException, GroupNotExistsException, GroupRelationDoesNotExist, GroupRelationCannotBeRemoved {
    Vo vo = this.getVo(sess, group);
    if (getGroupsManagerImpl().getSubGroupsCount(sess, group) > 0) {
        if (!forceDelete)
            throw new RelationExistsException("Group group=" + group + " contains subgroups");
        // get subgroups of this group
        List<Group> subGroups = getSubGroups(sess, group);
        for (Group subGroup : subGroups) {
            deleteAnyGroup(sess, subGroup, true);
        }
    }
    if ((this.getGroupMembersCount(sess, group) > 0) && !forceDelete) {
        throw new RelationExistsException("Group group=" + group + " contains members");
    }
    List<AssignedResource> assignedResources = getPerunBl().getResourcesManagerBl().getResourceAssignments(sess, group, List.of());
    try {
        for (AssignedResource assignedResource : assignedResources) {
            if (assignedResource.getSourceGroupId() == null) {
                getPerunBl().getResourcesManagerBl().removeGroupFromResource(sess, group, assignedResource.getEnrichedResource().getResource());
            } else {
                getPerunBl().getResourcesManagerBl().removeAutomaticGroupFromResource(sess, group, assignedResource.getEnrichedResource().getResource(), assignedResource.getSourceGroupId());
            }
        }
        // remove group's attributes
        getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, group);
    } catch (GroupNotDefinedOnResourceException ex) {
        throw new ConsistencyErrorException(ex);
    } catch (AttributeValueException ex) {
        throw new ConsistencyErrorException("All resources was removed from this group, so no attributes should remain assigned.", ex);
    }
    // delete all Groups reserved logins from KDC
    List<Integer> list = getGroupsManagerImpl().getGroupApplicationIds(sess, group);
    for (Integer appId : list) {
        // for each application
        for (Pair<String, String> login : getGroupsManagerImpl().getApplicationReservedLogins(appId)) {
            // for all reserved logins - delete them in ext. system (e.g. KDC)
            try {
                // left = namespace / right = login
                getPerunBl().getUsersManagerBl().deletePassword(sess, login.getRight(), login.getLeft());
            } catch (LoginNotExistsException ex) {
                log.error("Login: {} not exists in namespace: {} while deleting passwords.", login.getRight(), login.getLeft());
            } catch (InvalidLoginException e) {
                throw new InternalErrorException("We are deleting reserved login from group applications, but its syntax is not allowed by namespace configuration.", e);
            } catch (PasswordDeletionFailedException | PasswordOperationTimeoutException ex) {
                throw new InternalErrorException("Failed to delete reserved login " + login.getRight() + " from KDC.", ex);
            }
        }
    }
    // delete all Groups reserved logins from DB
    getGroupsManagerImpl().deleteGroupReservedLogins(sess, group);
    // remove all assigned ExtSources to this group
    List<ExtSource> assignedSources = getPerunBl().getExtSourcesManagerBl().getGroupExtSources(sess, group);
    for (ExtSource source : assignedSources) {
        try {
            getPerunBl().getExtSourcesManagerBl().removeExtSource(sess, group, source);
        } catch (ExtSourceNotAssignedException | ExtSourceAlreadyRemovedException ex) {
            // Just log this, because if method can't remove it, it is probably not assigned now
            log.warn("Try to remove not existing extSource {} from group {} when deleting group.", source, group);
        }
    }
    // 1. remove all relations with group g as an operand group.
    // this removes all relations that depend on this group
    List<Integer> relations = groupsManagerImpl.getResultGroupsIds(sess, group.getId());
    for (Integer groupId : relations) {
        removeGroupUnion(sess, groupsManagerImpl.getGroupById(sess, groupId), group, true);
    }
    // 2. remove all relations with group as a result group
    // We can remove relations without recalculation (@see removeRelationMembers)
    // because all dependencies of group were deleted in step 1.
    groupsManagerImpl.removeResultGroupRelations(sess, group);
    // Group applications, submitted data and app_form are deleted on cascade with "deleteGroup()"
    List<Member> membersFromDeletedGroup = getGroupMembers(sess, group);
    // delete all member-group attributes
    for (Member member : membersFromDeletedGroup) {
        try {
            perunBl.getAttributesManagerBl().removeAllAttributes(sess, member, group);
        } catch (AttributeValueException ex) {
            throw new ConsistencyErrorException("All members were removed from this group. So all member-group attribute values can be removed.", ex);
        } catch (MemberGroupMismatchException e) {
            throw new InternalErrorException("Member we tried to remove all member-group attributes doesn't come from the same VO as group", e);
        }
    }
    // remove admin roles of group
    List<Facility> facilitiesWhereGroupIsAdmin = getGroupsManagerImpl().getFacilitiesWhereGroupIsAdmin(sess, group);
    for (Facility facility : facilitiesWhereGroupIsAdmin) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, group, facility, Role.FACILITYADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("Can't unset group {} as admin of facility {} due to group not admin exception {}.", group, facility, e);
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    List<Group> groupsWhereGroupIsAdmin = getGroupsManagerImpl().getGroupsWhereGroupIsAdmin(sess, group);
    for (Group group1 : groupsWhereGroupIsAdmin) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, group, group1, Role.GROUPADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("Can't unset group {} as admin of group {} due to group not admin exception {}.", group, group1, e);
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    List<Resource> resourcesWhereGroupIsAdmin = getGroupsManagerImpl().getResourcesWhereGroupIsAdmin(sess, group);
    for (Resource resource : resourcesWhereGroupIsAdmin) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, group, resource, Role.RESOURCEADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("Can't unset group {} as admin of resource {} due to group not admin exception {}.", group, resource, e);
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    List<Resource> resourcesWhereGroupIsResourceSelfService = getGroupsManagerImpl().getResourcesWhereGroupIsResourceSelfService(sess, group);
    for (Resource resource : resourcesWhereGroupIsResourceSelfService) {
        try {
            perunBl.getResourcesManagerBl().removeResourceSelfServiceGroup(sess, resource, group);
        } catch (GroupNotAdminException e) {
            log.warn("Can't unset group {} as admin of resource {} due to group not admin exception {}.", group, resource, e);
        }
    }
    List<SecurityTeam> securityTeamsWhereGroupIsAdmin = getGroupsManagerImpl().getSecurityTeamsWhereGroupIsAdmin(sess, group);
    for (SecurityTeam securityTeam : securityTeamsWhereGroupIsAdmin) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, group, securityTeam, Role.SECURITYADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("Can't unset group {} as admin of security team {} due to group not admin exception {}.", group, securityTeam, e);
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    List<Vo> vosWhereGroupIsAdmin = getGroupsManagerImpl().getVosWhereGroupIsAdmin(sess, group);
    for (Vo vo1 : vosWhereGroupIsAdmin) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, group, vo1, Role.VOADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("Can't unset group {} as admin of facility {} due to group not admin exception {}.", group, vo1, e);
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    // remove admins of this group
    List<Group> adminGroups = getGroupsManagerImpl().getGroupAdmins(sess, group);
    for (Group adminGroup : adminGroups) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, adminGroup, group, Role.GROUPADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("When trying to unsetRole GroupAdmin for group {} in the group {} the exception was thrown {}", adminGroup, group, e);
        // skip and log as warning
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    List<User> adminUsers = getGroupsManagerImpl().getAdmins(sess, group);
    for (User adminUser : adminUsers) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, adminUser, group, Role.GROUPADMIN);
        } catch (UserNotAdminException e) {
            log.warn("When trying to unsetRole GroupAdmin for user {} in the group {} the exception was thrown {}", adminUser, group, e);
        // skip and log as warning
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    // Deletes also all direct and indirect members of the group
    getGroupsManagerImpl().deleteGroup(sess, vo, group);
    logTotallyRemovedMembers(sess, group.getParentGroupId(), membersFromDeletedGroup);
    getPerunBl().getAuditer().log(sess, new GroupDeleted(group));
}
Also used : ExtSourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.ExtSourceAlreadyRemovedException) EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) RichGroup(cz.metacentrum.perun.core.api.RichGroup) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) Group(cz.metacentrum.perun.core.api.Group) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) MemberGroupMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) AttributeValueException(cz.metacentrum.perun.core.api.exceptions.AttributeValueException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) Vo(cz.metacentrum.perun.core.api.Vo) GroupCreatedInVo(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupCreatedInVo) GroupDeleted(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupDeleted) ExtSourceNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotAssignedException) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) Resource(cz.metacentrum.perun.core.api.Resource) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) SecurityTeam(cz.metacentrum.perun.core.api.SecurityTeam) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) PasswordOperationTimeoutException(cz.metacentrum.perun.core.api.exceptions.PasswordOperationTimeoutException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) PasswordDeletionFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordDeletionFailedException) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Facility(cz.metacentrum.perun.core.api.Facility) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException)

Aggregations

InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)11 InvalidLoginException (cz.metacentrum.perun.core.api.exceptions.InvalidLoginException)11 LoginNotExistsException (cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException)9 PasswordDeletionFailedException (cz.metacentrum.perun.core.api.exceptions.PasswordDeletionFailedException)9 PasswordOperationTimeoutException (cz.metacentrum.perun.core.api.exceptions.PasswordOperationTimeoutException)9 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)9 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)9 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)8 RelationExistsException (cz.metacentrum.perun.core.api.exceptions.RelationExistsException)8 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)8 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)7 BanNotExistsException (cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)7 ExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)7 PasswordStrengthException (cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException)7 UserExtSourceExistsException (cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException)7 UserNotAdminException (cz.metacentrum.perun.core.api.exceptions.UserNotAdminException)7 LoginNotExistsRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.LoginNotExistsRuntimeException)7 PasswordCreationFailedRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException)7 PasswordDeletionFailedRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.PasswordDeletionFailedRuntimeException)7 AlreadyAdminException (cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)6