use of cz.metacentrum.perun.core.api.exceptions.PasswordStrengthFailedException 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);
}
}
use of cz.metacentrum.perun.core.api.exceptions.PasswordStrengthFailedException 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);
}
}
use of cz.metacentrum.perun.core.api.exceptions.PasswordStrengthFailedException in project perun by CESNET.
the class UsersManagerBlImpl method changePasswordRandom.
@Override
public String changePasswordRandom(PerunSession session, User user, String namespace) throws PasswordOperationTimeoutException, LoginNotExistsException, PasswordChangeFailedException, InvalidLoginException, PasswordStrengthException {
// first check if user has login in specified namespace!
String userLogin;
try {
Attribute userLoginAttribute = getPerunBl().getAttributesManagerBl().getAttribute(session, user, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:" + namespace);
userLogin = (String) userLoginAttribute.getValue();
} catch (WrongAttributeAssignmentException | AttributeNotExistsException e) {
// should not happen since the changePassword method passed
log.error("Unexpected exception when re-seting password to randomly generated for user {} in {}", user, namespace, e);
throw new InternalErrorException(e);
}
if (userLogin == null) {
log.warn("User {} has no login in {} namespace.", user, namespace);
throw new LoginNotExistsException("User has no login in " + namespace + " namespace.");
}
// generate and change password
PasswordManagerModule module = getPasswordManagerModule(session, namespace);
String newRandomPassword = module.generateRandomPassword(session, userLogin);
try {
changePassword(session, user, namespace, null, newRandomPassword, false);
} catch (PasswordDoesntMatchException | PasswordStrengthFailedException e) {
// should not happen when we are not using the old password and have good password generated
log.error("Unexpected exception when re-seting password to randomly generated for login {} in {}", userLogin, namespace, e);
throw new InternalErrorException(e);
}
// create template to return
String template = getPasswordResetTemplate(session, namespace);
return template.replace("{password}", StringEscapeUtils.escapeHtml4(newRandomPassword)).replace("{login}", StringEscapeUtils.escapeHtml4(userLogin));
}
use of cz.metacentrum.perun.core.api.exceptions.PasswordStrengthFailedException in project perun by CESNET.
the class UsersManagerBlImpl method reservePassword.
@Override
public void reservePassword(PerunSession sess, String userLogin, String loginNamespace, String password) throws PasswordCreationFailedException, PasswordOperationTimeoutException, PasswordStrengthFailedException, InvalidLoginException, PasswordStrengthException {
log.info("Reserving password for {} in login-namespace {}.", userLogin, loginNamespace);
// Reserve the password
PasswordManagerModule module = getPasswordManagerModule(sess, loginNamespace);
try {
module.reservePassword(sess, userLogin, 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 + ":" + userLogin + ".", ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.PasswordStrengthFailedException in project perun by CESNET.
the class UsersManagerBlImpl method changePassword.
@Override
public void changePassword(PerunSession sess, User user, String loginNamespace, String oldPassword, String newPassword, boolean checkOldPassword) throws LoginNotExistsException, PasswordDoesntMatchException, PasswordChangeFailedException, PasswordOperationTimeoutException, PasswordStrengthFailedException, InvalidLoginException, PasswordStrengthException {
log.info("Changing password for {} in login-namespace {}.", user, loginNamespace);
// Get User login in loginNamespace
Attribute userLogin;
try {
userLogin = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:" + loginNamespace);
} catch (AttributeNotExistsException e) {
throw new LoginNotExistsException(e);
} catch (WrongAttributeAssignmentException e) {
throw new InternalErrorException(e);
}
PasswordManagerModule module = getPasswordManagerModule(sess, loginNamespace);
// Check password if it was requested
if (checkOldPassword) {
try {
module.checkPassword(sess, userLogin.valueAsString(), oldPassword);
} catch (PasswordDoesntMatchRuntimeException e) {
throw new PasswordDoesntMatchException(e);
} catch (PasswordOperationTimeoutRuntimeException e) {
throw new PasswordOperationTimeoutException(e);
} catch (Exception ex) {
// fallback for exception compatibility
throw new PasswordDoesntMatchException("Old password doesn't match for " + loginNamespace + ":" + userLogin + ".", ex);
}
}
// Change the password
try {
module.changePassword(sess, userLogin.valueAsString(), newPassword);
} catch (PasswordChangeFailedRuntimeException e) {
throw new PasswordChangeFailedException(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 PasswordChangeFailedException("Password change failed for " + loginNamespace + ":" + userLogin + ".", ex);
}
// validate and set user ext sources
try {
this.validatePassword(sess, user, loginNamespace);
} catch (PasswordCreationFailedException ex) {
throw new PasswordChangeFailedException(ex);
}
}
Aggregations