use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class IdentityContractAddGuaranteeByProjectionProcessor method process.
@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
IdmIdentityContractDto contract = event.getContent();
//
// create contract guarantee
IdmContractGuaranteeDto guarantee = new IdmContractGuaranteeDto();
guarantee.setIdentityContract(contract.getId());
guarantee.setGuarantee(securityService.getCurrentId());
// preserve event chain (and priority)
ContractGuaranteeEvent guaranteeEvent = new ContractGuaranteeEvent(ContractGuaranteeEventType.CREATE, guarantee);
guaranteeService.publish(guaranteeEvent, event);
// evict authorization manager caches for token identity only
cacheManager.evictValue(AuthorizationManager.PERMISSION_CACHE_NAME, securityService.getCurrentId());
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto 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.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class ContractGuaranteeDeleteProcessor method checkControlledBySlices.
/**
* Test if contract of the given contract guarantee has some slices.
*
* @param guarantee
* @return
*/
private void checkControlledBySlices(EntityEvent<IdmContractGuaranteeDto> event) {
IdmContractGuaranteeDto guarantee = event.getContent();
if (getBooleanProperty(ContractSliceManager.SKIP_CHECK_FOR_SLICES, event.getProperties())) {
return;
}
UUID contract = guarantee.getIdentityContract();
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setParentContract(contract);
if (contract != null && sliceService.count(sliceFilter) > 0) {
throw new ResultCodeException(CoreResultCode.CONTRACT_IS_CONTROLLED_GUARANTEE_CANNOT_BE_DELETED, ImmutableMap.of("contractId", contract));
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class ContractGuaranteeDeleteProcessor method process.
@Override
public EventResult<IdmContractGuaranteeDto> process(EntityEvent<IdmContractGuaranteeDto> event) {
checkControlledBySlices(event);
IdmContractGuaranteeDto dto = event.getContent();
//
contractGuaranteeService.deleteInternal(dto);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto in project CzechIdMng by bcvsolutions.
the class IdentityAddContractGuaranteeBulkActionTest method withoutPermissionCreateGuarantee.
@Test
@Transactional
public void withoutPermissionCreateGuarantee() {
IdmIdentityDto identityForLogin = getHelper().createIdentity();
IdmRoleDto permissionRole = getHelper().createRole();
getHelper().createBasePolicy(permissionRole.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.READ, IdmBasePermission.COUNT);
getHelper().createIdentityRole(identityForLogin, permissionRole);
loginAsNoAdmin(identityForLogin.getUsername());
List<IdmIdentityDto> guarantees = this.createIdentities(1);
IdmIdentityDto employee = getHelper().createIdentity();
IdmIdentityContractDto contract1 = getHelper().getPrimeContract(employee);
IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityAddContractGuaranteeBulkAction.NAME);
Set<UUID> ids = this.getIdFromList(Arrays.asList(employee));
bulkAction.setIdentifiers(ids);
Map<String, Object> properties = new HashMap<>();
List<String> uuidStrings = guarantees.stream().map(AbstractDto::getId).map(Object::toString).collect(Collectors.toList());
properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_NEW_GUARANTEE, uuidStrings);
bulkAction.setProperties(properties);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
// no log record is expected
checkResultLrt(processAction, null, 0l, 1l);
// test guarantes on all contracts
List<IdmContractGuaranteeDto> assigned = getGuaranteesForContract(contract1.getId());
Assert.assertEquals(0, assigned.size());
}
Aggregations