use of cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule in project perun by CESNET.
the class urn_perun_user_attribute_def_def_login_namespace_eduroam_vsupTest method setUp.
@Before
public void setUp() throws Exception {
classInstance = new urn_perun_user_attribute_def_def_login_namespace_eduroam_vsup();
session = mock(PerunSessionImpl.class);
user = new User();
attributeToCheck = new Attribute();
attributeToCheck.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
attributeToCheck.setFriendlyName("login-namespace:eduroam-vsup");
attribute = new Attribute();
attribute.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
attribute.setFriendlyName("login-namespace:eduroam-vsup");
attribute.setValue("same_value");
PerunBl perunBl = mock(PerunBl.class);
when(session.getPerunBl()).thenReturn(perunBl);
ModulesUtilsBl modulesUtilsBl = mock(ModulesUtilsBl.class);
when(perunBl.getModulesUtilsBl()).thenReturn(modulesUtilsBl);
UsersManagerBl usersManagerBl = mock(UsersManagerBl.class);
when(perunBl.getUsersManagerBl()).thenReturn(usersManagerBl);
PasswordManagerModule module = mock(GenericPasswordManagerModule.class);
when(session.getPerunBl().getUsersManagerBl().getPasswordManagerModule(session, "eduroam-vsup")).thenReturn(module);
AttributesManagerBl attributesManagerBl = mock(AttributesManagerBl.class);
when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
when(attributesManagerBl.getAttribute(session, user, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:vsup")).thenReturn(attribute);
}
use of cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule in project perun by CESNET.
the class UsersManagerImpl method getPasswordManagerModule.
@Override
public PasswordManagerModule getPasswordManagerModule(PerunSession session, String namespace) {
if (namespace == null || namespace.isEmpty())
throw new InternalErrorException("Login-namespace to get password manager module must be specified.");
namespace = namespace.replaceAll("[^A-Za-z0-9]", "");
namespace = Character.toUpperCase(namespace.charAt(0)) + namespace.substring(1);
try {
return (PasswordManagerModule) Class.forName("cz.metacentrum.perun.core.impl.modules.pwdmgr." + namespace + "PasswordManagerModule").newInstance();
} catch (ClassNotFoundException ex) {
return null;
} catch (InstantiationException | IllegalAccessException ex) {
throw new InternalErrorException("Unable to instantiate password manager module.", ex);
}
}
use of cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule 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.implApi.modules.pwdmgr.PasswordManagerModule 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);
}
}
use of cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule 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);
}
}
Aggregations