use of cz.metacentrum.perun.core.api.exceptions.rt.PasswordOperationTimeoutRuntimeException in project perun by CESNET.
the class UsersManagerBlImpl method managePassword.
/**
* Calls external program which do the job with the password.
*
* Return codes of the external program
* If password check fails then return 1
* If there is no handler for loginNamespace return 2
* If setting of the new password failed return 3
*
* @param sess
* @param operation
* @param userLogin
* @param loginNamespace
* @param password
* @throws InternalErrorException
*/
protected void managePassword(PerunSession sess, String operation, String userLogin, String loginNamespace, String password) throws InternalErrorException {
// If new PWDMGR module exists, use-it
PasswordManagerModule module = null;
try {
module = getPasswordManagerModule(sess, loginNamespace);
} catch (Exception ex) {
// silently skip
}
if (module != null) {
if (operation.equals(PASSWORD_RESERVE)) {
try {
module.reservePassword(sess, userLogin, password);
return;
} catch (Exception ex) {
throw new PasswordCreationFailedRuntimeException("Password creation failed for " + loginNamespace + ":" + userLogin + ".");
}
}
if (operation.equals(PASSWORD_RESERVE_RANDOM)) {
try {
module.reserveRandomPassword(sess, userLogin);
return;
} catch (Exception ex) {
throw new PasswordCreationFailedRuntimeException("Password creation failed for " + loginNamespace + ":" + userLogin + ".");
}
}
if (operation.equals(PASSWORD_CHECK)) {
try {
module.checkPassword(sess, userLogin, password);
return;
} catch (Exception ex) {
throw new PasswordDoesntMatchRuntimeException("Old password doesn't match for " + loginNamespace + ":" + userLogin + ".");
}
}
if (operation.equals(PASSWORD_VALIDATE)) {
module.validatePassword(sess, userLogin);
return;
}
if (operation.equals(PASSWORD_CHANGE)) {
try {
module.changePassword(sess, userLogin, password);
return;
} catch (Exception ex) {
throw new PasswordChangeFailedRuntimeException("Password change failed for " + loginNamespace + ":" + userLogin + ".");
}
}
if (operation.equals(PASSWORD_DELETE)) {
try {
module.deletePassword(sess, userLogin);
return;
} catch (Exception ex) {
throw new PasswordDeletionFailedRuntimeException("Password deletion failed for " + loginNamespace + ":" + userLogin + ".");
}
}
}
// use good old way
// Check validity of original password
ProcessBuilder pb = new ProcessBuilder(BeansUtils.getCoreConfig().getPasswordManagerProgram(), operation, loginNamespace, userLogin);
Process process;
try {
process = pb.start();
} catch (IOException e) {
throw new InternalErrorException(e);
}
InputStream es = process.getErrorStream();
if (operation.equals(PASSWORD_CHANGE) || operation.equals(PASSWORD_CHECK) || operation.equals(PASSWORD_RESERVE)) {
OutputStream os = process.getOutputStream();
if (password == null || password.isEmpty()) {
throw new EmptyPasswordRuntimeException("Password for " + loginNamespace + ":" + userLogin + " cannot be empty.");
}
// Write password to the stdin of the program
PrintWriter pw = new PrintWriter(os, true);
pw.write(password);
pw.close();
}
// If non-zero exit code is returned, then try to read error output
try {
if (process.waitFor() != 0) {
if (process.exitValue() == 1) {
throw new PasswordDoesntMatchRuntimeException("Old password doesn't match for " + loginNamespace + ":" + userLogin + ".");
} else if (process.exitValue() == 3) {
throw new PasswordChangeFailedRuntimeException("Password change failed for " + loginNamespace + ":" + userLogin + ".");
} else if (process.exitValue() == 4) {
throw new PasswordCreationFailedRuntimeException("Password creation failed for " + loginNamespace + ":" + userLogin + ".");
} else if (process.exitValue() == 5) {
throw new PasswordDeletionFailedRuntimeException("Password deletion failed for " + loginNamespace + ":" + userLogin + ".");
} else if (process.exitValue() == 6) {
throw new LoginNotExistsRuntimeException("User login doesn't exists in underlying system for " + loginNamespace + ":" + userLogin + ".");
} else if (process.exitValue() == 11) {
throw new PasswordStrengthFailedRuntimeException("Password to set doesn't match expected restrictions for " + loginNamespace + ":" + userLogin + ".");
} else if (process.exitValue() == 12) {
throw new PasswordOperationTimeoutRuntimeException("Operation with password exceeded expected limit for " + loginNamespace + ":" + userLogin + ".");
} else {
// Some other error occured
BufferedReader inReader = new BufferedReader(new InputStreamReader(es));
StringBuffer errorMsg = new StringBuffer();
String line;
try {
while ((line = inReader.readLine()) != null) {
errorMsg.append(line);
}
} catch (IOException e) {
throw new InternalErrorException(e);
}
throw new InternalErrorException(errorMsg.toString());
}
}
} catch (InterruptedException e) {
throw new InternalErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.rt.PasswordOperationTimeoutRuntimeException 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.rt.PasswordOperationTimeoutRuntimeException 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.rt.PasswordOperationTimeoutRuntimeException in project perun by CESNET.
the class UsersManagerBlImpl method deletePassword.
@Override
public void deletePassword(PerunSession sess, String userLogin, String loginNamespace) throws LoginNotExistsException, PasswordDeletionFailedException, PasswordOperationTimeoutException, InvalidLoginException {
log.info("Deleting password for {} in login-namespace {}.", userLogin, loginNamespace);
// Delete the password
PasswordManagerModule module = getPasswordManagerModule(sess, loginNamespace);
try {
module.deletePassword(sess, userLogin);
} catch (PasswordDeletionFailedRuntimeException e) {
throw new PasswordDeletionFailedException(e);
} catch (LoginNotExistsRuntimeException e) {
throw new LoginNotExistsException(e);
} catch (PasswordOperationTimeoutRuntimeException e) {
throw new PasswordOperationTimeoutException(e);
} catch (InvalidLoginException e) {
throw e;
} catch (Exception ex) {
// fallback for exception compatibility
throw new PasswordDeletionFailedException("Password deletion failed for " + loginNamespace + ":" + userLogin + ".", ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.rt.PasswordOperationTimeoutRuntimeException in project perun by CESNET.
the class UsersManagerBlImpl method deletePassword.
@Override
public void deletePassword(PerunSession sess, User user, String loginNamespace) throws LoginNotExistsException, PasswordDeletionFailedException, PasswordOperationTimeoutException, InvalidLoginException {
log.info("Deleting password for {} in login-namespace {}.", user, loginNamespace);
// Delete the password
PasswordManagerModule module = getPasswordManagerModule(sess, loginNamespace);
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);
}
module.deletePassword(sess, attr.valueAsString());
} catch (PasswordDeletionFailedRuntimeException e) {
throw new PasswordDeletionFailedException(e);
} catch (LoginNotExistsRuntimeException e) {
throw new LoginNotExistsException(e);
} catch (PasswordOperationTimeoutRuntimeException e) {
throw new PasswordOperationTimeoutException(e);
} catch (Exception ex) {
// fallback for exception compatibility
throw new PasswordDeletionFailedException("Password deletion failed for " + loginNamespace + ": " + user + ".", ex);
}
}
Aggregations