use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningTest method testIdentityState.
@Test
public void testIdentityState() {
SysSystemDto systemDto = helper.createTestResourceSystem(true);
SysSystemMappingDto defaultMapping = helper.getDefaultMapping(systemDto);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(systemDto.getId());
List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
SysSchemaAttributeDto descriptionSchemaAttribute = schemaAttributes.stream().filter(attribute -> TestHelper.ATTRIBUTE_MAPPING_DESCRIPTION.equalsIgnoreCase(attribute.getName())).findFirst().get();
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setUid(false);
attributeMapping.setEntityAttribute(true);
attributeMapping.setIdmPropertyName(IdentityProvisioningExecutor.IDENTITY_STATE_IDM_NAME);
attributeMapping.setName(descriptionSchemaAttribute.getName());
attributeMapping.setSchemaAttribute(descriptionSchemaAttribute.getId());
attributeMapping.setSystemMapping(defaultMapping.getId());
attributeMapping = schemaAttributeMappingService.save(attributeMapping);
IdmRoleDto roleWithSystem = helper.createRole();
helper.createRoleSystem(roleWithSystem, systemDto);
IdmIdentityDto identity = helper.createIdentity();
helper.createIdentityRole(identity, roleWithSystem, null, null);
// the default state after identity creation
TestResource resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
String valueOnResource = resource.getDescrip();
Assert.assertEquals(IdentityState.VALID.toString(), valueOnResource);
// the identity state is changed manually
identity.setState(IdentityState.DISABLED);
identityService.save(identity);
resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
valueOnResource = resource.getDescrip();
Assert.assertEquals(IdentityState.DISABLED.toString(), valueOnResource);
// test transformation still works
attributeMapping.setTransformToResourceScript("return \"DELIBERATE_NONSENSE\";");
attributeMapping = schemaAttributeMappingService.save(attributeMapping);
identity.setState(IdentityState.LEFT);
identityService.save(identity);
resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
valueOnResource = resource.getDescrip();
Assert.assertEquals("DELIBERATE_NONSENSE", valueOnResource);
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningTest method testUserType.
@Test
public void testUserType() {
SysSystemDto systemDto = helper.createTestResourceSystem(true);
SysSystemMappingDto defaultMapping = helper.getDefaultMapping(systemDto);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(systemDto.getId());
List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
SysSchemaAttributeDto descriptionSchemaAttribute = schemaAttributes.stream().filter(attribute -> TestHelper.ATTRIBUTE_MAPPING_DESCRIPTION.equalsIgnoreCase(attribute.getName())).findFirst().get();
SysSystemAttributeMappingDto attributeAssignedRoles = new SysSystemAttributeMappingDto();
attributeAssignedRoles.setUid(false);
attributeAssignedRoles.setEntityAttribute(true);
attributeAssignedRoles.setIdmPropertyName(IdmIdentity_.formProjection.getName());
attributeAssignedRoles.setTransformToResourceScript("if(attributeValue != null) " + System.lineSeparator() + "{return attributeValue.getCode();}");
attributeAssignedRoles.setName(descriptionSchemaAttribute.getName());
attributeAssignedRoles.setSchemaAttribute(descriptionSchemaAttribute.getId());
attributeAssignedRoles.setSystemMapping(defaultMapping.getId());
schemaAttributeMappingService.save(attributeAssignedRoles);
IdmRoleDto roleWithSystem = helper.createRole();
helper.createRoleSystem(roleWithSystem, systemDto);
IdmIdentityDto identity = helper.createIdentity();
// Create projection
IdmFormProjectionDto projection = new IdmFormProjectionDto();
projection.setOwnerType(IdmIdentity.class.getCanonicalName());
projection.setCode(getHelper().createName());
projection.setDisabled(false);
projection = formProjectionService.save(projection);
// Set projection to the identity
identity.setFormProjection(projection.getId());
identity = identityService.save(identity);
// Execute provisioning
helper.createIdentityRole(identity, roleWithSystem, null, null);
TestResource resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
String valueOnResource = resource.getDescrip();
// Code of the projection must be on target system.
assertEquals(projection.getCode(), valueOnResource);
// Delete projection.
formProjectionService.delete(projection);
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningTest method testAssignedRoles.
@Test
public void testAssignedRoles() {
SysSystemDto systemDto = helper.createTestResourceSystem(true);
SysSystemMappingDto defaultMapping = helper.getDefaultMapping(systemDto);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(systemDto.getId());
List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
SysSchemaAttributeDto descriptionSchemaAttribute = schemaAttributes.stream().filter(attribute -> TestHelper.ATTRIBUTE_MAPPING_DESCRIPTION.equalsIgnoreCase(attribute.getName())).findFirst().get();
SysSystemAttributeMappingDto attributeAssignedRoles = new SysSystemAttributeMappingDto();
attributeAssignedRoles.setUid(false);
attributeAssignedRoles.setEntityAttribute(true);
attributeAssignedRoles.setIdmPropertyName(IdentityProvisioningExecutor.ASSIGNED_ROLES_FIELD);
attributeAssignedRoles.setTransformToResourceScript("if(attributeValue == null) " + System.lineSeparator() + "{return null;}" + System.lineSeparator() + " String result = '';" + System.lineSeparator() + " for(Object assignedRole : attributeValue)" + System.lineSeparator() + " {result = result + (assignedRole.toString())};" + System.lineSeparator() + " return result;");
attributeAssignedRoles.setName(descriptionSchemaAttribute.getName());
attributeAssignedRoles.setSchemaAttribute(descriptionSchemaAttribute.getId());
attributeAssignedRoles.setSystemMapping(defaultMapping.getId());
schemaAttributeMappingService.save(attributeAssignedRoles);
IdmRoleDto roleWithSystem = helper.createRole();
IdmRoleDto roleWithOutSystem = helper.createRole();
helper.createRoleSystem(roleWithSystem, systemDto);
IdmIdentityDto identity = helper.createIdentity();
helper.createIdentityRole(identity, roleWithOutSystem, null, null);
helper.createIdentityRole(identity, roleWithSystem, null, null);
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identity.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmIdentityRole_.created.getName()))).getContent();
TestResource resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
String valueOnResource = resource.getDescrip();
String result = "";
for (IdmIdentityRoleDto identityRole : identityRoles) {
IdmFormInstanceDto formInstanceDto = identityRoleService.getRoleAttributeValues(identityRole);
identityRole.getEavs().clear();
identityRole.getEavs().add(formInstanceDto);
result = result + IdentityProvisioningExecutor.convertToAssignedRoleDto(identityRole).toString();
}
assertEquals(result, valueOnResource);
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class PerformanceAccountManagementTest method createIdentityMapping.
private void createIdentityMapping(SysSystemDto system, final SysSystemMappingDto entityHandlingResult) {
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
Page<SysSchemaAttributeDto> schemaAttributesPage = schemaAttributeService.find(schemaAttributeFilter, null);
schemaAttributesPage.forEach(schemaAttr -> {
if (ATTRIBUTE_NAME.equals(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setUid(true);
attributeMapping.setEntityAttribute(true);
attributeMapping.setIdmPropertyName("username");
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(entityHandlingResult.getId());
schemaAttributeMappingService.save(attributeMapping);
} else if ("firstname".equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName("firstName");
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSystemMapping(entityHandlingResult.getId());
schemaAttributeMappingService.save(attributeMapping);
} else if ("lastname".equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName("lastName");
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(entityHandlingResult.getId());
schemaAttributeMappingService.save(attributeMapping);
} else if (ATTRIBUTE_EMAIL.equalsIgnoreCase(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setIdmPropertyName("email");
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(entityHandlingResult.getId());
schemaAttributeMappingService.save(attributeMapping);
}
});
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class MappingContextTest method createDescriptionAttribute.
private void createDescriptionAttribute(SysSystemDto system, SysSystemMappingDto mapping) {
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
schemaAttributeFilter.setName(TestHelper.ATTRIBUTE_MAPPING_DESCRIPTION);
SysSchemaAttributeDto descriptionSchemaAttribute = schemaAttributeService.find(schemaAttributeFilter, null).getContent().get(0);
Assert.assertNotNull(descriptionSchemaAttribute);
SysSystemAttributeMappingDto descriptionAttribute = new SysSystemAttributeMappingDto();
descriptionAttribute.setUid(false);
descriptionAttribute.setEntityAttribute(false);
descriptionAttribute.setName(descriptionSchemaAttribute.getName());
descriptionAttribute.setSchemaAttribute(descriptionSchemaAttribute.getId());
descriptionAttribute.setSystemMapping(mapping.getId());
descriptionAttribute.setTransformToResourceScript("return context.toString();");
descriptionAttribute = attributeMappingService.save(descriptionAttribute);
}
Aggregations