Search in sources :

Example 6 with PasswordManagerModule

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);
}
Also used : User(cz.metacentrum.perun.core.api.User) ModulesUtilsBl(cz.metacentrum.perun.core.bl.ModulesUtilsBl) CoreConfig(cz.metacentrum.perun.core.api.CoreConfig) Attribute(cz.metacentrum.perun.core.api.Attribute) PasswordManagerModule(cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule) GenericPasswordManagerModule(cz.metacentrum.perun.core.impl.modules.pwdmgr.GenericPasswordManagerModule) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) UsersManagerBl(cz.metacentrum.perun.core.bl.UsersManagerBl) Before(org.junit.Before)

Example 7 with PasswordManagerModule

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);
}
Also used : User(cz.metacentrum.perun.core.api.User) ModulesUtilsBl(cz.metacentrum.perun.core.bl.ModulesUtilsBl) Attribute(cz.metacentrum.perun.core.api.Attribute) PasswordManagerModule(cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule) GenericPasswordManagerModule(cz.metacentrum.perun.core.impl.modules.pwdmgr.GenericPasswordManagerModule) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) UsersManagerBl(cz.metacentrum.perun.core.bl.UsersManagerBl) Before(org.junit.Before)

Example 8 with PasswordManagerModule

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));
}
Also used : Pattern(java.util.regex.Pattern) ModulesUtilsBl(cz.metacentrum.perun.core.bl.ModulesUtilsBl) EinfraPasswordManagerModule(cz.metacentrum.perun.core.impl.modules.pwdmgr.EinfraPasswordManagerModule) PasswordManagerModule(cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) UsersManagerBl(cz.metacentrum.perun.core.bl.UsersManagerBl) Before(org.junit.Before)

Example 9 with PasswordManagerModule

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);
}
Also used : User(cz.metacentrum.perun.core.api.User) ModulesUtilsBl(cz.metacentrum.perun.core.bl.ModulesUtilsBl) Attribute(cz.metacentrum.perun.core.api.Attribute) PasswordManagerModule(cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule) GenericPasswordManagerModule(cz.metacentrum.perun.core.impl.modules.pwdmgr.GenericPasswordManagerModule) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) UsersManagerBl(cz.metacentrum.perun.core.bl.UsersManagerBl) Before(org.junit.Before)

Example 10 with PasswordManagerModule

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);
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) PasswordOperationTimeoutRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordOperationTimeoutRuntimeException) PasswordCreationFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordCreationFailedException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) PasswordOperationTimeoutRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordOperationTimeoutRuntimeException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) MemberAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException) PasswordCreationFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordCreationFailedException) UserExtSourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceAlreadyRemovedException) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) PasswordDoesntMatchRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordDoesntMatchRuntimeException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) LoginNotExistsRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.LoginNotExistsRuntimeException) PasswordStrengthFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthFailedException) PasswordCreationFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException) SpecificUserAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.SpecificUserAlreadyRemovedException) AlreadyReservedLoginException(cz.metacentrum.perun.core.api.exceptions.AlreadyReservedLoginException) SpecificUserOwnerAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.SpecificUserOwnerAlreadyRemovedException) IllegalArgumentException(cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException) PasswordChangeFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordChangeFailedException) PasswordResetLinkExpiredException(cz.metacentrum.perun.core.api.exceptions.PasswordResetLinkExpiredException) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) PasswordChangeFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordChangeFailedRuntimeException) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) PasswordStrengthFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordStrengthFailedRuntimeException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) PasswordStrengthException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException) PasswordDeletionFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordDeletionFailedException) UserAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.UserAlreadyRemovedException) PasswordOperationTimeoutException(cz.metacentrum.perun.core.api.exceptions.PasswordOperationTimeoutException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) RelationNotExistsException(cz.metacentrum.perun.core.api.exceptions.RelationNotExistsException) PasswordDoesntMatchException(cz.metacentrum.perun.core.api.exceptions.PasswordDoesntMatchException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException) PasswordResetLinkNotValidException(cz.metacentrum.perun.core.api.exceptions.PasswordResetLinkNotValidException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) PasswordDeletionFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordDeletionFailedRuntimeException) AnonymizationNotSupportedException(cz.metacentrum.perun.core.api.exceptions.AnonymizationNotSupportedException) PasswordOperationTimeoutException(cz.metacentrum.perun.core.api.exceptions.PasswordOperationTimeoutException) PasswordStrengthFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordStrengthFailedRuntimeException) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) PasswordManagerModule(cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule) GenericPasswordManagerModule(cz.metacentrum.perun.core.impl.modules.pwdmgr.GenericPasswordManagerModule) PasswordCreationFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException) PasswordStrengthFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthFailedException)

Aggregations

PasswordManagerModule (cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule)25 GenericPasswordManagerModule (cz.metacentrum.perun.core.impl.modules.pwdmgr.GenericPasswordManagerModule)20 Attribute (cz.metacentrum.perun.core.api.Attribute)16 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)15 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)13 LoginNotExistsException (cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException)13 PasswordCreationFailedException (cz.metacentrum.perun.core.api.exceptions.PasswordCreationFailedException)13 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)13 PasswordCreationFailedRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException)12 AlreadyAdminException (cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)11 BanNotExistsException (cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)11 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)11 ExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)11 IllegalArgumentException (cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException)11 InvalidLoginException (cz.metacentrum.perun.core.api.exceptions.InvalidLoginException)11 MemberAlreadyRemovedException (cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException)11 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)11 PasswordStrengthException (cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException)11 RelationExistsException (cz.metacentrum.perun.core.api.exceptions.RelationExistsException)11 UserExtSourceExistsException (cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException)11