Search in sources :

Example 11 with IdmIdentityProjectionDto

use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManagerIntegrationTest method testSaveAndGetSimpleIdentity.

@Test
@Transactional
public void testSaveAndGetSimpleIdentity() {
    IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
    IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
    IdmIdentityProjectionDto createdProjection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
    // 
    Assert.assertNotNull(createdProjection);
    Assert.assertNotNull(createdProjection.getId());
    Assert.assertEquals(createdProjection.getId(), createdProjection.getIdentity().getId());
    Assert.assertEquals(identity.getUsername(), createdProjection.getIdentity().getUsername());
    Assert.assertNull(createdProjection.getContract());
    Assert.assertTrue(createdProjection.getOtherContracts().isEmpty());
    Assert.assertTrue(createdProjection.getOtherPositions().isEmpty());
    Assert.assertTrue(createdProjection.getIdentityRoles().isEmpty());
}
Also used : IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with IdmIdentityProjectionDto

use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManagerIntegrationTest method testValidateExtendedAttributeRequiredFailed.

@Transactional
@Test(expected = InvalidFormException.class)
public void testValidateExtendedAttributeRequiredFailed() throws Exception {
    // prepare projection
    IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
    formProjection.setCode(getHelper().createName());
    formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
    formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS, true);
    // 
    IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
    attributeDefinitionOne.setCode(getHelper().createName());
    attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
    attributeDefinitionOne.setPersistentType(PersistentType.SHORTTEXT);
    IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class, getHelper().createName(), Lists.newArrayList(attributeDefinitionOne));
    attributeDefinitionOne = formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
    // 
    IdmFormAttributeDto attribute = new IdmFormAttributeDto();
    attribute.setId(attributeDefinitionOne.getId());
    attribute.setPersistentType(attributeDefinitionOne.getPersistentType());
    attribute.setFormDefinition(attributeDefinitionOne.getFormDefinition());
    attribute.setCode(attributeDefinitionOne.getCode());
    attribute.setRequired(true);
    attribute.setLabel("overriden");
    attribute.setPlaceholder("overriden");
    attribute.setMin(BigDecimal.ONE);
    attribute.setMax(BigDecimal.TEN);
    attribute.setRegex("[abc]");
    attribute.setValidationMessage("Test validation failed.");
    formProjection.setFormValidations(mapper.writeValueAsString(Lists.newArrayList(attribute)));
    formProjection = projectionService.save(formProjection);
    // 
    // create identity with projection is defined
    IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
    identity.setExternalCode(getHelper().createName());
    identity.setLastName(getHelper().createName());
    identity.setFormProjection(formProjection.getId());
    // 
    // set eav
    IdmFormInstanceDto instanceOne = new IdmFormInstanceDto();
    instanceOne.setFormDefinition(formDefinitionOne);
    IdmFormValueDto valueOne = new IdmFormValueDto(attribute);
    instanceOne.setValues(Lists.newArrayList(valueOne));
    identity.setEavs(Lists.newArrayList(instanceOne));
    // 
    IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
    // 
    IdentityProjectionEvent identityProjectionEvent = new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection);
    identityProjectionEvent.setPriority(PriorityType.IMMEDIATE);
    manager.publish(identityProjectionEvent);
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with IdmIdentityProjectionDto

use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManagerIntegrationTest method testSaveProjectionWithoutContractAuthority.

@Transactional
@Test(expected = ForbiddenEntityException.class)
public void testSaveProjectionWithoutContractAuthority() {
    String defaultRoleCode = roleConfiguration.getDefaultRoleCode();
    // create identity with update identity permission only
    // with password
    IdmIdentityDto identityLogged = getHelper().createIdentity();
    IdmRoleDto role = getHelper().createRole();
    // read all
    getHelper().createBasePolicy(role.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.READ, IdmBasePermission.CREATE, IdmBasePermission.UPDATE);
    getHelper().createIdentityRole(identityLogged, role);
    // 
    IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
    IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
    projection.setContract(new IdmIdentityContractDto());
    // 
    try {
        // empty property => disable default role
        getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, "");
        // 
        getHelper().login(identityLogged);
        // 
        manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection), IdmBasePermission.CREATE).getContent();
    } finally {
        logout();
        getHelper().setConfigurationValue(RoleConfiguration.PROPERTY_DEFAULT_ROLE, defaultRoleCode);
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with IdmIdentityProjectionDto

use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManagerIntegrationTest method testLoadAssignedRoles.

@Test
@Transactional
public void testLoadAssignedRoles() {
    IdmFormProjectionDto projection = new IdmFormProjectionDto();
    projection.setCode(getHelper().createName());
    projection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
    projection = projectionService.save(projection);
    // 
    // create identity with projection is defined
    IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
    identity.setFormProjection(projection.getId());
    identity = identityService.save(identity);
    IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
    getHelper().createIdentityRole(primeContract, getHelper().createRole());
    // 
    IdmIdentityProjectionDto identityProjection = manager.get(identity.getId());
    Assert.assertFalse(identityProjection.getIdentityRoles().isEmpty());
    // 
    projection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_LOAD_ASSIGNED_ROLES, false);
    projectionService.save(projection);
    identityProjection = manager.get(identity.getId());
    Assert.assertTrue(identityProjection.getIdentityRoles().isEmpty());
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with IdmIdentityProjectionDto

use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.

the class DefaultIdentityProjectionManager method get.

@Override
public IdmIdentityProjectionDto get(Serializable codeableIdentifier, BasePermission... permission) {
    LOG.trace("Load identity projection [{}]", codeableIdentifier);
    IdmIdentityDto identity = getIdentity(codeableIdentifier, permission);
    IdmIdentityProjectionDto dto = new IdmIdentityProjectionDto(identity);
    // contracts
    List<IdmIdentityContractDto> contracts = getContracts(dto, permission);
    if (!contracts.isEmpty()) {
        IdmIdentityContractDto contract = contracts.get(0);
        // prime contract
        dto.setContract(contract);
        contracts.removeIf(c -> Objects.equals(c, contract));
        // other contracts
        dto.setOtherContracts(contracts);
    }
    // other positions
    dto.setOtherPositions(getOtherPositions(dto, permission));
    // assigned roles
    dto.setIdentityRoles(getIdentityRoles(dto, permission));
    // 
    LOG.trace("Loaded identity projection [{}]", codeableIdentifier);
    return dto;
}
Also used : IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)

Aggregations

IdmIdentityProjectionDto (eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)34 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)32 Transactional (org.springframework.transaction.annotation.Transactional)24 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)23 Test (org.junit.Test)23 IdmFormProjectionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto)22 IdentityProjectionEvent (eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent)22 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)21 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)18 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)15 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)15 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)15 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 IdmContractPositionDto (eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto)8 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)8 ForbiddenEntityException (eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException)8 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)7 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)7 FormDefinitionAttributes (eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes)7