Search in sources :

Example 31 with IdmContractGuaranteeDto

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);
}
Also used : IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) ContractGuaranteeEvent(eu.bcvsolutions.idm.core.model.event.ContractGuaranteeEvent)

Example 32 with IdmContractGuaranteeDto

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);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ArrayList(java.util.ArrayList) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity)

Example 33 with IdmContractGuaranteeDto

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));
    }
}
Also used : IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) UUID(java.util.UUID)

Example 34 with IdmContractGuaranteeDto

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);
}
Also used : IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 35 with IdmContractGuaranteeDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) HashMap(java.util.HashMap) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmContractGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto)54 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)42 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)41 Test (org.junit.Test)31 UUID (java.util.UUID)27 IdmContractGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter)20 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)17 HashMap (java.util.HashMap)16 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)15 AbstractBulkActionTest (eu.bcvsolutions.idm.test.api.AbstractBulkActionTest)13 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)12 List (java.util.List)12 Transactional (org.springframework.transaction.annotation.Transactional)10 IdmContractGuaranteeService (eu.bcvsolutions.idm.core.api.service.IdmContractGuaranteeService)9 Map (java.util.Map)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 Collectors (java.util.stream.Collectors)8 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)7 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)6 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)6