use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto in project CzechIdMng by bcvsolutions.
the class ProvisioningOperationReportIntegrationTest method testProvisioningOperationReportMultivalued.
@Test
public void testProvisioningOperationReportMultivalued() throws Exception {
LdapServer server = new LdapServer();
server.run();
SysSystemDto system = ldapTestHelper.createTestResourceSystem(true, "ldap_test" + System.currentTimeMillis());
// create provisioning operation
// TODO: now is DN stored as username, create script in mapping that will composed the final dn
IdmIdentityDto identity = getHelper().createIdentity(LdapServer.generateDn("test-" + System.currentTimeMillis()));
IdmRoleDto role = getHelper().createRole();
getHelper().createRoleSystem(role, system);
getHelper().createIdentityRole(identity, role);
//
AccAccountFilter filter = new AccAccountFilter();
filter.setIdentityId(identity.getId());
filter.setSystemId(system.getId());
List<AccAccountDto> accounts = accountService.find(filter, null).getContent();
assertEquals(1, accounts.size());
SysProvisioningOperationFilter provisioningFilter = new SysProvisioningOperationFilter();
provisioningFilter.setEntityIdentifier(identity.getId());
List<SysProvisioningOperationDto> operations = provisioningOperationService.find(provisioningFilter, null).getContent();
assertTrue(operations.isEmpty());
boolean existsEntityByDn = server.existsEntityByDn(identity.getUsername());
assertTrue(existsEntityByDn);
// Set read only to system
system.setReadonly(true);
system = systemService.save(system);
IdmRoleDto roleWithMerge = getHelper().createRole();
SysRoleSystemDto createRoleSystem = getHelper().createRoleSystem(roleWithMerge, system);
ldapTestHelper.createMergeAttributeForRole(system, createRoleSystem, LdapServer.GROUP_A_DN);
getHelper().createIdentityRole(identity, roleWithMerge);
operations = provisioningOperationService.find(provisioningFilter, null).getContent();
assertFalse(operations.isEmpty());
// prepare report filter
RptReportDto report = new RptReportDto(UUID.randomUUID());
report.setExecutorName(reportExecutor.getName());
IdmFormDto filterForm = new IdmFormDto();
IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
IdmFormValueDto systemFilter = new IdmFormValueDto(definition.getMappedAttributeByCode(ProvisioningOperationReportExecutor.PARAMETER_SYSTEM));
systemFilter.setUuidValue(system.getId());
filterForm.getValues().add(systemFilter);
filterForm.setFormDefinition(definition.getId());
report.setFilter(filterForm);
//
// generate report
report = reportExecutor.generate(report);
Assert.assertNotNull(report.getData());
List<RptProvisioningOperationDto> reportItems = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<RptProvisioningOperationDto>>() {
});
assertEquals(1, reportItems.size());
RptProvisioningOperationDto rptProvisioningOperationDto = reportItems.get(0);
String value = rptProvisioningOperationDto.getProvisioningValues().get(LdapTestHelper.ATTRIBUTE_MAPPING_MEMBER_OF);
assertEquals(LdapServer.GROUP_A_DN, value);
server.stop();
}
use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto in project CzechIdMng by bcvsolutions.
the class DefaultAccTestHelper method createRoleSystem.
@Override
public SysRoleSystemDto createRoleSystem(IdmRoleDto role, SysSystemDto system) {
SysRoleSystemDto roleSystem = new SysRoleSystemDto();
roleSystem.setRole(role.getId());
roleSystem.setSystem(system.getId());
// default mapping
List<SysSystemMappingDto> mappings = systemMappingService.findBySystem(system, SystemOperationType.PROVISIONING, SystemEntityType.IDENTITY);
// required ...
roleSystem.setSystemMapping(mappings.get(0).getId());
//
return roleSystemService.save(roleSystem);
}
use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemServiceTest method testReferentialIntegrity.
@Test
public void testReferentialIntegrity() {
SysSystemDto system = new SysSystemDto();
String systemName = "t_s_" + System.currentTimeMillis();
system.setName(systemName);
system = systemService.save(system);
// object class
SysSchemaObjectClassDto objectClass = new SysSchemaObjectClassDto();
objectClass.setSystem(system.getId());
objectClass.setObjectClassName("obj_class");
objectClass = schemaObjectClassService.save(objectClass);
SysSchemaObjectClassFilter objectClassFilter = new SysSchemaObjectClassFilter();
objectClassFilter.setSystemId(system.getId());
// schema attribute
SysSchemaAttributeDto schemaAttribute = new SysSchemaAttributeDto();
schemaAttribute.setObjectClass(objectClass.getId());
schemaAttribute.setName("name");
schemaAttribute.setClassType("class");
schemaAttribute = schemaAttributeService.save(schemaAttribute);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
// system entity handling
SysSystemMappingDto systemMapping = new SysSystemMappingDto();
systemMapping.setName("default_" + System.currentTimeMillis());
systemMapping.setObjectClass(objectClass.getId());
systemMapping.setOperationType(SystemOperationType.PROVISIONING);
systemMapping.setEntityType(SystemEntityType.IDENTITY);
systemMapping = systemMappingService.save(systemMapping);
SysSystemMappingFilter entityHandlingFilter = new SysSystemMappingFilter();
entityHandlingFilter.setSystemId(system.getId());
// schema attribute handling
SysSystemAttributeMappingDto schemaAttributeHandling = new SysSystemAttributeMappingDto();
schemaAttributeHandling.setSchemaAttribute(schemaAttribute.getId());
schemaAttributeHandling.setSystemMapping(systemMapping.getId());
schemaAttributeHandling.setName("name");
schemaAttributeHandling.setIdmPropertyName("name");
schemaAttributeHandling = systemAttributeMappingService.save(schemaAttributeHandling);
SysSystemAttributeMappingFilter schemaAttributeHandlingFilter = new SysSystemAttributeMappingFilter();
schemaAttributeHandlingFilter.setSystemId(system.getId());
// role system
IdmRoleDto role = helper.createRole();
SysRoleSystemDto roleSystem = new SysRoleSystemDto();
roleSystem.setSystem(system.getId());
roleSystem.setRole(role.getId());
roleSystem.setSystemMapping(systemMapping.getId());
roleSystem = roleSystemService.save(roleSystem);
SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
roleSystemFilter.setRoleId(role.getId());
// role system attributes
SysRoleSystemAttributeDto roleSystemAttribute = new SysRoleSystemAttributeDto();
roleSystemAttribute.setRoleSystem(roleSystem.getId());
roleSystemAttribute.setSystemAttributeMapping(schemaAttributeHandling.getId());
roleSystemAttribute.setName("name");
roleSystemAttribute.setIdmPropertyName("name");
roleSystemAttribute = roleSystemAttributeService.save(roleSystemAttribute);
assertEquals(systemName, systemService.getByCode(systemName).getName());
assertEquals(1, schemaObjectClassService.find(objectClassFilter, null).getTotalElements());
assertEquals(1, schemaAttributeService.find(schemaAttributeFilter, null).getTotalElements());
assertEquals(1, systemMappingService.find(entityHandlingFilter, null).getTotalElements());
assertEquals(1, systemAttributeMappingService.find(schemaAttributeHandlingFilter, null).getTotalElements());
assertEquals(1, roleSystemService.find(roleSystemFilter, null).getTotalElements());
assertNotNull(roleSystemAttributeService.get(roleSystemAttribute.getId()));
systemService.delete(system);
assertNull(systemService.getByCode(systemName));
assertEquals(0, schemaObjectClassService.find(objectClassFilter, null).getTotalElements());
assertEquals(0, schemaAttributeService.find(schemaAttributeFilter, null).getTotalElements());
assertEquals(0, systemMappingService.find(entityHandlingFilter, null).getTotalElements());
assertEquals(0, systemAttributeMappingService.find(schemaAttributeHandlingFilter, null).getTotalElements());
assertEquals(0, roleSystemService.find(roleSystemFilter, null).getTotalElements());
assertNull(roleSystemAttributeService.get(roleSystemAttribute.getId()));
}
use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountManagementService method createAccountByRoleSystem.
/**
* Create Account by given roleSystem
*
* @param identity
* @param roleSystem
* @param identityAccountsToCreate
* @return
*/
private UUID createAccountByRoleSystem(IdmIdentityDto identity, SysRoleSystemDto roleSystem, List<AccIdentityAccountDto> identityAccountsToCreate) {
String uid = generateUID(identity, roleSystem);
// We try find account for same uid on same system
// First we try search same account in list for create new accounts
Optional<AccIdentityAccountDto> sameAccountOptional = identityAccountsToCreate.stream().filter(ia -> {
AccAccountDto account = accountService.get(ia.getAccount());
return account.getUid().equals(uid) && roleSystem.getId().equals(ia.getRoleSystem());
}).findFirst();
if (sameAccountOptional.isPresent()) {
return sameAccountOptional.get().getAccount();
}
UUID accountId = null;
// If account is not in the list accounts to create, then we will search in
// database
// Account management - can be the account created? - execute the script on the
// system mapping
SysSystemDto system = DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.system, SysSystemDto.class);
SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(system.getId(), SystemEntityType.IDENTITY);
if (mapping == null) {
return null;
}
if (!this.canBeAccountCreated(uid, identity, mapping, system)) {
LOG.info(MessageFormat.format("For entity [{0}] and entity type [{1}] cannot be created the account (on system [{2}])," + " because script \"Can be account created\" on the mapping returned \"false\"!", identity.getCode(), SystemEntityType.IDENTITY, system.getName()));
return null;
}
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setUid(uid);
accountFilter.setSystemId(roleSystem.getSystem());
List<AccAccountDto> sameAccounts = accountService.find(accountFilter, null).getContent();
if (CollectionUtils.isEmpty(sameAccounts)) {
// Create and persist new account
accountId = createAccount(uid, roleSystem);
} else {
// We use existed account
accountId = sameAccounts.get(0).getId();
}
return accountId;
}
use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountManagementService method resolveIdentityAccountForCreate.
/**
* Resolve Identity account - to create
*
* @param identity
* @param identityAccountList
* @param identityRoles
* @param identityAccountsToCreate
* @param identityAccountsToDelete
* @param resolvedRolesForCreate
*/
private void resolveIdentityAccountForCreate(IdmIdentityDto identity, List<AccIdentityAccountDto> identityAccountList, List<IdmIdentityRole> identityRoles, List<AccIdentityAccountDto> identityAccountsToCreate, List<AccIdentityAccountDto> identityAccountsToDelete) {
// Is role valid in this moment
identityRoles.stream().filter(identityRole -> {
return identityRole.isValid();
}).forEach(identityRole -> {
IdmRole role = identityRole.getRole();
SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
roleSystemFilter.setRoleId(role.getId());
List<SysRoleSystemDto> roleSystems = roleSystemService.find(roleSystemFilter, null).getContent();
roleSystems.stream().filter(roleSystem -> {
// Filter out identity-accounts for same role-system, account (by UID)
return !identityAccountList.stream().filter(identityAccount -> {
if (roleSystem.getId().equals(identityAccount.getRoleSystem())) {
// Has identity account same uid as account?
String uid = generateUID(identity, roleSystem);
AccAccountDto account = AccIdentityAccountService.getEmbeddedAccount(identityAccount);
if (!uid.equals(account.getUid())) {
// We found identityAccount for same identity and roleSystem, but this
// identityAccount
// is link to Account with different UID. It's probably means definition of UID
// (transformation)\
// on roleSystem was changed. We have to delete this identityAccount.
identityAccountsToDelete.add(identityAccount);
}
}
return false;
}).findFirst().isPresent();
}).forEach(roleSystem -> {
// For this system we have to create new account
UUID accountId = createAccountByRoleSystem(identity, roleSystem, identityAccountsToCreate);
if (accountId == null) {
return;
}
// TODO: find the better place for this check
if (identityAccountList.stream().filter(identityAccount -> {
return identityAccount.getAccount().equals(accountId) && identityRole.getId().equals(identityAccount.getIdentityRole()) && roleSystem.getId().equals(identityAccount.getRoleSystem());
}).count() == 0) {
AccIdentityAccountDto identityAccount = new AccIdentityAccountDto();
identityAccount.setAccount(accountId);
identityAccount.setIdentity(identity.getId());
identityAccount.setIdentityRole(identityRole.getId());
identityAccount.setRoleSystem(roleSystem.getId());
// TODO: Add flag ownership to SystemRole and set here.
identityAccount.setOwnership(true);
identityAccountsToCreate.add(identityAccount);
}
});
});
}
Aggregations