use of eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto 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<VsAttributeDto> resultAttributes = new ArrayList<>();
IcConnectorObject realConnectorObject = this.getVsConnectorObject(request);
IcConnectorObject currentObject = realConnectorObject != null ? realConnectorObject : new IcConnectorObjectImpl();
IcConnectorObject changeObject = request.getConnectorObject() != null ? request.getConnectorObject() : new IcConnectorObjectImpl();
List<IcAttribute> currentAttributes = currentObject.getAttributes();
List<IcAttribute> changedAttributes = request.getConnectorObject().getAttributes();
// First add all new attributes
changedAttributes.forEach(changedAttribute -> {
if (currentObject.getAttributeByName(changedAttribute.getName()) == null) {
VsAttributeDto vsAttribute = new VsAttributeDto(changedAttribute.getName(), changedAttribute.isMultiValue(), true);
if (changedAttribute.isMultiValue()) {
if (changedAttribute.getValues() != null) {
changedAttribute.getValues().forEach(value -> {
vsAttribute.getValues().add(new VsAttributeValueDto(value, null, VsValueChangeType.ADDED));
});
}
} else {
vsAttribute.setValue(new VsAttributeValueDto(changedAttribute.getValue(), null, VsValueChangeType.ADDED));
}
resultAttributes.add(vsAttribute);
}
});
// Second add all already exists attributes
currentAttributes.forEach(currentAttribute -> {
VsAttributeDto vsAttribute;
// Attribute was changed
if (changeObject.getAttributeByName(currentAttribute.getName()) != null) {
vsAttribute = new VsAttributeDto(currentAttribute.getName(), currentAttribute.isMultiValue(), true);
IcAttribute changedAttribute = changeObject.getAttributeByName(currentAttribute.getName());
if (changedAttribute.isMultiValue()) {
if (changedAttribute.getValues() != null) {
changedAttribute.getValues().forEach(value -> {
if (currentAttribute.getValues() != null && currentAttribute.getValues().contains(value)) {
vsAttribute.getValues().add(new VsAttributeValueDto(value, value, null));
} else {
vsAttribute.getValues().add(new VsAttributeValueDto(value, null, VsValueChangeType.ADDED));
}
});
}
if (currentAttribute.getValues() != null) {
currentAttribute.getValues().forEach(value -> {
if (changedAttribute.getValues() == null || !changedAttribute.getValues().contains(value)) {
vsAttribute.getValues().add(new VsAttributeValueDto(value, value, VsValueChangeType.REMOVED));
}
});
}
} else {
Object changedValue = changedAttribute.getValue();
Object currentValue = currentAttribute.getValue();
if ((changedValue == null && currentValue == null) || (changedValue != null && changedValue.equals(currentObject)) || (currentValue != null && currentValue.equals(changedValue))) {
vsAttribute.setValue(new VsAttributeValueDto(changedValue, currentValue, null));
} else {
vsAttribute.setValue(new VsAttributeValueDto(changedValue, currentValue, VsValueChangeType.UPDATED));
}
}
} else {
// Attribute was not changed
vsAttribute = new VsAttributeDto(currentAttribute.getName(), currentAttribute.isMultiValue(), false);
if (currentAttribute.isMultiValue()) {
if (currentAttribute.getValues() != null) {
currentAttribute.getValues().forEach(value -> {
vsAttribute.getValues().add(new VsAttributeValueDto(value, value, null));
});
}
} else {
vsAttribute.setValue(new VsAttributeValueDto(currentAttribute.getValue(), currentAttribute.getValue(), null));
}
}
resultAttributes.add(vsAttribute);
});
BasicVirtualConfiguration configuration = getVirtualConnector(request).getVirtualConfiguration();
// result list
if (!configuration.isDisableSupported()) {
VsAttributeDto enableAttribute = resultAttributes.stream().filter(attribute -> attribute.getName().equals(IcAttributeInfo.ENABLE)).findFirst().orElse(null);
if (enableAttribute != null) {
resultAttributes.remove(enableAttribute);
}
}
VsConnectorObjectDto wishObject = new VsConnectorObjectDto();
wishObject.setUid(request.getUid());
wishObject.setAttributes(resultAttributes);
return wishObject;
}
use of eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto in project CzechIdMng by bcvsolutions.
the class VsReqeustServiceTest method changeUidTest.
@Test
public void changeUidTest() {
SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
IdmIdentityDto userOne = helper.createIdentity(USER_ONE_NAME);
identityService.save(userOne);
this.assignRoleSystem(system, userOne, ROLE_ONE_NAME);
// Find created requests
VsRequestFilter requestFilter = new VsRequestFilter();
requestFilter.setSystemId(system.getId());
requestFilter.setUid(USER_ONE_NAME);
requestFilter.setState(VsRequestState.IN_PROGRESS);
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);
// Change username attributes
userOne.setUsername(USER_ONE_CHANGED_NAME);
// Invoke provisioning
identityService.save(userOne);
requests = requestService.find(requestFilter, null).getContent();
Assert.assertEquals(2, requests.size());
// We realize the create request
super.logout();
loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
requestService.realize(createRequest);
requests = requestService.find(requestFilter, null).getContent();
Assert.assertEquals(1, requests.size());
// get wish
wish = requestService.getWishConnectorObject(requests.get(0));
Assert.assertEquals(1, wish.getAttributes().stream().filter(attr -> attr.isChanged()).count());
// Find change for firstName value
boolean findCorrectChangedUserName = wish.getAttributes().stream().filter(attr -> attr.getValue().getValue().equals(USER_ONE_CHANGED_NAME) && attr.getValue().getOldValue().equals(USER_ONE_NAME) && VsValueChangeType.UPDATED == attr.getValue().getChange()).findFirst().isPresent();
Assert.assertTrue(findCorrectChangedUserName);
SysSystemEntityFilter systemEntityFilter = new SysSystemEntityFilter();
systemEntityFilter.setSystemId(system.getId());
systemEntityFilter.setUid(USER_ONE_NAME);
boolean oldUserNameExist = !systemEntityService.find(systemEntityFilter, null).getContent().isEmpty();
Assert.assertTrue(oldUserNameExist);
// Realize change username
requestService.realize(requests.get(0));
// We expects change UID in SystemEntity.UID
oldUserNameExist = !systemEntityService.find(systemEntityFilter, null).getContent().isEmpty();
Assert.assertTrue(!oldUserNameExist);
systemEntityFilter.setUid(USER_ONE_CHANGED_NAME);
boolean changedUserNameExist = !systemEntityService.find(systemEntityFilter, null).getContent().isEmpty();
Assert.assertTrue(changedUserNameExist);
}
use of eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto in project CzechIdMng by bcvsolutions.
the class DefaultVsRequestService method sendNotification.
private void sendNotification(VsRequestDto request, VsRequestDto previous) {
Assert.notNull(request, "VS request cannot be null for send notification!");
List<IdmIdentityDto> implementers = this.requestImplementerService.findRequestImplementers(request.getSystem());
if (implementers.isEmpty()) {
// We do not have any implementers ... we don`t have anyone to send
// notification
LOG.warn(MessageFormat.format("Notification cannot be send! We do not have any implementers in request [{0}].", request.getId()));
return;
}
// We assume the request.UID is equals Identity user name!;
IdmIdentityDto identity = this.getIdentity(request);
SysSystemDto system = systemService.get(request.getSystem());
VsConnectorObjectDto wish = this.getWishConnectorObject(request);
// send create notification
notificationManager.send(VirtualSystemModuleDescriptor.TOPIC_VS_REQUEST_CREATED, new IdmMessageDto.Builder().setLevel(NotificationLevel.INFO).addParameter("requestAttributes", request.getConnectorObject() != null ? request.getConnectorObject().getAttributes() : null).addParameter("wishAttributes", //
wish.getAttributes()).addParameter("fullName", //
identityService.getNiceLabel(identity)).addParameter("identity", //
identity).addParameter("url", //
getUrl(request)).addParameter("previousUrl", //
getUrl(previous)).addParameter("request", //
request).addParameter("systemName", system.getName()).build(), implementers);
}
use of eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto in project CzechIdMng by bcvsolutions.
the class VsReqeustServiceTest method checkSinglevalueInWishObjectTest.
@Test
public void checkSinglevalueInWishObjectTest() {
String changed = "changed";
String firstName = "firstName";
String lastName = "lastName";
SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
IdmIdentityDto userOne = helper.createIdentity(USER_ONE_NAME);
userOne.setFirstName(firstName);
userOne.setLastName(lastName);
identityService.save(userOne);
this.assignRoleSystem(system, userOne, ROLE_ONE_NAME);
// Find created requests
VsRequestFilter requestFilter = new VsRequestFilter();
requestFilter.setSystemId(system.getId());
requestFilter.setUid(USER_ONE_NAME);
requestFilter.setState(VsRequestState.IN_PROGRESS);
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);
// Change singlevalue attributes
userOne.setFirstName(changed);
userOne.setLastName(changed);
// Invoke provisioning
identityService.save(userOne);
requests = requestService.find(requestFilter, null).getContent();
Assert.assertEquals(2, requests.size());
// We realize the create request
super.logout();
loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
requestService.realize(createRequest);
requests = requestService.find(requestFilter, null).getContent();
Assert.assertEquals(1, requests.size());
// get wish
wish = requestService.getWishConnectorObject(requests.get(0));
Assert.assertEquals(2, wish.getAttributes().stream().filter(attr -> attr.isChanged()).count());
// Find change for firstName value
boolean findCorrectChangedFirstName = wish.getAttributes().stream().filter(attr -> attr.getValue().getValue().equals(changed) && attr.getValue().getOldValue().equals(firstName) && VsValueChangeType.UPDATED == attr.getValue().getChange()).findFirst().isPresent();
Assert.assertTrue(findCorrectChangedFirstName);
// Find change for lastName value
boolean findCorrectChangedLastName = wish.getAttributes().stream().filter(attr -> attr.getValue().getValue().equals(changed) && attr.getValue().getOldValue().equals(lastName) && VsValueChangeType.UPDATED == attr.getValue().getChange()).findFirst().isPresent();
Assert.assertTrue(findCorrectChangedLastName);
}
use of eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto in project CzechIdMng by bcvsolutions.
the class VsReqeustServiceTest 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);
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
VsAttributeDto 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)) && VsValueChangeType.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 && VsValueChangeType.ADDED == value.getChange()).findFirst().isPresent();
Assert.assertTrue(findCorrectCreatedChangedValue);
}
Aggregations