use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultTreeSynchronizationServiceTest method initData.
private void initData() {
// create test system
system = helper.createSystem("test_tree_resource");
system.setName(SYSTEM_NAME);
system = systemService.save(system);
// key to EAV
IdmFormDefinitionDto formDefinition = systemService.getConnectorFormDefinition(system);
formService.saveValues(system, formDefinition, "keyColumn", ImmutableList.of("ID"));
// generate schema for system
List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
IdmTreeTypeDto treeType = new IdmTreeTypeDto();
treeType.setCode(TREE_TYPE_TEST);
treeType.setName(TREE_TYPE_TEST);
treeType = treeTypeService.save(treeType);
// Create synchronization mapping
SysSystemMappingDto syncSystemMapping = new SysSystemMappingDto();
syncSystemMapping.setName("default_" + System.currentTimeMillis());
syncSystemMapping.setEntityType(SystemEntityType.TREE);
syncSystemMapping.setTreeType(treeType.getId());
syncSystemMapping.setOperationType(SystemOperationType.SYNCHRONIZATION);
syncSystemMapping.setObjectClass(objectClasses.get(0).getId());
final SysSystemMappingDto syncMapping = systemMappingService.save(syncSystemMapping);
createMapping(system, syncMapping);
deleteAllResourceData();
initTreeData();
syncConfigService.find(null).getContent().forEach(config -> {
syncConfigService.delete(config);
});
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testAutomaticRoleContractExterneAttributeEnumeration.
@Test
public void testAutomaticRoleContractExterneAttributeEnumeration() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity.getId());
//
IdmFormAttributeDto attribute = new IdmFormAttributeDto();
attribute.setCode(getHelper().createName());
attribute.setName(getHelper().createName());
attribute.setPersistentType(PersistentType.ENUMERATION);
attribute.setFaceType(BaseFaceType.OPERATION_STATE_ENUM);
IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmIdentityContract.class);
attribute = formService.saveAttribute(IdmIdentityContract.class, attribute);
//
IdmRoleDto role = getHelper().createRole();
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, attribute.getCode(), attribute.getId(), "test");
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
//
IdmFormValueDto value = new IdmFormValueDto(attribute);
value.setValue("test");
formService.saveValues(primeContract, formDefinition, Lists.newArrayList(value));
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
//
value.setValue(null);
formService.saveValues(primeContract, formDefinition, Lists.newArrayList(value));
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class AbstractReadWriteDtoControllerRestTest method toFormDefinitions.
/**
* Transform response with embedded dto list to dtos
*
* @param response
* @return
*/
protected List<IdmFormDefinitionDto> toFormDefinitions(String response) {
try {
JsonNode json = getMapper().readTree(response);
// by convention
JsonNode jsonEmbedded = json.get(EmbeddedDto.PROPERTY_EMBEDDED);
JsonNode jsonResources = jsonEmbedded.get(getResourcesName(IdmFormDefinitionDto.class));
//
// convert embedded object to target DTO classes
List<IdmFormDefinitionDto> results = new ArrayList<>();
jsonResources.forEach(jsonResource -> {
results.add(getMapper().convertValue(jsonResource, IdmFormDefinitionDto.class));
});
//
return results;
} catch (Exception ex) {
throw new RuntimeException("Failed to read form definitioons from response [" + response + "]", ex);
}
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class AbstractReadWriteDtoControllerRestTest method testDownloadFormValue.
@Test
public void testDownloadFormValue() throws Exception {
if (!supportsFormValues()) {
LOG.info("Controller [{}] doesn't support extended attributes. Method will not be tested.", getController().getClass());
return;
}
IdmFormAttributeDto formAttribute = new IdmFormAttributeDto(getHelper().createName());
formAttribute.setPersistentType(PersistentType.ATTACHMENT);
IdmFormDefinitionDto formDefinition = formService.createDefinition(getFormOwnerType(), getHelper().createName(), Lists.newArrayList(formAttribute));
formAttribute = formDefinition.getFormAttributes().get(0);
//
DTO owner = createDto();
//
// save value
String content = "text";
IdmAttachmentDto attachment = new IdmAttachmentDto();
UUID owwnerId = UUID.randomUUID();
attachment.setOwnerId(owwnerId);
attachment.setOwnerType(attachmentManager.getOwnerType(IdmFormValueDto.class));
attachment.setName("test.txt");
attachment.setMimetype("text/plain");
attachment.setInputData(IOUtils.toInputStream(content));
attachment = attachmentManager.saveAttachment(owner, attachment);
IdmFormValueDto formValue = new IdmFormValueDto(formAttribute);
formValue.setId(owwnerId);
formValue.setValue(attachment.getId());
IdmFormInstanceDto formInstance = saveFormValue(owner.getId(), TestHelper.ADMIN_USERNAME, formValue);
Assert.assertEquals(owner.getId().toString(), formInstance.getOwnerId());
Assert.assertEquals(formDefinition.getId().toString(), formInstance.getFormDefinition().getId().toString());
Assert.assertEquals(formDefinition.getFormAttributes().get(0).getId().toString(), formInstance.getFormDefinition().getFormAttributes().get(0).getId().toString());
Assert.assertEquals(1, formInstance.getValues().size());
formValue = formInstance.getValues().get(0);
//
// download saved value
String response = getMockMvc().perform(MockMvcRequestBuilders.get(getDownloadFormValuesUrl(owner.getId(), formValue.getId())).with(authentication(getAdminAuthentication()))).andExpect(status().isOk()).andExpect(content().contentType("text/plain")).andReturn().getResponse().getContentAsString();
//
// preview for the text files is not available
getMockMvc().perform(MockMvcRequestBuilders.get(getPreviewFormValuesUrl(owner.getId(), formValue.getId())).with(authentication(getAdminAuthentication()))).andExpect(status().isNoContent());
//
// download is available for the attachment persistent type only
IdmFormAttributeDto formAttributeWrong = new IdmFormAttributeDto(getHelper().createName());
formAttributeWrong.setPersistentType(PersistentType.TEXT);
IdmFormDefinitionDto formDefinitionWrong = formService.createDefinition(getFormOwnerType(), getHelper().createName(), Lists.newArrayList(formAttributeWrong));
formAttributeWrong = formDefinitionWrong.getFormAttributes().get(0);
IdmFormValueDto formValueWrong = new IdmFormValueDto(formAttributeWrong);
formValueWrong.setValue(getHelper().createName());
formInstance = saveFormValue(owner.getId(), TestHelper.ADMIN_USERNAME, formValueWrong);
formValueWrong = formInstance.getValues().get(0);
getMockMvc().perform(MockMvcRequestBuilders.get(getDownloadFormValuesUrl(owner.getId(), formValueWrong.getId())).with(authentication(getAdminAuthentication()))).andExpect(status().isBadRequest());
//
// download is available for the filled attachments
formValue.setValue(null);
saveFormValue(owner.getId(), TestHelper.ADMIN_USERNAME, formValue);
getMockMvc().perform(MockMvcRequestBuilders.get(getDownloadFormValuesUrl(owner.getId(), formValue.getId())).with(authentication(getAdminAuthentication()))).andExpect(status().isNotFound());
//
// entity not found
getMockMvc().perform(MockMvcRequestBuilders.get(getDownloadFormValuesUrl(owner.getId(), UUID.randomUUID())).with(authentication(getAdminAuthentication()))).andExpect(status().isNotFound());
getMockMvc().perform(MockMvcRequestBuilders.get(getDownloadFormValuesUrl(UUID.randomUUID(), formValue.getId())).with(authentication(getAdminAuthentication()))).andExpect(status().isNotFound());
//
Assert.assertEquals(content, response);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class AdUserConnectorType method getConnectorValuesByAttribute.
/**
* Search connector values for given attribute.
* If is system in cross-domain system group, then is will be call this method for all systems in a group.
* For searching in other systems will be used SID, GROUPS and 'foreignSecurityPrincipals' container.
*/
@Override
public List<Object> getConnectorValuesByAttribute(String uid, IcObjectClass objectClass, String schemaAttributeName, SysSystemDto system, IcConnectorObject connectorObject, SysSystemGroupSystemDto systemGroupSystem) {
List<Object> connectorValues = super.getConnectorValuesByAttribute(uid, objectClass, schemaAttributeName, system, connectorObject, systemGroupSystem);
if (systemGroupSystem == null) {
// Find if the system is in a group with cross-domain type and for given schema attribute.
SysSystemGroupSystemFilter systemGroupSystemFilter = new SysSystemGroupSystemFilter();
systemGroupSystemFilter.setGroupType(SystemGroupType.CROSS_DOMAIN);
systemGroupSystemFilter.setDisabled(Boolean.FALSE);
systemGroupSystemFilter.setSystemId(system.getId());
systemGroupSystemFilter.setMergeAttributeCode(schemaAttributeName);
UUID systemGroupId = systemGroupSystemService.find(systemGroupSystemFilter, null).getContent().stream().findFirst().map(SysSystemGroupSystemDto::getSystemGroup).orElse(null);
if (systemGroupId == null) {
// System is not in a cross-domain group -> we have all connector values.
return connectorValues;
}
// Found all group-systems for this group (without given system).
systemGroupSystemFilter.setSystemGroupId(systemGroupId);
systemGroupSystemFilter.setSystemId(null);
List<SysSystemGroupSystemDto> groupSystems = systemGroupSystemService.find(systemGroupSystemFilter, null).getContent().stream().filter(groupSystem -> !system.getId().equals(groupSystem.getSystem())).collect(Collectors.toList());
// Call connector type for every system and load values for given attribute.
groupSystems.forEach(groupSystem -> {
SysSystemDto systemInGroup = DtoUtils.getEmbedded(groupSystem, SysSystemGroupSystem_.system, SysSystemDto.class);
ConnectorType connectorType = getConnectorManager().findConnectorTypeBySystem(systemInGroup);
if (connectorType != null) {
List<Object> connectorValuesForSystemInGroup = connectorType.getConnectorValuesByAttribute(uid, objectClass, schemaAttributeName, systemInGroup, connectorObject, groupSystem);
if (connectorValuesForSystemInGroup != null) {
connectorValuesForSystemInGroup.forEach(value -> {
if (!connectorValues.contains(value)) {
connectorValues.add(value);
}
});
}
}
});
} else {
// System group is not null, so this is sub system in group. We need to get groups by SID.
Assert.notNull(connectorObject, "The parent connector object cannot be null!");
IcAttribute sid = connectorObject.getAttributeByName(SID_ATTRIBUTE_KEY);
Assert.notNull(sid, "SID attribute cannot be null!");
Object sidValue = sid.getValue();
Assert.notNull(sidValue, "SID value cannot be null!");
IdmFormDefinitionDto operationOptionsFormDefinition = this.getSystemService().getOperationOptionsConnectorFormDefinition(system);
Assert.notNull(operationOptionsFormDefinition, "Operation options form-definition cannot be null!");
// Find attribute with container with existed users.
String userContainer = getValueFromConnectorInstance(USER_SEARCH_CONTAINER_KEY, system, operationOptionsFormDefinition);
Assert.notNull(userContainer, "User container cannot be null!");
// First we have to find root DN (only DCs).
String dcs = getRoot(userContainer);
String foreignSecurityPrincipalsDN = MessageFormat.format("CN={0},CN={1},{2}", convertSidToStr((byte[]) sidValue), FOREIGN_SECURITY_PRINCIPALS_CN, dcs);
IcConnectorConfiguration connectorConfiguration = getSystemService().getConnectorConfiguration(system);
IcConnectorInstance connectorInstance = getSystemService().getConnectorInstance(system);
Set<String> groups = searchGroups("member", connectorConfiguration, connectorInstance, foreignSecurityPrincipalsDN);
connectorValues.addAll(groups);
}
return connectorValues;
}
Aggregations