Search in sources :

Example 26 with GuardedString

use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.

the class DefaultCryptServiceTest method encryptAndDecryptGuardedString.

@Test
public void encryptAndDecryptGuardedString() {
    GuardedString password = new GuardedString("123456");
    String encryptString = cryptService.encryptString(password.asString());
    assertNotEquals(password.asString(), encryptString);
    String decryptString = cryptService.decryptString(encryptString);
    assertNotEquals(decryptString, encryptString);
    assertEquals(decryptString, password.asString());
}
Also used : GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 27 with GuardedString

use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.

the class LoginControllerRestTest method testFailLoginCounter.

@Test
@Transactional
public void testFailLoginCounter() throws Exception {
    IdmIdentityDto identity = testHelper.createIdentity(new GuardedString("SafePassword"));
    // Unsuccessful attempts
    tryLogin(identity.getUsername(), "hgjgjh").andExpect(status().is(HttpStatus.UNAUTHORIZED.value()));
    tryLogin(identity.getUsername(), "hgjgjh").andExpect(status().is(HttpStatus.UNAUTHORIZED.value()));
    tryLogin(identity.getUsername(), "hgjgjh").andExpect(status().is(HttpStatus.UNAUTHORIZED.value()));
    assertEquals(3, passwordService.findOneByIdentity(identity.getUsername()).getUnsuccessfulAttempts());
    // Successful attempt
    LoginDto loginDto = new LoginDto();
    loginDto.setUsername(identity.getUsername());
    loginDto.setPassword(new GuardedString("SafePassword"));
    loginController.login(loginDto);
    // 
    assertEquals(0, passwordService.findOneByIdentity(identity.getUsername()).getUnsuccessfulAttempts());
    // 
    logout();
}
Also used : 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) Test(org.junit.Test) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with GuardedString

use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.

the class LoginControllerTest method testSuccesfulLogIn.

@Test
public void testSuccesfulLogIn() throws Exception {
    LoginDto loginDto = new LoginDto();
    loginDto.setUsername(InitTestData.TEST_ADMIN_USERNAME);
    loginDto.setPassword(new GuardedString(InitTestData.TEST_ADMIN_PASSWORD));
    Resource<LoginDto> response = loginController.login(loginDto);
    IdmJwtAuthenticationDto authentication = response.getContent().getAuthentication();
    assertNotNull(authentication);
    assertEquals(InitTestData.TEST_ADMIN_USERNAME, authentication.getCurrentUsername());
    assertEquals(InitTestData.TEST_ADMIN_USERNAME, authentication.getOriginalUsername());
}
Also used : IdmJwtAuthenticationDto(eu.bcvsolutions.idm.core.security.api.dto.IdmJwtAuthenticationDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 29 with GuardedString

use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.

the class LoginControllerTest method testBadCredentialsLogIn.

@Test(expected = AuthenticationException.class)
public void testBadCredentialsLogIn() {
    LoginDto loginDto = new LoginDto();
    loginDto.setUsername(InitTestData.TEST_ADMIN_USERNAME);
    loginDto.setPassword(new GuardedString("wrong_pass"));
    loginController.login(loginDto);
}
Also used : GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 30 with GuardedString

use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.

the class BasicIdmAuthenticationFilterTest method testEnableIdmPasswordChange.

@Test
public void testEnableIdmPasswordChange() {
    String testPassword = "testPassword";
    String newTestPassword = "newTestPassword";
    // 
    this.loginAsAdmin(TEST_ADMIN_USERNAME);
    configurationService.setBooleanValue(IdentityConfiguration.PROPERTY_PUBLIC_CHANGE_PASSWORD_FOR_IDM_ENABLED, true);
    // 
    // create identity
    IdmIdentityDto identity = testHelper.createIdentity();
    PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
    passwordChangeDto.setNewPassword(new GuardedString(testPassword));
    passwordService.save(identity, passwordChangeDto);
    this.logout();
    // 
    LoginDto loginDto = new LoginDto();
    loginDto.setUsername(identity.getUsername());
    loginDto.setPassword(new GuardedString(testPassword));
    LoginDto login = loginService.login(loginDto);
    // 
    assertNotNull(login.getAuthentication());
    // 
    passwordChangeDto = new PasswordChangeDto();
    passwordChangeDto.setNewPassword(new GuardedString(newTestPassword));
    passwordChangeDto.setOldPassword(new GuardedString(testPassword));
    passwordChangeDto.setAll(true);
    passwordChangeDto.setIdm(true);
    // 
    List<OperationResult> passwordChangeResults = identityService.passwordChange(identity, passwordChangeDto);
    // 
    assertEquals(1, passwordChangeResults.size());
    OperationResult operationResult = passwordChangeResults.get(0);
    assertEquals(OperationState.EXECUTED, operationResult.getState());
    assertEquals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name(), operationResult.getModel().getStatusEnum());
    assertEquals(HttpStatus.OK, operationResult.getModel().getStatus());
    // 
    loginDto.setUsername(identity.getUsername());
    loginDto.setPassword(new GuardedString(newTestPassword));
    login = loginService.login(loginDto);
    // 
    assertNotNull(login.getAuthentication());
}
Also used : PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) 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) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Aggregations

GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)97 Test (org.junit.Test)61 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)59 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)49 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)40 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)30 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)26 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)20 ArrayList (java.util.ArrayList)13 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)11 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)11 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)10 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)9 HashMap (java.util.HashMap)9 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)8 Transactional (org.springframework.transaction.annotation.Transactional)8 ProvisioningAttributeDto (eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto)7 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)7 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)7 List (java.util.List)7