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());
}
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);
}
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);
}
}
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());
}
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;
}
Aggregations