use of eu.bcvsolutions.idm.acc.dto.AccRoleAccountDto in project CzechIdMng by bcvsolutions.
the class RoleProvisioningExecutor method doProvisioning.
public void doProvisioning(AccAccountDto account) {
Assert.notNull(account, "Account is required.");
AccRoleAccountFilter filter = new AccRoleAccountFilter();
filter.setAccountId(account.getId());
List<AccRoleAccountDto> entityAccoutnList = roleAccountService.find(filter, null).getContent();
if (entityAccoutnList == null) {
return;
}
entityAccoutnList.stream().filter(entityAccount -> {
return entityAccount.isOwnership();
}).forEach((roleAccount) -> {
doProvisioning(account, DtoUtils.getEmbedded(roleAccount, AccRoleAccount_.role, IdmRoleDto.class));
});
}
use of eu.bcvsolutions.idm.acc.dto.AccRoleAccountDto in project CzechIdMng by bcvsolutions.
the class AccountManagementTest method testAccountCanBeCreated.
@Test
public /**
* Script on the mapping "Can be account created?" returns true (if priority is 1000).
*/
void testAccountCanBeCreated() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(system.getId(), SystemEntityType.ROLE);
Assert.assertNotNull(mapping);
mapping.setCanBeAccountCreatedScript("return entity.getPriority() == 1000;");
mapping = systemMappingService.save(mapping);
IdmRoleDto defaultRole = helper.createRole();
defaultRole.setPriority(500);
roleService.save(defaultRole);
AccRoleAccountFilter roleAccountFilter = new AccRoleAccountFilter();
roleAccountFilter.setEntityId(defaultRole.getId());
roleAccountFilter.setOwnership(Boolean.TRUE);
roleAccountFilter.setSystemId(system.getId());
List<AccRoleAccountDto> roleAccounts = roleAccountService.find(roleAccountFilter, null).getContent();
// Priority is 500 -> account should not be created
Assert.assertEquals(0, roleAccounts.size());
// Set priority to 1000
defaultRole.setPriority(1000);
roleService.save(defaultRole);
roleAccounts = roleAccountService.find(roleAccountFilter, null).getContent();
// Priority is 1000 -> account had to be created
Assert.assertEquals(1, roleAccounts.size());
// Delete role
roleService.delete(defaultRole);
// Delete role mapping
systemMappingService.delete(mapping);
}
use of eu.bcvsolutions.idm.acc.dto.AccRoleAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultAccRoleAccountService method getRoleId.
@Override
public UUID getRoleId(UUID account) {
AccRoleAccountFilter accountFilter = new AccRoleAccountFilter();
accountFilter.setAccountId(account);
accountFilter.setOwnership(Boolean.TRUE);
List<AccRoleAccountDto> roleAccounts = this.find(accountFilter, null).getContent();
if (roleAccounts.isEmpty()) {
throw new ResultCodeException(AccResultCode.ROLE_ACCOUNT_NOT_FOUND, ImmutableMap.of("account", account));
}
return roleAccounts.get(0).getRole();
}
use of eu.bcvsolutions.idm.acc.dto.AccRoleAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultAccRoleAccountService method delete.
@Override
@Transactional
public void delete(AccRoleAccountDto entity, boolean deleteTargetAccount, BasePermission... permission) {
Assert.notNull(entity, "Entity is required.");
super.delete(entity, permission);
UUID account = entity.getAccount();
// We check if exists another (ownership) identityAccounts, if not
// then
// we will delete account
AccRoleAccountFilter filter = new AccRoleAccountFilter();
filter.setAccountId(account);
filter.setOwnership(Boolean.TRUE);
List<AccRoleAccountDto> entityAccounts = this.find(filter, null).getContent();
boolean moreEntityAccounts = entityAccounts.stream().filter(treeAccount -> {
return treeAccount.isOwnership() && !treeAccount.equals(entity);
}).findAny().isPresent();
if (!moreEntityAccounts && entity.isOwnership()) {
// We delete all tree accounts first
entityAccounts.forEach(identityAccount -> {
super.delete(identityAccount);
});
// Finally we can delete account
accountService.publish(new AccountEvent(AccountEventType.DELETE, accountService.get(account), ImmutableMap.of(AccAccountService.DELETE_TARGET_ACCOUNT_PROPERTY, deleteTargetAccount, AccAccountService.ENTITY_ID_PROPERTY, entity.getEntity())));
}
}
use of eu.bcvsolutions.idm.acc.dto.AccRoleAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultRoleSynchronizationExecutorTest method testSyncRolesCatalogueRemoveUnderMain.
@Test
public void testSyncRolesCatalogueRemoveUnderMain() {
AbstractSysSyncConfigDto syncConfigCustom = createSyncConfig();
SysSystemDto userSystem = helper.createTestResourceSystem(true);
List<SysSystemMappingDto> userSystemMappings = systemMappingService.findBySystem(userSystem, SystemOperationType.PROVISIONING, SystemEntityType.IDENTITY);
Assert.assertNotNull(userSystemMappings);
Assert.assertEquals(1, userSystemMappings.size());
SysSystemMappingDto userMappingDto = userSystemMappings.get(0);
// Switch to the sync.
userMappingDto.setOperationType(SystemOperationType.SYNCHRONIZATION);
userMappingDto = systemMappingService.save(userMappingDto);
List<SysSystemAttributeMappingDto> attributeMappingDtos = schemaAttributeMappingService.findBySystemMapping(userMappingDto);
SysSystemAttributeMappingDto userEmailAttribute = attributeMappingDtos.stream().filter(attribute -> attribute.getName().equalsIgnoreCase(TestHelper.ATTRIBUTE_MAPPING_EMAIL)).findFirst().orElse(null);
Assert.assertNotNull(userEmailAttribute);
Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
Assert.assertTrue(syncConfigCustom instanceof SysSyncRoleConfigDto);
SysSyncRoleConfigDto roleConfigDto = (SysSyncRoleConfigDto) syncConfigCustom;
SysSystemMappingDto systemMappingDto = DtoUtils.getEmbedded(syncConfigCustom, SysSyncConfig_.systemMapping, SysSystemMappingDto.class);
SysSchemaObjectClassDto schemaObjectClassDto = DtoUtils.getEmbedded(systemMappingDto, SysSystemMapping_.objectClass, SysSchemaObjectClassDto.class);
UUID roleSystemId = schemaObjectClassDto.getSystem();
Assert.assertNotNull(roleSystemId);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(roleSystemId);
schemaAttributeFilter.setObjectClassId(schemaObjectClassDto.getId());
SysSchemaAttributeDto schemaAttributeDto = schemaAttributeService.find(schemaAttributeFilter, null).getContent().stream().filter(attribute -> attribute.getName().equalsIgnoreCase("name")).findFirst().orElse(null);
Assert.assertNotNull(schemaAttributeDto);
SysSystemDto roleSystemDto = new SysSystemDto();
roleSystemDto.setId(roleSystemId);
List<SysSystemMappingDto> roleSystemMappings = systemMappingService.findBySystem(roleSystemDto, SystemOperationType.SYNCHRONIZATION, SystemEntityType.ROLE);
Assert.assertNotNull(roleSystemMappings);
Assert.assertEquals(1, roleSystemMappings.size());
SysSystemMappingDto roleMappingDto = roleSystemMappings.get(0);
// Use ACC script "resolveRoleCatalogueUnderMainCatalogue".
IdmScriptFilter scriptFilter = new IdmScriptFilter();
scriptFilter.setCode("resolveRoleCatalogueUnderMainCatalogue");
scriptFilter.setCategory(IdmScriptCategory.TRANSFORM_FROM);
String catalogTransformationScript = null;
IdmScriptDto scriptDto = scriptService.find(scriptFilter, null).getContent().stream().findFirst().orElse(null);
if (scriptDto != null) {
catalogTransformationScript = this.getPluginExecutors().getPluginFor(IdmScriptCategory.TRANSFORM_FROM).generateTemplate(scriptDto);
}
Assert.assertNotNull(catalogTransformationScript);
// Create mapping attribute for get catalog.
SysSystemAttributeMappingDto roleIdAttribute = new SysSystemAttributeMappingDto();
roleIdAttribute.setEntityAttribute(true);
roleIdAttribute.setUid(false);
roleIdAttribute.setSystemMapping(roleMappingDto.getId());
roleIdAttribute.setExtendedAttribute(false);
roleIdAttribute.setIdmPropertyName(RoleSynchronizationExecutor.ROLE_CATALOGUE_FIELD);
roleIdAttribute.setSchemaAttribute(schemaAttributeDto.getId());
roleIdAttribute.setTransformFromResourceScript(catalogTransformationScript);
roleIdAttribute.setName(helper.createName());
roleIdAttribute = attributeMappingService.save(roleIdAttribute);
IdmRoleCatalogueDto parentRoleCatalogue = getHelper().createRoleCatalogue();
IdmRoleCatalogueDto mainRoleCatalogue = getHelper().createRoleCatalogue(getHelper().createName(), parentRoleCatalogue.getId());
// Enable assign of role catalogue.
roleConfigDto.setAssignCatalogueSwitch(true);
roleConfigDto.setRemoveCatalogueRoleSwitch(false);
roleConfigDto.setMainCatalogueRoleNode(mainRoleCatalogue.getId());
roleConfigDto.setRemoveCatalogueRoleParentNode(mainRoleCatalogue.getId());
syncConfigCustom = syncConfigService.save(roleConfigDto);
//
helper.startSynchronization(syncConfigCustom);
//
SysSyncLogFilter logFilter = new SysSyncLogFilter();
logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
Assert.assertEquals(1, logs.size());
SysSyncLogDto log = logs.get(0);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
helper.checkSyncLog(syncConfigCustom, SynchronizationActionType.CREATE_ENTITY, 5, OperationResultType.SUCCESS);
AccRoleAccountFilter roleAccountFilter = new AccRoleAccountFilter();
roleAccountFilter.setSystemId(roleSystemId);
List<AccRoleAccountDto> roleAccountDtos = roleAccountService.find(roleAccountFilter, null).getContent();
Assert.assertEquals(5, roleAccountDtos.size());
roleAccountDtos.forEach(roleAccountDto -> {
UUID roleId = roleAccountDto.getRole();
IdmRoleCatalogueRoleFilter roleCatalogueRoleFilter = new IdmRoleCatalogueRoleFilter();
roleCatalogueRoleFilter.setRoleId(roleId);
List<IdmRoleCatalogueRoleDto> roleCatalogueRoleDtos = roleCatalogueRoleService.find(roleCatalogueRoleFilter, null).getContent();
Assert.assertEquals(1, roleCatalogueRoleDtos.size());
Assert.assertEquals(mainRoleCatalogue.getId(), roleCatalogueRoleDtos.get(0).getRoleCatalogue());
});
roleAccountDtos.forEach(roleAccountDto -> {
UUID roleId = roleAccountDto.getRole();
getHelper().createRoleCatalogueRole(roleService.get(roleId), mainRoleCatalogue);
getHelper().createRoleCatalogueRole(roleService.get(roleId), parentRoleCatalogue);
IdmRoleCatalogueRoleFilter roleCatalogueRoleFilter = new IdmRoleCatalogueRoleFilter();
roleCatalogueRoleFilter.setRoleId(roleId);
List<IdmRoleCatalogueRoleDto> roleCatalogueRoleDtos = roleCatalogueRoleService.find(roleCatalogueRoleFilter, null).getContent();
// The role is in 3 catalogs (one from system, two redundant).
Assert.assertEquals(3, roleCatalogueRoleDtos.size());
Assert.assertEquals(mainRoleCatalogue.getId(), roleCatalogueRoleDtos.get(0).getRoleCatalogue());
});
// Start a sync again. Remove redundant catalogs is not enabled -> Same results.
helper.startSynchronization(syncConfigCustom);
helper.checkSyncLog(syncConfigCustom, SynchronizationActionType.UPDATE_ENTITY, 5, OperationResultType.SUCCESS);
roleAccountDtos.forEach(roleAccountDto -> {
UUID roleId = roleAccountDto.getRole();
IdmRoleCatalogueRoleFilter roleCatalogueRoleFilter = new IdmRoleCatalogueRoleFilter();
roleCatalogueRoleFilter.setRoleId(roleId);
List<IdmRoleCatalogueRoleDto> roleCatalogueRoleDtos = roleCatalogueRoleService.find(roleCatalogueRoleFilter, null).getContent();
// Remove redundant catalogs is not enabled -> Same results: The role is in 3 catalogs (one from system, two redundant).
Assert.assertEquals(3, roleCatalogueRoleDtos.size());
Assert.assertEquals(mainRoleCatalogue.getId(), roleCatalogueRoleDtos.get(0).getRoleCatalogue());
});
roleConfigDto.setRemoveCatalogueRoleSwitch(true);
roleConfigDto.setRemoveCatalogueRoleParentNode(mainRoleCatalogue.getId());
syncConfigCustom = syncConfigService.save(roleConfigDto);
// Start a sync again. Remove redundant catalogs is enabled -> Redundant relation from main catalog should be removed.
helper.startSynchronization(syncConfigCustom);
helper.checkSyncLog(syncConfigCustom, SynchronizationActionType.UPDATE_ENTITY, 5, OperationResultType.SUCCESS);
roleAccountDtos.forEach(roleAccountDto -> {
UUID roleId = roleAccountDto.getRole();
IdmRoleCatalogueRoleFilter roleCatalogueRoleFilter = new IdmRoleCatalogueRoleFilter();
roleCatalogueRoleFilter.setRoleId(roleId);
List<IdmRoleCatalogueRoleDto> roleCatalogueRoleDtos = roleCatalogueRoleService.find(roleCatalogueRoleFilter, null).getContent();
// Remove redundant catalogs is enabled -> Redundant relation from main catalog should be removed: The role is in 2 catalogs (one from system, one redundant).
Assert.assertEquals(2, roleCatalogueRoleDtos.size());
Assert.assertEquals(mainRoleCatalogue.getId(), roleCatalogueRoleDtos.get(0).getRoleCatalogue());
});
roleConfigDto.setRemoveCatalogueRoleSwitch(true);
roleConfigDto.setRemoveCatalogueRoleParentNode(parentRoleCatalogue.getId());
syncConfigCustom = syncConfigService.save(roleConfigDto);
// Start a sync again. Remove redundant catalogs is enabled -> Redundant relation from parent catalog should be removed.
helper.startSynchronization(syncConfigCustom);
helper.checkSyncLog(syncConfigCustom, SynchronizationActionType.UPDATE_ENTITY, 5, OperationResultType.SUCCESS);
roleAccountDtos.forEach(roleAccountDto -> {
UUID roleId = roleAccountDto.getRole();
IdmRoleCatalogueRoleFilter roleCatalogueRoleFilter = new IdmRoleCatalogueRoleFilter();
roleCatalogueRoleFilter.setRoleId(roleId);
List<IdmRoleCatalogueRoleDto> roleCatalogueRoleDtos = roleCatalogueRoleService.find(roleCatalogueRoleFilter, null).getContent();
// Remove redundant catalogs is enabled -> Redundant relation from parent catalog should be removed: The role is in 1 catalog.
Assert.assertEquals(1, roleCatalogueRoleDtos.size());
Assert.assertEquals(mainRoleCatalogue.getId(), roleCatalogueRoleDtos.get(0).getRoleCatalogue());
});
cleanAfterTest(syncConfigCustom, roleSystemId, log, roleAccountDtos);
}
Aggregations