use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningArchiveService method evaluateProvisioningDifferences.
@Override
public List<SysAttributeDifferenceDto> evaluateProvisioningDifferences(IcConnectorObject current, IcConnectorObject changed) {
List<SysAttributeDifferenceDto> resultAttributes = new ArrayList<>();
IcConnectorObject currentObject = current != null ? current : new IcConnectorObjectImpl();
IcConnectorObject changedObject = changed != null ? changed : new IcConnectorObjectImpl();
List<IcAttribute> currentAttributes = currentObject.getAttributes();
List<IcAttribute> changedAttributes = changedObject.getAttributes();
changedAttributes.forEach(changedAttribute -> {
if (currentObject.getAttributeByName(changedAttribute.getName()) == null) {
SysAttributeDifferenceDto vsAttribute = new SysAttributeDifferenceDto(changedAttribute.getName(), changedAttribute.isMultiValue(), true);
if (changedAttribute.isMultiValue()) {
if (changedAttribute.getValues() != null) {
changedAttribute.getValues().forEach(value -> {
vsAttribute.getValues().add(new SysAttributeDifferenceValueDto(value, null, SysValueChangeType.ADDED));
});
}
} else {
vsAttribute.setValue(new SysAttributeDifferenceValueDto(changedAttribute.getValue(), null, SysValueChangeType.ADDED));
}
resultAttributes.add(vsAttribute);
}
});
// Second add all already existing attributes
currentAttributes.forEach(currentAttribute -> {
SysAttributeDifferenceDto vsAttribute;
// Attribute was changed
if (changedObject.getAttributeByName(currentAttribute.getName()) != null) {
IcAttribute changedAttribute = changedObject.getAttributeByName(currentAttribute.getName());
boolean isMultivalue = isIcAttributeMultivalue(currentAttribute, changedAttribute);
vsAttribute = new SysAttributeDifferenceDto(currentAttribute.getName(), isMultivalue, true);
if (isMultivalue) {
vsAttribute.setChanged(false);
if (changedAttribute.getValues() != null) {
changedAttribute.getValues().forEach(value -> {
if (currentAttribute.getValues() != null && currentAttribute.getValues().contains(value)) {
vsAttribute.getValues().add(new SysAttributeDifferenceValueDto(value, value, null));
} else {
vsAttribute.setChanged(true);
vsAttribute.getValues().add(new SysAttributeDifferenceValueDto(value, null, SysValueChangeType.ADDED));
}
});
}
if (currentAttribute.getValues() != null) {
currentAttribute.getValues().forEach(value -> {
if (changedAttribute.getValues() == null || !changedAttribute.getValues().contains(value)) {
vsAttribute.setChanged(true);
vsAttribute.getValues().add(new SysAttributeDifferenceValueDto(value, value, SysValueChangeType.REMOVED));
}
});
}
} else {
Object changedValue = changedAttribute.getValue();
Object currentValue = currentAttribute.getValue();
if ((changedValue == null && currentValue == null) || (changedValue != null && changedValue.equals(currentValue)) || (currentValue != null && currentValue.equals(changedValue))) {
vsAttribute.setValue(new SysAttributeDifferenceValueDto(changedValue, currentValue, null));
} else {
vsAttribute.setValue(new SysAttributeDifferenceValueDto(changedValue, currentValue, SysValueChangeType.UPDATED));
}
}
} else {
// Attribute was not changed
boolean isMultivalue = isIcAttributeMultivalue(currentAttribute, null);
vsAttribute = new SysAttributeDifferenceDto(currentAttribute.getName(), isMultivalue, false);
if (isMultivalue) {
if (currentAttribute.getValues() != null) {
currentAttribute.getValues().forEach(value -> {
vsAttribute.getValues().add(new SysAttributeDifferenceValueDto(value, value, null));
});
}
} else {
vsAttribute.setValue(new SysAttributeDifferenceValueDto(currentAttribute.getValue(), currentAttribute.getValue(), null));
}
}
resultAttributes.add(vsAttribute);
});
return resultAttributes;
}
use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningArchiveServiceIntegrationTest method differenceObjectMultipleTest.
@Test
public void differenceObjectMultipleTest() {
String attrName = getHelper().createName();
IcAttributeImpl icAttributeOne = new IcAttributeImpl(attrName, Lists.newArrayList("TESTExisting", "TESTRemoved"));
IcConnectorObject connObjectOld = new IcConnectorObjectImpl(getHelper().createName(), new IcObjectClassImpl("__mock__"), ImmutableList.of(icAttributeOne));
IcAttributeImpl icAttributeTwo = new IcAttributeImpl(attrName, Lists.newArrayList("TESTExisting", "TESTNew"));
IcConnectorObject connObjectNew = new IcConnectorObjectImpl(getHelper().createName(), new IcObjectClassImpl("__mock__"), ImmutableList.of(icAttributeTwo));
List<SysAttributeDifferenceDto> diffs = service.evaluateProvisioningDifferences(connObjectOld, connObjectNew);
List<SysAttributeDifferenceValueDto> values = diffs.get(0).getValues();
Assert.assertEquals(1, diffs.size());
Assert.assertTrue(diffs.get(0).isMultivalue());
Assert.assertTrue(diffs.get(0).isChanged());
Assert.assertNotNull(values);
Assert.assertEquals(3, values.size());
SysAttributeDifferenceValueDto value;
value = values.stream().filter(item -> item.getChange() == null).findFirst().orElse(null);
Assert.assertNotNull(value);
Assert.assertEquals("TESTExisting", value.getValue());
Assert.assertEquals("TESTExisting", value.getOldValue());
value = values.stream().filter(item -> item.getChange() == SysValueChangeType.ADDED).findFirst().orElse(null);
Assert.assertNotNull(value);
Assert.assertEquals("TESTNew", value.getValue());
Assert.assertEquals(null, value.getOldValue());
value = values.stream().filter(item -> item.getChange() == SysValueChangeType.REMOVED).findFirst().orElse(null);
Assert.assertNotNull(value);
Assert.assertEquals("TESTRemoved", value.getValue());
Assert.assertEquals("TESTRemoved", value.getOldValue());
}
use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto in project CzechIdMng by bcvsolutions.
the class SysProvisioningArchiveController method getDifferenceObject.
@ResponseBody
@RequestMapping(value = "/{backendId}/difference-object", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + AccGroupPermission.PROVISIONING_ARCHIVE_READ + "')")
@ApiOperation(value = "Detail of the provisioning changes", nickname = "getProvisioningDetail", tags = { SysProvisioningArchiveController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.PROVISIONING_ARCHIVE_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.PROVISIONING_ARCHIVE_READ, description = "") }) })
public ResponseEntity<?> getDifferenceObject(@ApiParam(value = "Provisioning detail uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
SysProvisioningArchiveDto archive = getDto(backendId);
if (archive == null) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
ProvisioningContext context = archive.getProvisioningContext();
if (context == null) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
List<SysAttributeDifferenceDto> result = ((SysProvisioningArchiveService) getService()).evaluateProvisioningDifferences(context.getSystemConnectorObject(), context.getConnectorObject());
return new ResponseEntity<>(result, HttpStatus.OK);
}
use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto in project CzechIdMng by bcvsolutions.
the class DefaultVsRequestService method getWishConnectorObject.
@Override
public VsConnectorObjectDto getWishConnectorObject(VsRequestDto request) {
LOG.info(MessageFormat.format("Start read wish connector object [{0}].", request));
Assert.notNull(request, "VS request cannot be null!");
List<SysAttributeDifferenceDto> resultAttributes;
IcConnectorObject realConnectorObject = null;
boolean isArchived = VsRequestState.REALIZED == request.getState() || VsRequestState.CANCELED == request.getState() || VsRequestState.DUPLICATED == request.getState() || VsRequestState.REJECTED == request.getState();
// only changes.
if (!isArchived) {
realConnectorObject = this.getVsConnectorObject(request);
}
IcConnectorObject currentObject = realConnectorObject != null ? realConnectorObject : new IcConnectorObjectImpl();
IcConnectorObject changeObject = request.getConnectorObject() != null ? request.getConnectorObject() : new IcConnectorObjectImpl();
resultAttributes = provisioningArchiveService.evaluateProvisioningDifferences(currentObject, changeObject);
BasicVirtualConfiguration configuration = getVirtualConnector(request).getVirtualConfiguration();
// result list
if (!configuration.isDisableSupported()) {
resultAttributes.stream().filter(attribute -> IcAttributeInfo.ENABLE.equals(attribute.getName())).findFirst().ifPresent(resultAttributes::remove);
}
VsConnectorObjectDto wishObject = new VsConnectorObjectDto();
wishObject.setUid(request.getUid());
wishObject.setAttributes(resultAttributes);
return wishObject;
}
use of eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto in project CzechIdMng by bcvsolutions.
the class DefaultVsRequestServiceIntegrationTest method checkMultivalueInWishObjectTest.
@Test
public void checkMultivalueInWishObjectTest() {
String ldapGroupsName = "ldapGroups";
String changed = "changed";
List<String> attributes = new ArrayList<>(Lists.newArrayList(BasicVirtualConfiguration.DEFAULT_ATTRIBUTES));
attributes.add(ldapGroupsName);
// Create virtual system with extra attribute (ldapGroups)
SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, attributes);
// Search attribute definition for ldapGroups and set him to multivalue
String virtualSystemKey = MessageFormat.format("{0}:systemId={1}", system.getConnectorKey().getFullName(), system.getId().toString());
String type = VsAccount.class.getName();
IdmFormDefinitionDto definition = this.formService.getDefinition(type, virtualSystemKey);
IdmFormAttributeDto ldapGroupsFormAttr = formAttributeService.findAttribute(VsAccount.class.getName(), definition.getCode(), ldapGroupsName);
Assert.assertNotNull("Ldap attribute muste exist!", ldapGroupsFormAttr);
ldapGroupsFormAttr.setMultiple(true);
// Change the name of this attribute. We want to check that logic no depends on the attribute name.
ldapGroupsFormAttr.setName(helper.createName());
formService.saveAttribute(ldapGroupsFormAttr);
// Generate schema for system (we need propagate multivalue setting)
SysSchemaObjectClassDto schema = systemService.generateSchema(system).get(0);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
SysSystemMappingFilter systemMappingFilter = new SysSystemMappingFilter();
systemMappingFilter.setSystemId(system.getId());
systemMappingFilter.setObjectClassId(schema.getId());
SysSystemMappingDto mapping = systemMappingService.find(systemMappingFilter, null).getContent().get(0);
for (SysSchemaAttributeDto schemaAttr : schemaAttributes) {
if (ldapGroupsName.equals(schemaAttr.getName())) {
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
attributeMapping.setUid(false);
attributeMapping.setEntityAttribute(false);
attributeMapping.setExtendedAttribute(true);
attributeMapping.setIdmPropertyName(ldapGroupsName);
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(mapping.getId());
systemAttributeMappingService.save(attributeMapping);
}
}
IdmIdentityDto userOne = helper.createIdentity(USER_ONE_NAME);
List<Serializable> initList = ImmutableList.of("TEST1", "TEST2", "TEST3");
formService.saveValues(userOne, ldapGroupsName, initList);
this.assignRoleSystem(system, userOne, ROLE_ONE_NAME);
// Find created requests
VsRequestFilter requestFilter = new VsRequestFilter();
requestFilter.setSystemId(system.getId());
requestFilter.setUid(USER_ONE_NAME);
List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
Assert.assertEquals(1, requests.size());
VsRequestDto createRequest = requests.get(0);
Assert.assertEquals(USER_ONE_NAME, createRequest.getUid());
Assert.assertEquals(VsOperationType.CREATE, createRequest.getOperationType());
Assert.assertEquals(VsRequestState.IN_PROGRESS, createRequest.getState());
VsConnectorObjectDto wish = requestService.getWishConnectorObject(createRequest);
boolean findAttributeWithouChange = wish.getAttributes().stream().filter(attribute -> !attribute.isChanged()).findFirst().isPresent();
Assert.assertTrue(!findAttributeWithouChange);
// Check on exist ldapGroups attribute with three values
SysAttributeDifferenceDto ldapGroupAttribute = wish.getAttributes().stream().filter(attribute -> ldapGroupsName.equals(attribute.getName())).findFirst().get();
Assert.assertTrue(ldapGroupAttribute.isMultivalue());
Assert.assertEquals(3, ldapGroupAttribute.getValues().size());
// Change multivalue attribute
List<Serializable> changeList = ImmutableList.of("TEST1", changed, "TEST3");
formService.saveValues(userOne, ldapGroupsName, changeList);
// Invoke provisioning
identityService.save(userOne);
requests = requestService.find(requestFilter, null).getContent();
Assert.assertEquals(2, requests.size());
VsRequestDto changeRequest = requests.stream().filter(req -> VsOperationType.UPDATE == req.getOperationType()).findFirst().get();
wish = requestService.getWishConnectorObject(changeRequest);
ldapGroupAttribute = wish.getAttributes().stream().filter(attribute -> ldapGroupsName.equals(attribute.getName())).findFirst().get();
Assert.assertTrue(ldapGroupAttribute.isMultivalue());
// Wish must contains three values (all add) ... because previous create
// request is not realize yet. Wish show changes versus reals state in
// VsAccount.
Assert.assertEquals(3, ldapGroupAttribute.getValues().size());
// We realize the create request
super.logout();
loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
requestService.realize(createRequest);
// Refresh wish
wish = requestService.getWishConnectorObject(changeRequest);
ldapGroupAttribute = wish.getAttributes().stream().filter(attribute -> ldapGroupsName.equals(attribute.getName())).findFirst().get();
Assert.assertTrue(ldapGroupAttribute.isMultivalue());
// Wish must contains four values ... two without change, one delete and
// one add value
Assert.assertEquals(4, ldapGroupAttribute.getValues().size());
// Find unchanged value
boolean findCorrectTest1Value = ldapGroupAttribute.getValues().stream().filter(value -> value.getValue().equals(initList.get(0)) && value.getOldValue().equals(initList.get(0)) && value.getChange() == null).findFirst().isPresent();
Assert.assertTrue(findCorrectTest1Value);
// Find deleted value
boolean findCorrectDeletedTest2Value = ldapGroupAttribute.getValues().stream().filter(value -> value.getValue().equals(initList.get(1)) && value.getOldValue().equals(initList.get(1)) && SysValueChangeType.REMOVED == value.getChange()).findFirst().isPresent();
Assert.assertTrue(findCorrectDeletedTest2Value);
// Find added value
boolean findCorrectCreatedChangedValue = ldapGroupAttribute.getValues().stream().filter(value -> value.getValue().equals(changed) && value.getOldValue() == null && SysValueChangeType.ADDED == value.getChange()).findFirst().isPresent();
Assert.assertTrue(findCorrectCreatedChangedValue);
}
Aggregations