Search in sources :

Example 6 with PasswordDeletionFailedRuntimeException

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

the class UsersManagerBlImpl method deleteAlternativePassword.

@Override
public void deleteAlternativePassword(PerunSession sess, User user, String loginNamespace, String passwordId) throws PasswordDeletionFailedException, LoginNotExistsException {
    log.info("Deleting alternative password for {} in login-namespace {} with passwordId {}.", user, loginNamespace, passwordId);
    try {
        Attribute userAlternativePassword = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, A_USER_DEF_ALT_PASSWORD_NAMESPACE + loginNamespace);
        Map<String, String> altPassValue = new LinkedHashMap<>();
        // Set not null value from altPassword attribute of this user
        if (userAlternativePassword.getValue() != null)
            altPassValue = userAlternativePassword.valueAsMap();
        // If password already exists, throw an exception
        if (!altPassValue.containsValue(passwordId))
            throw new PasswordDeletionFailedException("Password not found by ID.");
        // remove key with this value from map
        Set<String> keys = altPassValue.keySet();
        String description = null;
        for (String key : keys) {
            String valueOfKey = altPassValue.get(key);
            if (valueOfKey.equals(passwordId)) {
                if (description != null)
                    throw new ConsistencyErrorException("There is more than 1 password with same ID in value for user " + user);
                description = key;
            }
        }
        if (description == null)
            throw new InternalErrorException("Password not found by ID.");
        altPassValue.remove(description);
        // set new value for altPassword attribute for this user
        userAlternativePassword.setValue(altPassValue);
        getPerunBl().getAttributesManagerBl().setAttribute(sess, user, userAlternativePassword);
    } catch (WrongAttributeAssignmentException | WrongReferenceAttributeValueException | WrongAttributeValueException ex) {
        throw new InternalErrorException(ex);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    }
    // actually delete password in the backend
    PasswordManagerModule module = getPasswordManagerModule(sess, loginNamespace);
    try {
        module.deleteAlternativePassword(sess, user, passwordId);
    } catch (PasswordDeletionFailedRuntimeException ex) {
        throw new PasswordDeletionFailedException(ex);
    } catch (LoginNotExistsRuntimeException ex) {
        throw new LoginNotExistsException(ex);
    } catch (Exception ex) {
        // fallback for exception compatibility
        throw new PasswordDeletionFailedException("Alternative password deletion failed for " + loginNamespace + ":" + passwordId + " of " + user + ".", 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) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) LoginNotExistsRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.LoginNotExistsRuntimeException) 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) LinkedHashMap(java.util.LinkedHashMap) PasswordDeletionFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordDeletionFailedRuntimeException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) PasswordDeletionFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordDeletionFailedException) PasswordManagerModule(cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule) GenericPasswordManagerModule(cz.metacentrum.perun.core.impl.modules.pwdmgr.GenericPasswordManagerModule) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

PasswordDeletionFailedRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.PasswordDeletionFailedRuntimeException)6 LoginNotExistsRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.LoginNotExistsRuntimeException)5 PasswordCreationFailedRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException)5 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)4 PasswordChangeFailedRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.PasswordChangeFailedRuntimeException)4 PasswordDoesntMatchRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.PasswordDoesntMatchRuntimeException)4 AlreadyAdminException (cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)3 AlreadyReservedLoginException (cz.metacentrum.perun.core.api.exceptions.AlreadyReservedLoginException)3 AnonymizationNotSupportedException (cz.metacentrum.perun.core.api.exceptions.AnonymizationNotSupportedException)3 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)3 BanNotExistsException (cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)3 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)3 ExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)3 IllegalArgumentException (cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException)3 InvalidLoginException (cz.metacentrum.perun.core.api.exceptions.InvalidLoginException)3 LoginNotExistsException (cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException)3 MemberAlreadyRemovedException (cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException)3 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)3 PasswordChangeFailedException (cz.metacentrum.perun.core.api.exceptions.PasswordChangeFailedException)3 PasswordCreationFailedException (cz.metacentrum.perun.core.api.exceptions.PasswordCreationFailedException)3