use of eu.bcvsolutions.idm.acc.entity.TestResource 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);
}
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningTest method testAssignedRolesForSystem.
@Test
public void testAssignedRolesForSystem() {
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_FOR_SYSTEM_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);
IdmIdentityRoleDto identityRoleWithSystem = 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();
String result = "";
IdmFormInstanceDto formInstanceDto = identityRoleService.getRoleAttributeValues(identityRoleWithSystem);
identityRoleWithSystem.getEavs().clear();
identityRoleWithSystem.getEavs().add(formInstanceDto);
result = IdentityProvisioningExecutor.convertToAssignedRoleDto(identityRoleWithSystem).toString();
assertEquals(result, valueOnResource);
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningTest method testProvisioningOnChangeRoleAttributeValue.
@Test
public void testProvisioningOnChangeRoleAttributeValue() {
SysSystemDto systemDto = helper.createTestResourceSystem(true);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(systemDto.getId());
IdmRoleDto roleWithSystem = helper.createRole();
helper.createRoleSystem(roleWithSystem, systemDto);
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityContractDto primeContract = helper.getPrimeContract(identity);
assertNotNull(primeContract);
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, roleWithSystem, null, null);
identity.setFirstName(helper.createName());
identityService.save(identity);
TestResource resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
String valueOnResource = resource.getFirstname();
assertEquals(identity.getFirstName(), valueOnResource);
// Change first name without call provisioning
identity.setFirstName(helper.createName());
identityService.saveInternal(identity);
resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
assertNotEquals(identity.getFirstName(), resource.getFirstname());
// Create request
IdmRoleRequestDto request = getHelper().createRoleRequest(identity);
// Create change role-concept
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setRoleRequest(request.getId());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setValidFrom(identityRole.getValidFrom());
conceptRoleRequest.setValidTill(identityRole.getValidTill());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.UPDATE);
conceptRoleRequest = conceptRoleRequestService.save(conceptRoleRequest);
conceptRoleRequest.getEavs().clear();
// Execution of the request must execute provisioning
request = getHelper().executeRequest(request, false, true);
// Check request
assertEquals(RoleRequestState.EXECUTED, request.getState());
resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
assertEquals(identity.getFirstName(), resource.getFirstname());
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class IdentityAccountManagementTest method overloadedAttributeAdd_B_DisableFirstNameRole.
@Test
public void overloadedAttributeAdd_B_DisableFirstNameRole() {
IdmIdentityDto identity = identityService.getByUsername(IDENTITY_USERNAME);
IdmRoleDto roleLastName = roleService.getByCode(ROLE_OVERLOADING_FIRST_NAME);
Assert.assertNotNull("Account for this identity have to be found!", helper.findResource("x" + IDENTITY_USERNAME));
IdmIdentityRoleDto irdto = new IdmIdentityRoleDto();
irdto.setIdentityContract(identityContractService.findAllByIdentity(identity.getId()).get(0).getId());
irdto.setRole(roleLastName.getId());
// This evokes IdentityRole SAVE event. On this event will be start
// account management and provisioning
identityRoleService.save(irdto);
AccIdentityAccountFilter iaccFilter = new AccIdentityAccountFilter();
iaccFilter.setIdentityId(identity.getId());
// Now we have to identity roles (role_overloading_first_name and
// role_overloading_last_name) and identity accounts
Assert.assertEquals("Idenitity accounts have to exists (two items) after account management was started!", 2, identityAccountService.find(iaccFilter, null).getContent().size());
TestResource createdAccount = helper.findResource("x" + IDENTITY_USERNAME);
Assert.assertNotNull("Idenitity have to exists on target system (after account management)", createdAccount);
Assert.assertEquals("First name on target system must be equals with first name on identity", identity.getFirstName(), createdAccount.getFirstname());
identity.setFirstName(IDENTITY_CHANGED_FIRST_NAME);
identity.setEmail(IDENTITY_EMAIL_CHANGED);
// This evokes Identity SAVE event. On this event will be start
// account management and provisioning
identityService.save(identity);
createdAccount = helper.findResource("x" + IDENTITY_USERNAME);
// Because first name attribute was disabled, we now expect change only
// on email attribute
Assert.assertEquals("Last name on target system must be equals with email on identity (we use overloded attribute)", IDENTITY_EMAIL_CHANGED, createdAccount.getLastname());
Assert.assertNotEquals("First name on target system must be not equals with first name on identity (we use overloded disabled attribute)", identity.getFirstName(), createdAccount.getFirstname());
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class IdentityAccountManagementTest method defaultAccountAddValid.
@Test
public void defaultAccountAddValid() {
IdmIdentityDto identity = identityService.getByUsername(IDENTITY_USERNAME);
IdmRoleDto roleDefault = roleService.getByCode(ROLE_DEFAULT);
Assert.assertNull("No account for this identity can be found, before account management start!", helper.findResource("x" + IDENTITY_USERNAME));
IdmIdentityRoleDto irdto = new IdmIdentityRoleDto();
irdto.setIdentityContract(identityContractService.findAllByIdentity(identity.getId()).get(0).getId());
irdto.setRole(roleDefault.getId());
// This evokes IdentityRole SAVE event. On this event will be start
// account management and provisioning
IdmIdentityRoleDto irCreated = identityRoleService.save(irdto);
AccIdentityAccountFilter iaccFilter = new AccIdentityAccountFilter();
iaccFilter.setIdentityId(identity.getId());
iaccFilter.setIdentityRoleId(irCreated.getId());
AccIdentityAccountDto identityAccount = identityAccountService.find(iaccFilter, null).getContent().get(0);
Assert.assertNotNull("Idenitity account have to exists after account management was started!", identityAccount);
Assert.assertNotNull("Account have to exists after account management was started!", identityAccount.getAccount());
Assert.assertEquals(accountService.get(identityAccount.getAccount()).getUid(), "x" + IDENTITY_USERNAME);
TestResource createdAccount = helper.findResource("x" + IDENTITY_USERNAME);
Assert.assertNotNull("Idenitity have to exists on target system (after account management)", createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
}
Aggregations