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());
}
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();
}
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());
}
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);
}
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());
}
Aggregations