Search in sources :

Example 1 with IdmAutomaticRoleAttributeDto

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

the class AutomaticRoleAttributeRuleConceptProcessor method process.

@Override
public EventResult<IdmAutomaticRoleAttributeRuleDto> process(EntityEvent<IdmAutomaticRoleAttributeRuleDto> event) {
    IdmAutomaticRoleAttributeRuleDto dto = event.getContent();
    IdmAutomaticRoleAttributeDto automaticRole = automactiRoleAttributeService.get(dto.getAutomaticRoleAttribute());
    // 
    if (automaticRole == null) {
        throw new IllegalStateException("Automatic role [" + dto.getAutomaticRoleAttribute() + "] is null. Please check this rule: " + dto.getId());
    }
    // set concept
    if (!automaticRole.isConcept()) {
        automaticRole.setConcept(true);
        automaticRole = automactiRoleAttributeService.save(automaticRole);
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)

Example 2 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeService method getRulesForContract.

@Override
public Set<AbstractIdmAutomaticRoleDto> getRulesForContract(boolean pass, AutomaticRoleAttributeRuleType type, UUID contractId) {
    Set<AbstractIdmAutomaticRoleDto> automaticRoles = new HashSet<>();
    // 
    // iterate trough all automatic role that has at least one rule and isn't in concept state
    Page<IdmAutomaticRoleAttributeDto> automaticRolesToProcess = this.findAllToProcess(type, new PageRequest(0, PROCESS_ROLE_SIZE));
    while (automaticRolesToProcess.hasContent()) {
        // all found roles it will has rules and will not be in concept state
        for (IdmAutomaticRoleAttributeDto automaticRole : automaticRolesToProcess) {
            List<IdmAutomaticRoleAttributeRuleDto> allRulesForAutomaticRole = automaticRoleAttributeRuleService.findAllRulesForAutomaticRole(automaticRole.getId());
            // 
            Specification<IdmIdentityContract> criteria = this.getCriteriaForRulesByContract(automaticRole.getId(), allRulesForAutomaticRole, pass, contractId);
            boolean result = !identityContractRepository.findAll(criteria).isEmpty();
            if (result) {
                automaticRoles.add(automaticRole);
            }
        }
        // 
        if (automaticRolesToProcess.hasNext()) {
            automaticRolesToProcess = this.findAllToProcess(type, automaticRolesToProcess.nextPageable());
        } else {
            break;
        }
    }
    // 
    return automaticRoles;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) HashSet(java.util.HashSet) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)

Example 3 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeService method recalculate.

@Override
@Transactional
public IdmAutomaticRoleAttributeDto recalculate(UUID automaticRoleId) {
    Assert.notNull(automaticRoleId);
    // 
    // set concept to false before recalculation
    IdmAutomaticRoleAttributeDto automaticRolAttributeDto = this.get(automaticRoleId);
    automaticRolAttributeDto.setConcept(false);
    automaticRolAttributeDto = this.save(automaticRolAttributeDto);
    // 
    ProcessAutomaticRoleByAttributeTaskExecutor automaticRoleTask = AutowireHelper.createBean(ProcessAutomaticRoleByAttributeTaskExecutor.class);
    automaticRoleTask.setAutomaticRoleId(automaticRoleId);
    longRunningTaskManager.execute(automaticRoleTask);
    // 
    return automaticRolAttributeDto;
}
Also used : ProcessAutomaticRoleByAttributeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByAttributeTaskExecutor) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with IdmAutomaticRoleAttributeDto

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

the class ProcessAllAutomaticRoleByAttributeTaskExecutor method process.

@Override
public Boolean process() {
    // found all IdmAutomaticRoleAttributeDto for process
    Page<IdmAutomaticRoleAttributeDto> toProcessOthers = automaticRoleAttributeService.findAllToProcess(null, new PageRequest(0, DEFAULT_PAGE_SIZE_ROLE));
    boolean canContinue = true;
    // 
    this.counter = 0L;
    this.count = Long.valueOf(toProcessOthers.getTotalElements());
    // others
    while (toProcessOthers.hasContent()) {
        for (IdmAutomaticRoleAttributeDto automaticAttribute : toProcessOthers) {
            // start recalculation
            processAutomaticRoleForContract(automaticAttribute);
            // 
            counter++;
            canContinue = updateState();
            if (!canContinue) {
                break;
            }
        }
        if (!toProcessOthers.hasNext()) {
            break;
        }
        toProcessOthers = automaticRoleAttributeService.findAllToProcess(null, toProcessOthers.nextPageable());
    }
    // 
    return Boolean.TRUE;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)

Example 5 with IdmAutomaticRoleAttributeDto

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

the class IdentitySyncTest method testEnableAutomaticRoleDuringSynchronization.

@Test
public void testEnableAutomaticRoleDuringSynchronization() {
    // default initialization of system and all necessary things
    SysSystemDto system = initData();
    SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
    IdmRoleDto defaultRole = helper.createRole();
    // Set default role to sync configuration
    config.setDefaultRole(defaultRole.getId());
    // we want start recalculation after synchronization
    config.setStartAutoRoleRec(true);
    config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
    this.getBean().deleteAllResourceData();
    String testLastName = "test-last-name-same-" + System.currentTimeMillis();
    String testFirstName = "test-first-name";
    String user1 = "test-1-" + System.currentTimeMillis();
    this.getBean().setTestData(user1, testFirstName, testLastName);
    String user2 = "test-2-" + System.currentTimeMillis();
    this.getBean().setTestData(user2, testFirstName, testLastName);
    String user3 = "test-3-" + System.currentTimeMillis();
    this.getBean().setTestData(user3, testFirstName, testLastName);
    IdmRoleDto role1 = helper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = helper.createAutomaticRole(role1.getId());
    helper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.username.getName(), null, user1);
    synchornizationService.setSynchronizationConfigId(config.getId());
    synchornizationService.process();
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3, OperationResultType.WARNING);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    IdmIdentityDto identity1 = identityService.getByUsername(user1);
    IdmIdentityDto identity2 = identityService.getByUsername(user2);
    IdmIdentityDto identity3 = identityService.getByUsername(user3);
    // we must change username, after create contract is also save identity (change state)
    identity1.setUsername(user1 + System.currentTimeMillis());
    identity1 = identityService.save(identity1);
    helper.createIdentityContact(identity1);
    helper.createIdentityContact(identity2);
    helper.createIdentityContact(identity3);
    List<IdmIdentityRoleDto> identityRoles1 = identityRoleService.findAllByIdentity(identity1.getId());
    List<IdmIdentityRoleDto> identityRoles2 = identityRoleService.findAllByIdentity(identity2.getId());
    List<IdmIdentityRoleDto> identityRoles3 = identityRoleService.findAllByIdentity(identity3.getId());
    assertEquals(0, identityRoles1.size());
    assertEquals(0, identityRoles2.size());
    assertEquals(0, identityRoles3.size());
    // enable test processor
    testIdentityProcessor.enable();
    synchornizationService.setSynchronizationConfigId(config.getId());
    synchornizationService.process();
    identityRoles1 = identityRoleService.findAllByIdentity(identity1.getId());
    identityRoles2 = identityRoleService.findAllByIdentity(identity2.getId());
    identityRoles3 = identityRoleService.findAllByIdentity(identity3.getId());
    assertEquals(1, identityRoles1.size());
    assertEquals(0, identityRoles2.size());
    assertEquals(0, identityRoles3.size());
    IdmIdentityRoleDto foundIdentityRole = identityRoles1.get(0);
    assertEquals(automaticRole.getId(), foundIdentityRole.getRoleTreeNode());
    // synchronization immediately recalculate is disabled
    int size = testIdentityProcessor.getRolesByUsername(user1).size();
    assertEquals(0, size);
    size = testIdentityProcessor.getRolesByUsername(user2).size();
    assertEquals(0, size);
    size = testIdentityProcessor.getRolesByUsername(user3).size();
    assertEquals(0, size);
}
Also used : SysSyncIdentityConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) DefaultSynchronizationServiceTest(eu.bcvsolutions.idm.acc.service.impl.DefaultSynchronizationServiceTest)

Aggregations

IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)56 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)44 Test (org.junit.Test)41 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)37 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)34 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)30 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)20 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)17 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)15 UUID (java.util.UUID)12 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)7 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)7 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)7 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)6 AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)5 IdmAutomaticRoleAttributeRuleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter)5 LocalDate (org.joda.time.LocalDate)5 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)4 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)4 RoleRequestException (eu.bcvsolutions.idm.core.api.exception.RoleRequestException)4