use of eu.bcvsolutions.idm.acc.dto.AccAccountDto 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.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class ProvisioningBreakProcessorTest method createAccount.
/**
* Create {@link AccAccountDto} and {@link AccIdentityAccountDto} for system
* and identity
*
* @param system
* @param identity
* @return
*/
private AccIdentityAccountDto createAccount(SysSystemDto system, IdmIdentityDto identity) {
AccAccountDto account = new AccAccountDto();
account.setSystem(system.getId());
account.setUid(identity.getUsername());
account.setAccountType(AccountType.PERSONAL);
account.setEntityType(SystemEntityType.IDENTITY);
account = accountService.save(account);
AccIdentityAccountDto accountIdentity = new AccIdentityAccountDto();
accountIdentity.setIdentity(identity.getId());
accountIdentity.setOwnership(true);
accountIdentity.setAccount(account.getId());
return identityAccoutnService.save(accountIdentity);
}
use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class AccountProtectionExpirationTaskExecutorIntegrationTest method testRemoveExpiredAccount.
@Test
public void testRemoveExpiredAccount() {
IdmIdentityDto identity = helper.createIdentity();
IdmRoleDto role = helper.createRole();
SysSystemDto system = helper.createTestResourceSystem(true);
SysSystemMappingDto mapping = helper.getDefaultMapping(system);
mapping.setProtectionInterval(1);
mapping.setProtectionEnabled(true);
systemMappingService.save(mapping);
helper.createRoleSystem(role, system);
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role);
//
AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertFalse(account.isInProtection());
TestResource createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
//
// remove role
identityRoleService.deleteById(identityRole.getId());
//
account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertTrue(account.isInProtection());
Assert.assertNotNull(account.getEndOfProtection());
createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
//
// test LRT - nothing to remove
AccountProtectionExpirationTaskExecutor taskExecutor = new AccountProtectionExpirationTaskExecutor();
longRunningTaskManager.execute(taskExecutor);
//
account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertTrue(account.isInProtection());
Assert.assertNotNull(account.getEndOfProtection());
createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
// change account expiration
account.setEndOfProtection(new DateTime().minusDays(1));
account = accountService.save(account);
taskExecutor = new AccountProtectionExpirationTaskExecutor();
longRunningTaskManager.execute(taskExecutor);
AccAccountDto removedAccount = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNull(removedAccount);
createdAccount = helper.findResource(account.getUid());
Assert.assertNull(createdAccount);
}
use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class AccountProtectionExpirationTaskExecutorUnitTest method testTwoPageIterations.
@Test
public void testTwoPageIterations() {
List<AccAccountDto> accounts = new ArrayList<>();
accounts.add(new AccAccountDto());
accounts.add(new AccAccountDto());
//
when(service.findExpired(any(DateTime.class), any(PageRequest.class))).thenReturn(new PageImpl<AccAccountDto>(accounts));
//
doNothing().when(service).delete(any(AccAccountDto.class));
//
when(executor.updateState()).thenReturn(true);
//
Boolean result = executor.process();
Assert.assertTrue(result);
Assert.assertEquals(Long.valueOf(2), executor.getCount());
}
use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.
the class IdentityAccountByRoleEvaluatorIntegrationTest method testCanReadIdentityAccount.
@Test
public void testCanReadIdentityAccount() {
IdmIdentityDto identity;
AccIdentityAccountDto accountIdentityOne;
try {
loginAsAdmin(InitApplicationData.ADMIN_USERNAME);
//
identity = helper.createIdentity();
SysSystemDto system = helper.createTestResourceSystem(true);
AccAccountDto accountOne = new AccAccountDto();
accountOne.setSystem(system.getId());
accountOne.setUid(identity.getUsername());
accountOne.setAccountType(AccountType.PERSONAL);
accountOne = accountService.save(accountOne);
accountIdentityOne = new AccIdentityAccountDto();
accountIdentityOne.setIdentity(identity.getId());
accountIdentityOne.setOwnership(true);
accountIdentityOne.setAccount(accountOne.getId());
accountIdentityOne = identityAccountService.save(accountIdentityOne);
IdmRoleDto role = helper.createRole();
IdmRoleDto defaultRole = roleService.getByCode(InitDemoData.DEFAULT_ROLE_NAME);
IdmAuthorizationPolicyDto policy = new IdmAuthorizationPolicyDto();
policy.setRole(role.getId());
policy.setGroupPermission(AccGroupPermission.IDENTITYACCOUNT.getName());
policy.setAuthorizableType(AccIdentityAccount.class.getCanonicalName());
policy.setEvaluator(IdentityAccountByAccountEvaluator.class);
authorizationPolicyService.save(policy);
IdmAuthorizationPolicyDto policyAccount = new IdmAuthorizationPolicyDto();
policyAccount.setRole(role.getId());
policyAccount.setGroupPermission(AccGroupPermission.ACCOUNT.getName());
policyAccount.setAuthorizableType(AccAccount.class.getCanonicalName());
policyAccount.setEvaluator(ReadAccountByIdentityEvaluator.class);
authorizationPolicyService.save(policyAccount);
helper.createIdentityRole(identity, role);
helper.createIdentityRole(identity, defaultRole);
} finally {
logout();
}
// check
try {
loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
AccIdentityAccountDto read = identityAccountService.get(accountIdentityOne.getId(), IdmBasePermission.READ);
Assert.assertEquals(accountIdentityOne, read);
} finally {
logout();
}
}
Aggregations