use of eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter in project CzechIdMng by bcvsolutions.
the class IdentityDeleteProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
IdmIdentityDto identity = event.getContent();
Assert.notNull(identity, "Identity is required.");
Assert.notNull(identity.getId(), "Identity identifier is required.");
//
// Clears default leader.
syncConfigRepository.findByDefaultLeader(identity.getId()).forEach(config -> {
SysSyncContractConfigDto configDto = (SysSyncContractConfigDto) syncConfigService.get(config.getId());
configDto.setDefaultLeader(null);
syncConfigService.save(configDto);
});
//
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
identityAccountService.find(filter, null).forEach(identityAccount -> {
identityAccountService.forceDelete(identityAccount);
});
//
// remove all recipients from provisioning break
deleteProvisioningRecipients(identity.getId());
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter in project CzechIdMng by bcvsolutions.
the class AccIdentityAccountController method toFilter.
@Override
protected AccIdentityAccountFilter toFilter(MultiValueMap<String, Object> parameters) {
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setAccountId(getParameterConverter().toUuid(parameters, "accountId"));
filter.setIdentityId(getParameterConverter().toEntityUuid(parameters, AccIdentityAccountFilter.PARAMETER_IDENTITY_ID, IdmIdentityDto.class));
filter.setRoleId(getParameterConverter().toUuid(parameters, "roleId"));
filter.setSystemId(getParameterConverter().toUuid(parameters, "systemId"));
filter.setOwnership(getParameterConverter().toBoolean(parameters, "ownership"));
return filter;
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testDefaultRoleToAllContracts.
@Test
public void testDefaultRoleToAllContracts() {
IdmIdentityDto identityDto = helper.createIdentity((GuardedString) null);
SysSystemDto system = initData(identityDto.getUsername());
Assert.assertNotNull(system);
IdmRoleDto defaultRole = helper.createRole();
//
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
config.setInactiveOwnerBehavior(SynchronizationInactiveOwnerBehaviorType.LINK);
config.setCreateDefaultContract(false);
config.setAssignDefaultRoleToAll(true);
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
//
// create default mapping for provisioning
helper.createMapping(system);
helper.createRoleSystem(defaultRole, system);
IdmIdentityContractDto validContract = helper.getPrimeContract(identityDto);
IdmIdentityContractDto validFutureContract = helper.createContract(identityDto, null, LocalDate.now().plusDays(10), null);
helper.createContract(identityDto, null, null, LocalDate.now().minusDays(1));
List<IdmIdentityContractDto> contracts = contractService.findAllByIdentity(identityDto.getId());
Assert.assertEquals(3, contracts.size());
helper.startSynchronization(config);
// Have to be in the success state, because default role will be assigned to the valid contracts.
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK, 1, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
IdmIdentityDto identity = identityService.get(identityDto);
List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, roles.size());
long identityRolesWithDefaultRole = roles.stream().filter(role -> role.getRole().equals(defaultRole.getId())).count();
Assert.assertEquals(2, identityRolesWithDefaultRole);
// Valid contract must have default role
long identityRolesWithValidContract = roles.stream().filter(role -> role.getIdentityContract().equals(validContract.getId())).count();
Assert.assertEquals(1, identityRolesWithValidContract);
// Future contract must have default role
long identityRolesWithFutureContract = roles.stream().filter(role -> role.getIdentityContract().equals(validFutureContract.getId())).count();
Assert.assertEquals(1, identityRolesWithFutureContract);
// Check only one identity account is created.
// Only one identity-account relation can exists, because only one
// current valid identity-role exists now (the second is future valid).
AccIdentityAccountFilter accountFilter = new AccIdentityAccountFilter();
accountFilter.setIdentityId(identity.getId());
List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(accountFilter, null).getContent();
// !!!!To delete - Test doesn't pass on the Jenkins, we need to more information
if (identityAccounts.size() > 1) {
identityAccounts.forEach(identityAccountDtoOne -> {
System.out.println("Id - identityAccount: " + identityAccountDtoOne.getId());
System.out.println("Account: " + identityAccountDtoOne.getAccount());
System.out.println("RoleSystem: " + identityAccountDtoOne.getRoleSystem());
System.out.println("Identity: " + identityAccountDtoOne.getIdentity());
System.out.println("IdentityRole: " + identityAccountDtoOne.getIdentityRole());
System.out.println("----");
});
}
// !!!
Assert.assertEquals(1, identityAccounts.size());
// Delete log
syncLogService.delete(log);
syncConfigService.delete(config);
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method checkIdentityAccount.
private void checkIdentityAccount(IdmIdentityDto identity, int numberOfAccounts, UUID identityRole) {
AccIdentityAccountFilter identityAccountFilter = new AccIdentityAccountFilter();
identityAccountFilter.setIdentityId(identity.getId());
List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(identityAccountFilter, null).getContent();
Assert.assertEquals(numberOfAccounts, identityAccounts.size());
if (numberOfAccounts == 0) {
return;
}
Assert.assertEquals(identityRole, identityAccounts.get(0).getIdentityRole());
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testCreateIdentityWithDefaultContractAndRoleSync.
@Test
public void testCreateIdentityWithDefaultContractAndRoleSync() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
IdmRoleDto defaultRole = helper.createRole();
//
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
config.setInactiveOwnerBehavior(SynchronizationInactiveOwnerBehaviorType.LINK);
config.setCreateDefaultContract(true);
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
//
// create default mapping for provisioning
helper.createMapping(system);
helper.createRoleSystem(defaultRole, system);
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setUsername(IDENTITY_ONE);
List<IdmIdentityDto> identities = identityService.find(identityFilter, null).getContent();
Assert.assertEquals(0, identities.size());
helper.startSynchronization(config);
// Have to be in the success state, because default role will be assigned to the default contract.
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
identities = identityService.find(identityFilter, null).getContent();
Assert.assertEquals(1, identities.size());
IdmIdentityDto identity = identities.get(0);
List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identities.get(0).getId());
Assert.assertEquals(1, roles.size());
IdmIdentityRoleDto assignedRole = roles.get(0);
Assert.assertEquals(defaultRole.getId(), assignedRole.getRole());
// check only one identity account is created
AccIdentityAccountFilter accountFilter = new AccIdentityAccountFilter();
accountFilter.setIdentityId(identity.getId());
List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(accountFilter, null).getContent();
Assert.assertEquals(1, identityAccounts.size());
Assert.assertEquals(assignedRole.getId(), identityAccounts.get(0).getIdentityRole());
// Delete log
syncLogService.delete(log);
syncConfigService.delete(config);
}
Aggregations