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_mu_admTest method setUp.
@Before
public void setUp() throws Exception {
// prepare core config for this test
CoreConfig cfNew = new CoreConfig();
cfNew.setInstanceId("test");
BeansUtils.setConfig(cfNew);
classInstance = new urn_perun_user_attribute_def_def_login_namespace_mu_adm();
session = mock(PerunSessionImpl.class);
user = new User();
attributeToCheck = new Attribute();
attributeToCheck.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
attributeToCheck.setFriendlyName("login-namespace:mu-adm");
PerunBl perunBl = mock(PerunBl.class);
when(session.getPerunBl()).thenReturn(perunBl);
UsersManagerBl usersManagerBl = mock(UsersManagerBl.class);
when(session.getPerunBl().getUsersManagerBl()).thenReturn(usersManagerBl);
PasswordManagerModule module = mock(GenericPasswordManagerModule.class);
when(session.getPerunBl().getUsersManagerBl().getPasswordManagerModule(session, "mu-adm")).thenReturn(module);
ModulesUtilsBl modulesUtilsBl = mock(ModulesUtilsBl.class);
when(perunBl.getModulesUtilsBl()).thenReturn(modulesUtilsBl);
}
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_ceitecTest method setUp.
@Before
public void setUp() throws Exception {
classInstance = new urn_perun_user_attribute_def_def_login_namespace_ceitec();
session = mock(PerunSessionImpl.class);
user = new User();
attributeToCheck = new Attribute();
attributeToCheck.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
attributeToCheck.setFriendlyName("login-namespace:ceitec");
PerunBl perunBl = mock(PerunBl.class);
when(session.getPerunBl()).thenReturn(perunBl);
UsersManagerBl usersManagerBl = mock(UsersManagerBl.class);
when(session.getPerunBl().getUsersManagerBl()).thenReturn(usersManagerBl);
PasswordManagerModule module = mock(GenericPasswordManagerModule.class);
when(session.getPerunBl().getUsersManagerBl().getPasswordManagerModule(session, "ceitec")).thenReturn(module);
ModulesUtilsBl modulesUtilsBl = mock(ModulesUtilsBl.class);
when(perunBl.getModulesUtilsBl()).thenReturn(modulesUtilsBl);
}
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_einfraTest method setUp.
@Before
public void setUp() throws Exception {
classInstance = new urn_perun_user_attribute_def_def_login_namespace_einfra();
session = mock(PerunSessionImpl.class, RETURNS_DEEP_STUBS);
attributeToCheck = new Attribute();
attributeToCheck.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
attributeToCheck.setFriendlyName("login-namespace:einfra");
attributeToCheck.setValue("test");
PerunBl perunBl = mock(PerunBl.class);
when(session.getPerunBl()).thenReturn(perunBl);
UsersManagerBl usersManagerBl = mock(UsersManagerBl.class);
when(session.getPerunBl().getUsersManagerBl()).thenReturn(usersManagerBl);
PasswordManagerModule module = mock(EinfraPasswordManagerModule.class);
when(session.getPerunBl().getUsersManagerBl().getPasswordManagerModule(session, "einfra")).thenReturn(module);
ModulesUtilsBl modulesUtilsBlSpy = spy(mock(ModulesUtilsBl.class));
when(session.getPerunBl().getModulesUtilsBl()).thenReturn(modulesUtilsBlSpy);
Mockito.doThrow(InvalidLoginException.class).when(modulesUtilsBlSpy).checkLoginNamespaceRegex(eq("einfra"), // negated einfra check
ArgumentMatchers.matches("(?!^[a-z][a-z0-9_-]{1,14}$)"), ArgumentMatchers.any(Pattern.class));
}
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_vsupTest method setUp.
@Before
public void setUp() throws Exception {
classInstance = new urn_perun_user_attribute_def_def_login_namespace_vsup();
session = mock(PerunSessionImpl.class);
user = new User();
attributeToCheck = new Attribute();
attributeToCheck.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
attributeToCheck.setFriendlyName("login-namespace:vsup");
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, "vsup")).thenReturn(module);
}
use of cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule 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);
}
}
Aggregations