use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto 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);
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemService method convertIcAttributeInfo.
private SysSchemaAttributeDto convertIcAttributeInfo(IcAttributeInfo attributeInfo, SysSchemaAttributeDto sysAttribute) {
if (attributeInfo == null) {
return null;
}
if (sysAttribute == null) {
sysAttribute = new SysSchemaAttributeDto();
}
sysAttribute.setClassType(attributeInfo.getClassType());
sysAttribute.setName(attributeInfo.getName());
sysAttribute.setMultivalued(attributeInfo.isMultivalued());
sysAttribute.setNativeName(attributeInfo.getNativeName());
sysAttribute.setReadable(attributeInfo.isReadable());
sysAttribute.setRequired(attributeInfo.isRequired());
sysAttribute.setReturnedByDefault(attributeInfo.isReturnedByDefault());
sysAttribute.setUpdateable(attributeInfo.isUpdateable());
sysAttribute.setCreateable(attributeInfo.isCreateable());
return sysAttribute;
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class ComplexHrProcessIntegrationTest method createLdapProvisioningMapping.
private void createLdapProvisioningMapping(SysSystemDto system) {
List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
SysSchemaObjectClassDto objectClass = objectClasses.stream().filter(oc -> oc.getObjectClassName().equals("__ACCOUNT__")).findFirst().orElse(null);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
// Provisioning mapping
SysSystemMappingDto mapping = new SysSystemMappingDto();
mapping.setName(getHelper().createName());
mapping.setEntityType(SystemEntityType.IDENTITY);
mapping.setOperationType(SystemOperationType.PROVISIONING);
mapping.setObjectClass(objectClass.getId());
mapping = systemMappingService.save(mapping);
ImmutableMap<String, String> mappingConfig = new ImmutableMap.Builder<String, String>().put("mail", IdmIdentity_.email.getName()).put("sn", IdmIdentity_.lastName.getName()).put("givenName", IdmIdentity_.firstName.getName()).put("cn", IdmIdentity_.username.getName()).put("__NAME__", IdmIdentity_.username.getName()).put("title ", IdmIdentity_.titleBefore.getName()).put("__PASSWORD__", "__PASSWORD__").put("initials", "multivalue").build();
for (SysSchemaAttributeDto schemaAttr : schemaAttributes) {
String schemaName = schemaAttr.getName();
if (!mappingConfig.containsKey(schemaName)) {
continue;
}
SysSystemAttributeMappingFilter attrFilt = new SysSystemAttributeMappingFilter();
attrFilt.setName(schemaName);
attrFilt.setSystemId(system.getId());
attrFilt.setOperationType(SystemOperationType.PROVISIONING);
if (systemAttributeMappingService.count(attrFilt) > 0) {
// some attributes are in the schema more than once, skip if already mapped
continue;
}
SysSystemAttributeMappingDto mappingAttr = new SysSystemAttributeMappingDto();
mappingAttr.setName(schemaName);
mappingAttr.setIdmPropertyName(mappingConfig.get(schemaName));
mappingAttr.setSystemMapping(mapping.getId());
mappingAttr.setSchemaAttribute(schemaAttr.getId());
mappingAttr.setEntityAttribute(true);
if ("__NAME__".equals(schemaName)) {
mappingAttr.setUid(true);
mappingAttr.setTransformToResourceScript("return \"uid=\"+attributeValue+\",ou=" + ldapUserOU + "," + ldapBaseOU + "\";");
} else if ("__PASSWORD__".equals(schemaName)) {
mappingAttr.setPasswordAttribute(true);
mappingAttr.setEntityAttribute(false);
mappingAttr.setIdmPropertyName(null);
mappingAttr.setSendAlways(true);
} else if ("initials".equals(schemaName)) {
// used as multivalue merged attr
mappingAttr.setEntityAttribute(false);
mappingAttr.setStrategyType(AttributeMappingStrategyType.MERGE);
mappingAttr = systemAttributeMappingService.save(mappingAttr);
createLdapGroupRoles(system, mappingAttr);
}
systemAttributeMappingService.save(mappingAttr);
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class IdentityPasswordProvisioningTest method initDescriptionAttribute.
/**
* Init description attribute. The attribute will be mapped to entity attribute
* description.
*
* @param system
* @return
*/
private SysSystemAttributeMappingDto initDescriptionAttribute(SysSystemDto system) {
// update attribute description for password
SysSystemMappingDto mapping = helper.getDefaultMapping(system);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
assertFalse(schemaAttributes.isEmpty());
SysSystemAttributeMappingDto attributeMapping = new SysSystemAttributeMappingDto();
for (SysSchemaAttributeDto schemaAttr : schemaAttributes) {
if (schemaAttr.getName().equalsIgnoreCase(TestHelper.ATTRIBUTE_MAPPING_DESCRIPTION)) {
attributeMapping.setEntityAttribute(true);
attributeMapping.setIdmPropertyName(IdmIdentity_.description.getName());
attributeMapping.setName(schemaAttr.getName());
attributeMapping.setSchemaAttribute(schemaAttr.getId());
attributeMapping.setSystemMapping(mapping.getId());
attributeMapping = systemAttributeMappingService.save(attributeMapping);
}
}
return attributeMapping;
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningTest method testAttachment.
@Test
public void testAttachment() {
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 attributeByte = new SysSystemAttributeMappingDto();
attributeByte.setUid(false);
attributeByte.setEntityAttribute(false);
attributeByte.setExtendedAttribute(true);
attributeByte.setIdmPropertyName(getHelper().createName());
attributeByte.setName(descriptionSchemaAttribute.getName());
attributeByte.setSchemaAttribute(descriptionSchemaAttribute.getId());
attributeByte.setSystemMapping(defaultMapping.getId());
// Transformation data to string
attributeByte.setTransformToResourceScript("if(attributeValue == null) " + System.lineSeparator() + "{return null;}" + System.lineSeparator() + " return new String(attributeValue.getData());");
schemaAttributeMappingService.save(attributeByte);
IdmRoleDto roleWithSystem = helper.createRole();
helper.createRoleSystem(roleWithSystem, systemDto);
// Set type of attribute to attachment
IdmFormAttributeDto eavAttributeByte = formService.getAttribute(IdmIdentityDto.class, attributeByte.getIdmPropertyName());
eavAttributeByte.setPersistentType(PersistentType.ATTACHMENT);
eavAttributeByte = formService.saveAttribute(eavAttributeByte);
// Create attachment with content
String originalContent = getHelper().createName();
IdmAttachmentDto attachment = new IdmAttachmentDto();
attachment.setName("test.txt");
attachment.setMimetype("text/plain");
attachment.setInputData(IOUtils.toInputStream(originalContent));
attachment.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
attachment = attachmentManager.saveAttachment(null, attachment);
InputStream inputStream = attachmentManager.getAttachmentData(attachment.getId());
try {
String content = IOUtils.toString(inputStream);
assertEquals(originalContent, content);
// Create form value with attachment
IdmIdentityDto identity = helper.createIdentity();
formService.saveValues(identity, eavAttributeByte, Lists.newArrayList(attachment.getId()));
// Assign the system
helper.createIdentityRole(identity, roleWithSystem, null, null);
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identity.getId());
TestResource resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
String valueOnResource = resource.getDescrip();
InputStream is = attachmentManager.getAttachmentData(attachment.getId());
try {
String data = new String(IOUtils.toByteArray(is));
assertEquals(data, valueOnResource);
} finally {
IOUtils.closeQuietly(is);
}
} catch (IOException e) {
throw new CoreException(e);
} finally {
IOUtils.closeQuietly(inputStream);
}
}
Aggregations