Search in sources :

Example 61 with TestResource

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);
    }
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) InputStream(java.io.InputStream) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IOException(java.io.IOException) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 62 with TestResource

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);
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 63 with TestResource

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 64 with TestResource

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 65 with TestResource

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)97 Test (org.junit.Test)83 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)81 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)69 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)51 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)50 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)36 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)32 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)32 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)30 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)27 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)26 ConfidentialString (eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString)19 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)17 SysSchemaAttributeFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter)12 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)12 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)12 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)11 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)10 Transactional (org.springframework.transaction.annotation.Transactional)10