Search in sources :

Example 36 with IdmIdentityFilter

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

the class IdentityFilterTest method testPropertyValueFilter.

@Test
public void testPropertyValueFilter() {
    IdmIdentityDto person = getIdmIdentity("ThisIsTestName012", "ThisIsTestName012", "ThisIsTestName012@gemail.eu", "100000012", false);
    IdmIdentityFilter filter = new IdmIdentityFilter();
    filter.setProperty(IdmIdentity_.username.getName());
    filter.setValue(person.getUsername());
    Page<IdmIdentityDto> result = identityService.find(filter, null);
    assertEquals("Wrong Set Property and Value - username", 1, result.getTotalElements());
    assertEquals("Wrong Property an Value - username user ID", person.getId(), result.getContent().get(0).getId());
    filter.setProperty(IdmIdentity_.firstName.getName());
    filter.setValue(person.getFirstName());
    result = identityService.find(filter, null);
    assertEquals("Wrong Set Property and Value - firstname", 1, result.getTotalElements());
    assertEquals("Wrong Property an Value - firstname user ID", person.getId(), result.getContent().get(0).getId());
    filter.setProperty(IdmIdentity_.lastName.getName());
    filter.setValue(person.getLastName());
    result = identityService.find(filter, null);
    assertEquals("Wrong Set Property and Value - lastname", 1, result.getTotalElements());
    assertEquals("Wrong Property an Value - lastname user ID", person.getId(), result.getContent().get(0).getId());
    filter.setProperty(IdmIdentity_.email.getName());
    filter.setValue(person.getEmail());
    result = identityService.find(filter, null);
    assertEquals("Wrong Set Property and Value - email", 1, result.getTotalElements());
    assertEquals("Wrong Property an Value - email user ID", person.getId(), result.getContent().get(0).getId());
}
Also used : IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 37 with IdmIdentityFilter

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

the class AutomaticRoleAttributeRuleDeleteProcessor method process.

@Override
public EventResult<IdmAutomaticRoleAttributeRuleDto> process(EntityEvent<IdmAutomaticRoleAttributeRuleDto> event) {
    IdmAutomaticRoleAttributeRuleDto dto = event.getContent();
    // 
    List<IdmAutomaticRoleAttributeRuleDto> allRules = automactiRoleAttributeRuleService.findAllRulesForAutomaticRole(dto.getAutomaticRoleAttribute());
    // by default is skip value null => false
    if (!this.getBooleanProperty(SKIP_CHECK_LAST_RULE, event.getProperties())) {
        // it's last rule, remove all identity role
        if (allRules.size() == 1 && dto.getId().equals(allRules.get(0).getId())) {
            // before we start delete identity role, we check how many identities has the auto role
            // if doesn't exist identities that has the role, skip remove
            IdmIdentityFilter identityFilter = new IdmIdentityFilter();
            long totalElements = identityService.find(identityFilter, new PageRequest(0, 1)).getTotalElements();
            if (totalElements > 0) {
                UUID automaticRoleAttributeId = dto.getAutomaticRoleAttribute();
                removeAllRoles(automaticRoleAttributeId);
                // 
                // we also set concept to false
                IdmAutomaticRoleAttributeDto roleAttributeDto = automaticRoleAttributeRuleService.get(automaticRoleAttributeId);
                roleAttributeDto.setConcept(false);
                roleAttributeDto = automaticRoleAttributeRuleService.save(roleAttributeDto);
            }
        }
    }
    UUID automaticRuleId = dto.getId();
    // Find all automatic role requests and remove relation on rule
    if (automaticRuleId != null) {
        IdmAutomaticRoleAttributeRuleRequestFilter automaticRoleRequestFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
        automaticRoleRequestFilter.setRuleId(automaticRuleId);
        ruleRequestService.find(automaticRoleRequestFilter, null).getContent().forEach(request -> {
            request.setRule(null);
            ruleRequestService.save(request);
        });
    }
    // 
    automactiRoleAttributeRuleService.deleteInternal(dto);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmAutomaticRoleAttributeRuleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter) PageRequest(org.springframework.data.domain.PageRequest) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) UUID(java.util.UUID) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)

Example 38 with IdmIdentityFilter

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

the class IdentitySynchronizationExecutor method findByAttribute.

@Override
protected IdmIdentityDto findByAttribute(String idmAttributeName, String value) {
    CorrelationFilter filter = getEntityFilter();
    filter.setProperty(idmAttributeName);
    filter.setValue(value);
    List<IdmIdentityDto> entities = identityService.find((IdmIdentityFilter) filter, null).getContent();
    if (CollectionUtils.isEmpty(entities)) {
        return null;
    }
    if (entities.size() > 1) {
        throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_CORRELATION_TO_MANY_RESULTS, ImmutableMap.of("correlationAttribute", idmAttributeName, "value", value));
    }
    if (entities.size() == 1) {
        return entities.get(0);
    }
    return null;
}
Also used : CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 39 with IdmIdentityFilter

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

the class ExecuteScriptTaskExecutorTest method testExeciteScriptWithResult.

@Test
public void testExeciteScriptWithResult() {
    // remove previous long running task
    List<IdmLongRunningTaskDto> tasks = longRunningTaskService.find(null).getContent();
    for (IdmLongRunningTaskDto task : tasks) {
        longRunningTaskService.delete(task);
    }
    IdmScriptDto scriptDto = new IdmScriptDto();
    scriptDto.setCode(TEST_SCRIPT_CODE + "_3");
    scriptDto.setName(TEST_SCRIPT_CODE + "_3");
    scriptDto.setCategory(IdmScriptCategory.SYSTEM);
    StringBuilder builder = new StringBuilder();
    builder.append("import eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto;\n");
    builder.append("task.setCounter(0l);\n");
    builder.append("task.setCount(5l);\n");
    builder.append("for (int index = 0; index < 5; index++) {\n");
    builder.append("    IdmIdentityDto dto = new IdmIdentityDto();\n");
    builder.append("    dto.setUsername('test-execute-' + index);\n");
    builder.append("    dto.setLastName('test-execute-' + index);\n");
    builder.append("    dto.setFirstName('' + index);\n");
    builder.append("    identityService.save(dto);\n");
    builder.append("    task.increaseCounter();\n");
    builder.append("    task.updateState();\n");
    builder.append("}\n");
    scriptDto.setScript(builder.toString());
    scriptDto = scriptService.save(scriptDto);
    prepareAuthForTestScript(scriptDto);
    IdmScriptAuthorityDto authDto = new IdmScriptAuthorityDto();
    authDto.setType(ScriptAuthorityType.SERVICE);
    authDto.setClassName("eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmIdentityService");
    authDto.setScript(scriptDto.getId());
    authDto.setService("identityService");
    scriptAuthorityService.save(authDto);
    authDto = new IdmScriptAuthorityDto();
    authDto.setType(ScriptAuthorityType.CLASS_NAME);
    authDto.setClassName("eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto");
    authDto.setScript(scriptDto.getId());
    scriptAuthorityService.save(authDto);
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("scriptCode", TEST_SCRIPT_CODE + "_3");
    taskExecutor.init(parameters);
    LongRunningFutureTask<Boolean> futureTask = manager.execute(taskExecutor);
    try {
        assertEquals(Boolean.TRUE, futureTask.getFutureTask().get());
    } catch (InterruptedException | ExecutionException e) {
        fail(e.getMessage());
    }
    IdmLongRunningTaskDto longRunningTask = longRunningTaskService.get(taskExecutor.getLongRunningTaskId());
    assertEquals(OperationState.EXECUTED, longRunningTask.getResult().getState());
    assertEquals(5, longRunningTask.getCount().longValue());
    assertEquals(5, longRunningTask.getCounter().longValue());
    IdmIdentityFilter identityFilter = new IdmIdentityFilter();
    identityFilter.setText("test-execute-");
    List<IdmIdentityDto> identities = identityService.find(identityFilter, new PageRequest(0, 20, new Sort(Direction.ASC, IdmIdentity_.firstName.getName()))).getContent();
    assertEquals(5, identities.size());
    for (int index = 0; index < 5; index++) {
        assertEquals(String.valueOf(index), identities.get(index).getFirstName());
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) HashMap(java.util.HashMap) IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) PageRequest(org.springframework.data.domain.PageRequest) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) Sort(org.springframework.data.domain.Sort) ExecutionException(java.util.concurrent.ExecutionException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)39 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)31 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)26 Test (org.junit.Test)26 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)9 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)8 UUID (java.util.UUID)7 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)6 SysSyncIdentityConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto)5 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)5 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)5 DefaultSynchronizationServiceTest (eu.bcvsolutions.idm.acc.service.impl.DefaultSynchronizationServiceTest)5 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)5 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)5 PageRequest (org.springframework.data.domain.PageRequest)5 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)4 Sort (org.springframework.data.domain.Sort)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 IdmScriptAuthorityDto (eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto)2 IdmScriptDto (eu.bcvsolutions.idm.core.api.dto.IdmScriptDto)2