use of cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException in project perun by CESNET.
the class UsersManagerBlImpl method createAlternativePassword.
@Override
public void createAlternativePassword(PerunSession sess, User user, String description, String loginNamespace, String password) throws PasswordCreationFailedException, LoginNotExistsException, PasswordStrengthException {
String passwordId = Long.toString(System.currentTimeMillis());
log.info("Creating alternative password for {} in login-namespace {} with description {} and passwordId {}.", user, loginNamespace, description, 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.containsKey(description))
throw new ConsistencyErrorException("Password with this description already exists. Description: " + description);
// set new value to attribute
altPassValue.put(description, passwordId);
userAlternativePassword.setValue(altPassValue);
// set new attribute with value to perun
getPerunBl().getAttributesManagerBl().setAttribute(sess, user, userAlternativePassword);
} catch (WrongAttributeAssignmentException | WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
// actually create password in the backend
PasswordManagerModule module = getPasswordManagerModule(sess, loginNamespace);
try {
module.createAlternativePassword(sess, user, passwordId, password);
} catch (PasswordCreationFailedRuntimeException ex) {
throw new PasswordCreationFailedException(ex);
} catch (LoginNotExistsRuntimeException ex) {
throw new LoginNotExistsException(ex);
} catch (PasswordStrengthException e) {
throw e;
} catch (Exception ex) {
// fallback for exception compatibility
throw new PasswordCreationFailedException("Alternative password creation failed for " + loginNamespace + ":" + passwordId + " of " + user + ".", ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException in project perun by CESNET.
the class UsersManagerBlImpl method validatePassword.
@Override
public void validatePassword(PerunSession sess, User user, String loginNamespace) throws PasswordCreationFailedException, LoginNotExistsException, InvalidLoginException {
log.info("Validating 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);
}
// Validate the password
PasswordManagerModule module = getPasswordManagerModule(sess, loginNamespace);
try {
module.validatePassword(sess, attr.valueAsString(), user);
} catch (PasswordCreationFailedRuntimeException e) {
throw new PasswordCreationFailedException(e);
}
} catch (AttributeNotExistsException e) {
throw new LoginNotExistsException(e);
} catch (WrongAttributeAssignmentException e) {
throw new InternalErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException in project perun by CESNET.
the class UsersManagerBlImpl method validatePassword.
@Override
public void validatePassword(PerunSession sess, String userLogin, String loginNamespace) throws PasswordCreationFailedException, InvalidLoginException {
log.info("Validating password for {} in login-namespace {}.", userLogin, loginNamespace);
// Validate the password
PasswordManagerModule module = getPasswordManagerModule(sess, loginNamespace);
try {
module.validatePassword(sess, userLogin, null);
} catch (PasswordCreationFailedRuntimeException e) {
throw new PasswordCreationFailedException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException 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);
}
}
Aggregations