use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class IdentityContractAddGuaranteeByProjectionProcessor method conditional.
@Override
public boolean conditional(EntityEvent<IdmIdentityContractDto> event) {
if (!super.conditional(event)) {
return false;
}
// check user is logged => from gui
if (securityService.getCurrentId() == null) {
LOG.debug("User is not logged in, contract will NOT be processed (e.g. from synchronization).");
return false;
}
// check configured projection is used
IdmIdentityContractDto content = event.getContent();
IdmIdentityDto identity = lookupService.lookupEmbeddedDto(content, IdmIdentityContract_.identity);
UUID formProjectionId = identity.getFormProjection();
if (formProjectionId == null) {
LOG.debug("Contract is created without projection, contract will NOT be processer.");
return false;
}
//
// projection flag is set
IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(identity, IdmIdentity_.formProjection);
if (formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_SET_CONTRACT_GUARANTEE)) {
LOG.debug("Contract is created with projection [{}], add direct guarantee for newly created contract is enabled.", formProjection.getId());
return true;
}
//
LOG.debug("Contract is created with projection [{}], " + "add direct guarantee for newly created contract is NOT enabled, " + "contract will NOT be processed.", formProjection.getId());
return false;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class InitDemoDataProcessor method process.
@Override
public EventResult<ModuleDescriptorDto> process(EntityEvent<ModuleDescriptorDto> event) {
LOG.info("Creating demo data.");
//
// form attributes at first => identity will be created with default values
createFormAttributes();
//
// get default tree type and root (by init data defensively)
IdmTreeTypeDto treeType = treeTypeService.getByCode(InitApplicationData.DEFAULT_TREE_TYPE);
Page<IdmTreeNodeDto> rootsList = treeNodeService.findRoots(treeType.getId(), PageRequest.of(0, 1));
IdmTreeNodeDto rootOrganization = null;
if (!rootsList.getContent().isEmpty()) {
rootOrganization = rootsList.getContent().get(0);
} else {
rootOrganization = new IdmTreeNodeDto();
rootOrganization.setCode("root");
rootOrganization.setName("Organization");
rootOrganization.setTreeType(treeTypeService.getByCode(InitOrganizationProcessor.DEFAULT_TREE_TYPE).getId());
rootOrganization = treeNodeService.save(rootOrganization);
}
//
IdmRoleDto role2 = createRequestableCustomRole();
//
IdmRoleDto userManagerRole = roleConfiguration.getUserManagerRole();
if (userManagerRole == null) {
userManagerRole = new IdmRoleDto();
userManagerRole.setCode("userManagerRole");
userManagerRole.setCanBeRequested(true);
userManagerRole = roleService.save(userManagerRole);
//
LOG.info("Role created [id: {}]", userManagerRole.getId());
}
//
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername("john");
identity.setPassword(new GuardedString("john"));
identity.setFirstName("John");
identity.setLastName("Doe");
identity.setEmail("john.doe@bcvsolutions.eu");
identity = identityService.save(identity);
List<IdmFormValueDto> values = new ArrayList<>();
IdmFormValueDto phoneValue = new IdmFormValueDto();
phoneValue.setFormAttribute(formService.getAttribute(identity.getClass(), FORM_ATTRIBUTE_PHONE).getId());
phoneValue.setStringValue("12345679");
values.add(phoneValue);
formService.saveValues(identity.getId(), IdmIdentity.class, null, values);
LOG.info("Identity created [id: {}]", identity.getId());
//
// create prime contract
IdmIdentityContractDto identityContract = identityContractService.getPrimeContract(identity.getId());
if (identityContract == null) {
identityContract = identityContractService.prepareMainContract(identity.getId());
identityContract = identityContractService.save(identityContract);
}
//
IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
identityRole.setIdentityContract(identityContract.getId());
identityRole.setRole(role2.getId());
identityRole = identityRoleService.save(identityRole);
//
IdmIdentityDto identity2 = new IdmIdentityDto();
identity2.setUsername("jane");
identity2.setFirstName("Jane");
identity2.setPassword(new GuardedString("jane"));
identity2.setLastName("Doe");
identity2.setEmail("jane.doe@bcvsolutions.eu");
identity2 = identityService.save(identity2);
LOG.info("Identity created [id: {}]", identity2.getId());
//
IdmIdentityDto identity3 = new IdmIdentityDto();
identity3.setUsername("novak");
identity3.setFirstName("Jan");
identity3.setPassword(new GuardedString("novak"));
identity3.setLastName("Novák");
identity3.setEmail("jan.novak@bcvsolutions.eu");
identity3 = identityService.save(identity3);
LOG.info("Identity created [id: {}]", identity3.getId());
//
IdmTreeNodeDto organization1 = new IdmTreeNodeDto();
organization1.setCode("one");
organization1.setName("Organization One");
organization1.setParent(rootOrganization.getId());
organization1.setTreeType(treeType.getId());
organization1 = treeNodeService.save(organization1);
//
IdmTreeNodeDto organization2 = new IdmTreeNodeDto();
organization2.setCode("two");
organization2.setName("Organization Two");
organization2.setParent(rootOrganization.getId());
organization2.setTreeType(treeType.getId());
organization2 = treeNodeService.save(organization2);
//
// form projection for externe user
IdmFormProjectionDto externeProjection = new IdmFormProjectionDto();
externeProjection.setOwnerType(lookupService.getOwnerType(IdmIdentity.class));
externeProjection.setCode("identity-externe");
externeProjection.setRoute(IdentityFormProjectionRoute.PROJECTION_NAME);
try {
// TODO: better setter
externeProjection.setBasicFields(mapper.writeValueAsString(Lists.newArrayList(IdmIdentity_.username.getName(), IdmIdentity_.firstName.getName(), IdmIdentity_.lastName.getName())));
} catch (Exception ex) {
LOG.warn("Demo form proction will show all basic attributes.", ex);
}
// not available now in product projection
externeProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_LOAD_ASSIGNED_ROLES, false);
externeProjection = formProjectionService.save(externeProjection);
IdmIdentityDto externeIdentity = new IdmIdentityDto();
externeIdentity.setUsername("externeUser");
externeIdentity.setFirstName("František");
externeIdentity.setPassword(new GuardedString("externeUser"));
externeIdentity.setLastName("Nový");
externeIdentity.setEmail("frantisek.novy@bcvsolutions.eu");
externeIdentity.setFormProjection(externeProjection.getId());
externeIdentity = identityService.save(externeIdentity);
LOG.info("Externe identity created [id: {}]", externeIdentity.getId());
//
// helpdesk
IdmRoleDto helpdeskRole = roleConfiguration.getHelpdeskRole();
if (helpdeskRole != null) {
identity = new IdmIdentityDto();
identity.setUsername("helpdesk");
identity.setPassword(new GuardedString("helpdesk"));
identity.setFirstName("Helpdesk");
identity.setLastName("User");
identity.setEmail("hepldesk@bcvsolutions.eu");
identity.setDescription("Helpdesk - can read other users and change passwords.");
identity = identityService.save(identity);
// create prime contract
identityContract = identityContractService.getPrimeContract(identity.getId());
if (identityContract == null) {
identityContract = identityContractService.prepareMainContract(identity.getId());
identityContract = identityContractService.save(identityContract);
}
//
identityRole = new IdmIdentityRoleDto();
identityRole.setIdentityContract(identityContract.getId());
identityRole.setRole(helpdeskRole.getId());
identityRole = identityRoleService.save(identityRole);
}
//
// user manager - role created defensively above
identity = new IdmIdentityDto();
identity.setUsername("manager");
identity.setPassword(new GuardedString("manager"));
identity.setFirstName("Manager");
identity.setLastName("User");
identity.setEmail("manager@bcvsolutions.eu");
identity.setDescription("Manager with subordinates (externeUser)");
identity = identityService.save(identity);
// create prime contract
identityContract = identityContractService.getPrimeContract(identity.getId());
if (identityContract == null) {
identityContract = identityContractService.prepareMainContract(identity.getId());
identityContract = identityContractService.save(identityContract);
}
//
identityRole = new IdmIdentityRoleDto();
identityRole.setIdentityContract(identityContract.getId());
identityRole.setRole(userManagerRole.getId());
identityRole = identityRoleService.save(identityRole);
//
identityContract = identityContractService.getPrimeContract(externeIdentity.getId());
if (identityContract == null) {
identityContract = identityContractService.prepareMainContract(identity.getId());
identityContract.setExterne(true);
identityContract = identityContractService.save(identityContract);
} else {
identityContract.setExterne(true);
identityContract = identityContractService.save(identityContract);
}
// externe - set manager
IdmContractGuaranteeDto guarantee = new IdmContractGuaranteeDto();
guarantee.setIdentityContract(identityContract.getId());
guarantee.setGuarantee(identity.getId());
contractGuaranteeService.save(guarantee);
//
// role manager
IdmRoleDto roleManagerRole = roleConfiguration.getRoleManagerRole();
if (roleManagerRole != null) {
identity = new IdmIdentityDto();
identity.setUsername("roleManager");
identity.setPassword(new GuardedString("roleManager"));
identity.setFirstName("Role");
identity.setLastName("Manager");
identity.setEmail("role.manager@bcvsolutions.eu");
identity.setDescription("Role manager - can edit managed roles.");
identity = identityService.save(identity);
// create prime contract
identityContract = identityContractService.getPrimeContract(identity.getId());
if (identityContract == null) {
identityContract = identityContractService.prepareMainContract(identity.getId());
identityContract = identityContractService.save(identityContract);
}
//
identityRole = new IdmIdentityRoleDto();
identityRole.setIdentityContract(identityContract.getId());
identityRole.setRole(roleManagerRole.getId());
identityRole = identityRoleService.save(identityRole);
}
//
LOG.info("Demo data was created.");
//
configurationService.setBooleanValue(PARAMETER_DEMO_DATA_CREATED, true);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class IdentityChangeUserTypeBulkActionTest method processBulkActionByIds.
@Test
public void processBulkActionByIds() {
List<IdmIdentityDto> identities = this.createIdentities(5);
IdmFormProjectionDto projection = new IdmFormProjectionDto();
projection.setCode(getHelper().createName());
projection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
projection = projectionService.save(projection);
IdmFormProjectionDto projection2 = new IdmFormProjectionDto();
projection2.setCode(getHelper().createName());
projection2.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
projection2 = projectionService.save(projection2);
IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityChangeUserTypeBulkAction.NAME);
Set<UUID> ids = this.getIdFromList(identities);
bulkAction.setIdentifiers(this.getIdFromList(identities));
// set created form projection to all identities
Map<String, Object> properties = new HashMap<>();
properties.put(IdentityChangeUserTypeBulkAction.PROPERTY_USER_TYPE, projection.getId().toString());
bulkAction.setProperties(properties);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, 5l, null, null);
for (UUID id : ids) {
IdmIdentityDto identityDto = identityService.get(id);
assertNotNull(identityDto);
assertEquals(identityDto.getFormProjection(), projection.getId());
}
// change form projection to another type
properties.put(IdentityChangeUserTypeBulkAction.PROPERTY_USER_TYPE, projection2.getId().toString());
bulkAction.setProperties(properties);
processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, 5l, null, null);
for (UUID id : ids) {
IdmIdentityDto identityDto = identityService.get(id);
assertNotNull(identityDto);
assertEquals(identityDto.getFormProjection(), projection2.getId());
}
// removing projection in bulk action is now forbidden
properties.put(IdentityChangeUserTypeBulkAction.PROPERTY_USER_TYPE, null);
bulkAction.setProperties(properties);
try {
processAction = bulkActionManager.processAction(bulkAction);
Assert.fail();
} catch (ResultCodeException e) {
assertEquals(e.getError().getError().getStatusEnum(), CoreResultCode.BULK_ACTION_REQUIRED_PROPERTY.getCode());
}
checkResultLrt(processAction, 5l, null, null);
for (UUID id : ids) {
IdmIdentityDto identityDto = identityService.get(id);
assertNotNull(identityDto);
assertEquals(identityDto.getFormProjection(), projection2.getId());
}
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testAssingByIdentityFormProjection.
@Test
public void testAssingByIdentityFormProjection() {
IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(getLookupService().getOwnerType(IdmIdentityDto.class));
formProjection = formProjectionService.save(formProjection);
IdmIdentityDto identity = getHelper().createIdentity();
identity.setFormProjection(formProjection.getId());
identity = identityService.save(identity);
//
IdmRoleDto role = getHelper().createRole();
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.formProjection.getName(), null, formProjection.getId().toString());
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
//
// add new one
this.recalculateSync(automaticRole.getId());
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
//
IdmIdentityRoleDto identityRoleDto = identityRoles.get(0);
assertNotNull(identityRoleDto.getAutomaticRole());
assertEquals(automaticRole.getId(), identityRoleDto.getAutomaticRole());
assertEquals(automaticRole.getRole(), identityRoleDto.getRole());
//
// change value and recalculate
identity.setFormProjection(null);
identity = identityService.save(identity);
//
// recalculate isn't needed, is done when save identity
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityControllerRestTest method testFindWithoutFormProjection.
@Test
public void testFindWithoutFormProjection() {
String description = getHelper().createName();
//
// without
IdmIdentityDto identity = prepareDto();
identity.setDescription(description);
IdmIdentityDto identityOne = createDto(identity);
//
// with projection
IdmFormProjectionDto projection = new IdmFormProjectionDto();
projection.setCode(getHelper().createName());
projection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
projection = formProjectionService.save(projection);
identity = prepareDto();
identity.setDescription(description);
identity.setFormProjection(projection.getId());
IdmIdentityDto identityTwo = createDto(identity);
//
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setText(description);
filter.setWithoutFormProjection(Boolean.TRUE);
List<IdmIdentityDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(identityOne.getId())));
//
filter.setWithoutFormProjection(Boolean.FALSE);
results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(identityTwo.getId())));
}
Aggregations