Search in sources :

Example 26 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultAuthenticationManagerIntegrationTest method testChangPasswordWithNeverExpiresAndValidTill.

@Test
public void testChangPasswordWithNeverExpiresAndValidTill() {
    IdmPasswordPolicyDto validatePolicy = new IdmPasswordPolicyDto();
    validatePolicy.setName(getHelper().createName());
    validatePolicy.setMaxPasswordAge(10);
    validatePolicy.setDefaultPolicy(true);
    validatePolicy.setType(IdmPasswordPolicyType.VALIDATE);
    validatePolicy = passwordPolicyService.save(validatePolicy);
    String password = "pass-" + System.currentTimeMillis();
    IdmIdentityDto identityDto = this.getHelper().createIdentity(new GuardedString(password));
    IdmPasswordDto passwordDto = passwordService.findOneByIdentity(identityDto.getId());
    assertEquals(LocalDate.now().plusDays(10), passwordDto.getValidTill());
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setOldPassword(new GuardedString(password));
    passwordChange.setNewPassword(new GuardedString(password + "2"));
    passwordService.save(identityDto, passwordChange);
    assertFalse(passwordDto.isPasswordNeverExpires());
    passwordDto.setPasswordNeverExpires(true);
    IdmPasswordDto newlySaved = passwordService.save(passwordDto);
    assertTrue(newlySaved.isPasswordNeverExpires());
    assertNull(passwordDto.getValidTill());
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 27 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultAuthenticationManagerIntegrationTest method testSavePasswordNeverExpires.

@Test
public void testSavePasswordNeverExpires() {
    String password = "pass-" + System.currentTimeMillis();
    IdmIdentityDto identityDto = this.getHelper().createIdentity(new GuardedString(password));
    IdmPasswordDto passwordDto = passwordService.findOneByIdentity(identityDto.getId());
    assertFalse(passwordDto.isPasswordNeverExpires());
    passwordDto.setPasswordNeverExpires(true);
    IdmPasswordDto newlySaved = passwordService.save(passwordDto);
    assertTrue(newlySaved.isPasswordNeverExpires());
}
Also used : IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 28 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultAuthenticationManagerIntegrationTest method testBlockLogin.

@Test
public void testBlockLogin() throws InterruptedException {
    loginAsAdmin();
    String testPassword = "testPassword" + System.currentTimeMillis();
    IdmPasswordPolicyDto passwordPolicy = new IdmPasswordPolicyDto();
    passwordPolicy.setName(getHelper().createName());
    passwordPolicy.setDefaultPolicy(true);
    passwordPolicy.setType(IdmPasswordPolicyType.VALIDATE);
    passwordPolicy.setBlockLoginTime(2);
    passwordPolicy.setMaxUnsuccessfulAttempts(4);
    passwordPolicy = passwordPolicyService.save(passwordPolicy);
    IdmIdentityDto identity = getHelper().createIdentity(new GuardedString(testPassword));
    logout();
    LoginDto loginDto = tryLogin(identity.getUsername(), testPassword);
    assertNotNull(loginDto.getToken());
    assertEquals(CoreModuleDescriptor.MODULE_ID, loginDto.getAuthenticationModule());
    // try fail - 1#
    tryLoginExceptFail(identity.getUsername(), "badPassword" + System.currentTimeMillis());
    identity = identityService.get(identity.getId());
    assertNull(identity.getBlockLoginDate());
    // try fail - 2#
    tryLoginExceptFail(identity.getUsername(), "badPassword" + System.currentTimeMillis());
    identity = identityService.get(identity.getId());
    assertNull(identity.getBlockLoginDate());
    // try fail - 3#
    tryLoginExceptFail(identity.getUsername(), "badPassword" + System.currentTimeMillis());
    identity = identityService.get(identity.getId());
    assertNull(identity.getBlockLoginDate());
    // try fail - 4# (block)
    tryLoginExceptFail(identity.getUsername(), "badPassword" + System.currentTimeMillis());
    identity = identityService.get(identity.getId());
    ZonedDateTime blockLoginDate = identity.getBlockLoginDate();
    // blockLoginDate isn't filled by service more
    assertNull(blockLoginDate);
    IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
    assertNotNull(password);
    blockLoginDate = password.getBlockLoginDate();
    assertNotNull(blockLoginDate);
    // try success but login is blocked
    tryLoginExceptFail(identity.getUsername(), testPassword);
    identity = identityService.get(identity.getId());
    password = passwordService.findOneByIdentity(identity.getId());
    assertNotNull(password);
    assertNotNull(password.getBlockLoginDate());
    // date is same
    assertEquals(blockLoginDate, password.getBlockLoginDate());
    // wait for 2 sec
    Thread.sleep(2000);
    loginDto = tryLogin(identity.getUsername(), testPassword);
    assertNotNull(loginDto.getToken());
    assertEquals(CoreModuleDescriptor.MODULE_ID, loginDto.getAuthenticationModule());
    passwordPolicyService.delete(passwordPolicy);
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) ZonedDateTime(java.time.ZonedDateTime) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 29 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultAuthenticationManagerIntegrationTest method testLoginWithoutPasswordPolicy.

@Test
public void testLoginWithoutPasswordPolicy() {
    // remove all policies
    for (IdmPasswordPolicyDto passwordPolicy : passwordPolicyService.find(null)) {
        passwordPolicyService.delete(passwordPolicy);
    }
    String testPassword = "testPassword" + System.currentTimeMillis();
    IdmIdentityDto identity = getHelper().createIdentity(new GuardedString(testPassword));
    logout();
    LoginDto loginDto = tryLogin(identity.getUsername(), testPassword);
    checkLoginDto(loginDto);
    String wrongPassword = "badPassword" + System.currentTimeMillis();
    tryLoginExceptFail(identity.getUsername(), wrongPassword);
    tryLoginExceptFail(identity.getUsername(), wrongPassword);
    tryLoginExceptFail(identity.getUsername(), wrongPassword);
    tryLoginExceptFail(identity.getUsername(), wrongPassword);
    IdmPasswordDto passwordDto = passwordService.findOneByIdentity(identity.getId());
    assertNotNull(passwordDto);
    assertNull(passwordDto.getBlockLoginDate());
    identity = identityService.get(identity.getId());
    assertNull(identity.getBlockLoginDate());
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 30 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultTwoFactorAuthenticationManagerIntegrationTest method testAuthenticateMustChangePasswordIsSkipped.

@Test
public void testAuthenticateMustChangePasswordIsSkipped() {
    // password is needed
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
    password.setMustChange(true);
    passwordService.save(password);
    // 
    TwoFactorRegistrationResponseDto initResponse = manager.init(identity.getId(), TwoFactorAuthenticationType.NOTIFICATION);
    Assert.assertNotNull(initResponse);
    Assert.assertNotNull(initResponse.getVerificationSecret());
    Assert.assertEquals(identity.getUsername(), initResponse.getUsername());
    Assert.assertNull(initResponse.getQrcode());
    // 
    // confirm
    TwoFactorRegistrationConfirmDto confirm = new TwoFactorRegistrationConfirmDto();
    confirm.setVerificationSecret(new GuardedString(initResponse.getVerificationSecret()));
    confirm.setVerificationCode(manager.generateCode(new GuardedString(initResponse.getVerificationSecret())));
    confirm.setTwoFactorAuthenticationType(TwoFactorAuthenticationType.NOTIFICATION);
    Assert.assertTrue(manager.confirm(identity.getId(), confirm));
    Assert.assertEquals(initResponse.getVerificationSecret(), getHelper().getPassword(identity).getVerificationSecret());
    // 
    LoginDto loginDto = new LoginDto();
    loginDto.setUsername(identity.getUsername());
    loginDto.setPassword(identity.getPassword());
    // creadentials are valid
    Assert.assertTrue(authenticationManager.validate(loginDto));
    // but two factor authentication is required
    String token = null;
    try {
        authenticationManager.authenticate(loginDto);
    } catch (TwoFactorAuthenticationRequiredException ex) {
        token = ex.getToken();
    }
    Assert.assertNotNull(token);
    // 
    loginDto.setToken(token);
    loginDto.setPassword(manager.generateCode(identity.getId()));
    loginDto.setSkipMustChange(true);
    LoginDto authenticated = manager.authenticate(loginDto);
    // 
    Assert.assertNotNull(authenticated);
    Assert.assertNotNull(authenticated.getAuthentication());
    Assert.assertTrue(tokenManager.getToken(authenticated.getAuthentication().getId()).isSecretVerified());
}
Also used : TwoFactorRegistrationConfirmDto(eu.bcvsolutions.idm.core.security.api.dto.TwoFactorRegistrationConfirmDto) TwoFactorRegistrationResponseDto(eu.bcvsolutions.idm.core.security.api.dto.TwoFactorRegistrationResponseDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) TwoFactorAuthenticationRequiredException(eu.bcvsolutions.idm.core.security.api.exception.TwoFactorAuthenticationRequiredException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)88 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)71 Test (org.junit.Test)65 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)53 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)52 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)28 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)20 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)19 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)11 Transactional (org.springframework.transaction.annotation.Transactional)11 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)10 AbstractPasswordFilterIntegrationTest (eu.bcvsolutions.idm.acc.AbstractPasswordFilterIntegrationTest)9 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)9 IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)9 IdmScheduledTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)9 ZonedDateTime (java.time.ZonedDateTime)9 UUID (java.util.UUID)9 IdmPasswordFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordFilter)8 IdmAuthenticationException (eu.bcvsolutions.idm.core.security.api.exception.IdmAuthenticationException)8 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)7