use of eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto in project CzechIdMng by bcvsolutions.
the class IdentitySetPasswordProcessorIntegrationTest method testGeneratePassword.
@Test
public void testGeneratePassword() {
SysSystemDto system = helper.createTestResourceSystem(true);
//
IdmRoleDto role = helper.createRole();
helper.createRoleSystem(role, system);
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityContractDto contract = helper.getPrimeContract(identity.getId());
contract.setValidFrom(new LocalDate().plusDays(1));
identityContractService.save(contract);
identity = identityService.get(identity.getId());
Assert.assertEquals(IdentityState.FUTURE_CONTRACT, identity.getState());
helper.createIdentityRole(identity, role);
//
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
AccIdentityAccountDto accountIdentityOne = identityAccountService.find(filter, null).getContent().get(0);
AccAccountDto account = accountService.get(accountIdentityOne.getAccount());
// Create new password one
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setAccounts(ImmutableList.of(account.getId().toString()));
passwordChange.setNewPassword(new GuardedString(IDENTITY_PASSWORD_ONE));
passwordChange.setIdm(true);
//
// Do change of password for selected accounts
identityService.passwordChange(identity, passwordChange);
//
// Check correct password One
TestResource resource = helper.findResource(account.getRealUid());
Assert.assertNotNull(resource);
Assert.assertEquals(IDENTITY_PASSWORD_ONE, resource.getPassword());
//
// set contract to valid
contract.setValidFrom(new LocalDate());
identityContractService.save(contract);
identity = identityService.get(identity.getId());
Assert.assertEquals(IdentityState.VALID, identity.getState());
//
// check password on target system was changed
resource = helper.findResource(account.getRealUid());
Assert.assertNotNull(resource);
Assert.assertNotEquals(IDENTITY_PASSWORD_ONE, resource.getPassword());
}
use of eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto in project CzechIdMng by bcvsolutions.
the class IdentityAccountManagementTest method overloadedAttributeChangePassword.
@Test
public void overloadedAttributeChangePassword() {
IdmIdentityDto identity = identityService.getByUsername(IDENTITY_USERNAME);
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
filter.setSystemId(systemService.getByCode(SYSTEM_NAME).getId());
List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(filter, new PageRequest(0, 1, new Sort(Sort.Direction.ASC, AccIdentityAccount_.created.getName()))).getContent();
TestResource resourceAccount = helper.findResource("x" + IDENTITY_USERNAME);
// Create new password two
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setAccounts(ImmutableList.of(identityAccounts.get(0).getAccount().toString()));
passwordChange.setNewPassword(new GuardedString(IDENTITY_PASSWORD_TWO));
passwordChange.setIdm(true);
// Do change of password for selected accounts
identityService.passwordChange(identity, passwordChange);
// Check correct password two
resourceAccount = helper.findResource("x" + IDENTITY_USERNAME);
Assert.assertEquals("Check same password on target system", IDENTITY_PASSWORD_TWO, resourceAccount.getPassword());
// Add overloaded password attribute
IdmRoleDto rolePassword = roleService.getByCode(ROLE_OVERLOADING_PASSWORD);
IdmIdentityRoleDto irdto = new IdmIdentityRoleDto();
irdto.setIdentityContract(identityContractService.findAllByIdentity(identity.getId()).get(0).getId());
irdto.setRole(rolePassword.getId());
// This evokes IdentityRole SAVE event. On this event will be start
// account management and provisioning
identityRoleService.save(irdto);
// Do change of password for selected accounts
passwordChange.setNewPassword(new GuardedString(IDENTITY_PASSWORD_THREE));
identityService.passwordChange(identity, passwordChange);
// Check correct overloaded password two
resourceAccount = helper.findResource("x" + IDENTITY_USERNAME);
Assert.assertEquals("Check overloaded password (added x) on target system", "x" + IDENTITY_PASSWORD_THREE, resourceAccount.getPassword());
}
use of eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAuthenticatorTest method loginViaManagerBadCredentials.
@Test(expected = IdmAuthenticationException.class)
public void loginViaManagerBadCredentials() {
IdmIdentityDto identity = identityService.getByUsername(USERNAME);
PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
passwordChangeDto.setAll(true);
passwordChangeDto.setIdm(false);
passwordChangeDto.setNewPassword(new GuardedString(PASSWORD));
// change password for system
provisioningService.changePassword(identity, passwordChangeDto);
LoginDto loginDto = new LoginDto();
loginDto.setUsername(USERNAME);
loginDto.setPassword(new GuardedString("test"));
authenticationManager.authenticate(loginDto);
}
use of eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto 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());
}
use of eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto in project CzechIdMng by bcvsolutions.
the class BasicIdmAuthenticationFilterTest method testDisableIdmPasswordChangeViaRest.
@Test
public void testDisableIdmPasswordChangeViaRest() throws JsonProcessingException {
String testPassword = "testPassword";
String newTestPassword = "newTestPassword";
//
this.loginAsAdmin(TEST_ADMIN_USERNAME);
configurationService.setBooleanValue(IdentityConfiguration.PROPERTY_PUBLIC_CHANGE_PASSWORD_FOR_IDM_ENABLED, false);
//
// create identity
IdmIdentityDto identity = createIdentityInTransaction(testPassword);
// allow password change
IdmRoleDto roleWithPermission = testHelper.createRole();
testHelper.createAuthorizationPolicy(roleWithPermission.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, SelfIdentityEvaluator.class, IdentityBasePermission.PASSWORDCHANGE);
testHelper.assignRoles(testHelper.getPrimeContract(identity.getId()), roleWithPermission);
this.logout();
authorizationPolicyService.getDefaultAuthorities(identity.getId());
PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
passwordChangeDto.setAll(true);
passwordChangeDto.setIdm(true);
passwordChangeDto.setNewPassword(new GuardedString(newTestPassword));
passwordChangeDto.setOldPassword(new GuardedString(testPassword));
List<OperationResult> passwordChangeResults = passwordChangeController.passwordChange(identity.getUsername(), passwordChangeDto);
assertEquals(0, passwordChangeResults.size());
}
Aggregations