Search in sources :

Example 6 with IdmIdentity_

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity_ in project CzechIdMng by bcvsolutions.

the class TestFilterReportExecutor method generateData.

@Override
@SuppressWarnings("rawtypes")
protected IdmAttachmentDto generateData(RptReportDto report) {
    try {
        IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
        // 
        List usernames = (List) formInstance.toPersistentValues(IdmIdentity_.username.getName());
        List<IdmIdentityDto> results = TestReportExecutor.identities.stream().filter(identity -> {
            return ObjectUtils.isEmpty(usernames) || usernames.contains(identity.getUsername());
        }).collect(Collectors.toList());
        return createAttachment(report, IOUtils.toInputStream(getMapper().writeValueAsString(results)));
    } catch (FileNotFoundException | JsonProcessingException ex) {
        throw new ReportGenerateException(report.getName(), ex);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Description(org.springframework.context.annotation.Description) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) ObjectUtils(org.springframework.util.ObjectUtils) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) AbstractReportExecutor(eu.bcvsolutions.idm.rpt.api.executor.AbstractReportExecutor) FileNotFoundException(java.io.FileNotFoundException) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 7 with IdmIdentity_

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity_ in project CzechIdMng by bcvsolutions.

the class IdmAuditControllerRestTest method testFindEntityByUsername.

@Test
public void testFindEntityByUsername() throws Exception {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    MultiValueMap<String, String> filter = new LinkedMultiValueMap<>();
    filter.set("ownerType", IdmIdentity.class.getCanonicalName());
    filter.set(IdmIdentity_.username.getName(), identity.getUsername());
    // 
    List<IdmAuditDto> find = find(filter, "/audits/search/entity");
    // 
    Assert.assertFalse(find.isEmpty());
    Assert.assertTrue(find.stream().allMatch(a -> a.getOwnerId().equals(identity.getId().toString())));
    // 
    // test get revision
    String response = getMockMvc().perform(get(BaseController.BASE_PATH + "/audits/" + find.get(0).getId()).with(authentication(getAdminAuthentication())).params(filter).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
    // FIXME: jsou deserialization doesn't work ...
    // IdmAuditDto audit = getMapper().convertValue(response, IdmAuditDto.class);
    // //
    // Assert.assertNotNull(audit);
    // Assert.assertEquals(identity.getId().toString(), audit.getOwnerId());
    // ugly workaround:
    Assert.assertTrue(response.contains(identity.getId().toString()));
    // username => entity Id is set
    Assert.assertTrue(response.contains(identity.getUsername()));
    // 
    // delete identity - check revision values is set
    identityService.delete(identity);
    Assert.assertNull(identityService.get(identity));
    // 
    filter = new LinkedMultiValueMap<>();
    filter.set("type", IdmIdentity.class.getCanonicalName());
    filter.set("entityId", identity.getId().toString());
    response = getMockMvc().perform(get(BaseController.BASE_PATH + "/audits/search/quick").with(authentication(getAdminAuthentication())).params(filter).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
    // 
    // ugly workaround:
    Assert.assertTrue(response.contains(identity.getId().toString()));
    // username => entity Id is set
    Assert.assertTrue(response.contains(identity.getUsername()));
}
Also used : IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Autowired(org.springframework.beans.factory.annotation.Autowired) MultiValueMap(org.springframework.util.MultiValueMap) Test(org.junit.Test) UUID(java.util.UUID) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) List(java.util.List) BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) IdmAuditService(eu.bcvsolutions.idm.core.api.audit.service.IdmAuditService) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) BaseController(eu.bcvsolutions.idm.core.api.rest.BaseController) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Transactional(org.springframework.transaction.annotation.Transactional) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Test(org.junit.Test) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest)

Example 8 with IdmIdentity_

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity_ in project CzechIdMng by bcvsolutions.

the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testRecalculationWithManyIdentities.

@Test
@Ignore
public void testRecalculationWithManyIdentities() {
    String description = getHelper().createName();
    List<IdmIdentityDto> identities = new ArrayList<IdmIdentityDto>();
    try {
        // 
        for (int index = 0; index < 187; index++) {
            IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
            identity.setDescription(description);
            identityService.save(identity);
            identities.add(identity);
        }
        assertEquals(187, identities.size());
        IdmRoleDto role = getHelper().createRole();
        IdmRoleDto subRole = getHelper().createRole();
        getHelper().createRoleComposition(role, subRole);
        IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
        getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.description.getName(), null, description);
        // turn on async processing
        getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
        // 
        // execute recalculation
        automaticRoleAttributeService.recalculate(automaticRole.getId());
        // 
        // wait for result
        IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
        filter.setAutomaticRoleId(automaticRole.getId());
        getHelper().waitForResult(res -> {
            return identityRoleService.count(filter) != 187;
        }, 1000, 300);
        List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
        Assert.assertEquals(187, identityRoles.size());
        for (IdmIdentityDto identity : identities) {
            List<IdmIdentityRoleDto> allByIdentity = identityRoleService.findAllByIdentity(identity.getId());
            Assert.assertEquals(2, allByIdentity.size());
            Assert.assertTrue(allByIdentity.stream().anyMatch(ir -> automaticRole.getId().equals(ir.getAutomaticRole()) && ir.getRole().equals(role.getId())));
            Assert.assertTrue(allByIdentity.stream().anyMatch(ir -> ir.getDirectRole() != null && ir.getRole().equals(subRole.getId())));
        }
    } finally {
        // turn off async processing
        getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
        identityService.deleteAll(identities);
    }
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ZonedDateTime(java.time.ZonedDateTime) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) BaseCodeList(eu.bcvsolutions.idm.core.eav.api.domain.BaseCodeList) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ProcessAllAutomaticRoleByAttributeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAllAutomaticRoleByAttributeTaskExecutor) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) Assert.fail(org.junit.Assert.fail) Sort(org.springframework.data.domain.Sort) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) PageRequest(org.springframework.data.domain.PageRequest) IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) UUID(java.util.UUID) Instant(java.time.Instant) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState) ZoneId(java.time.ZoneId) Serializable(java.io.Serializable) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) IdmEmailLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmEmailLogRepository) Assert.assertFalse(org.junit.Assert.assertFalse) ProcessAutomaticRoleByAttributeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByAttributeTaskExecutor) LocalDate(java.time.LocalDate) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) IdmAutomaticRoleAttributeRuleService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmAutomaticRoleAttributeService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeService) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) IdmNotificationLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationLogRepository) ArrayList(java.util.ArrayList) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) Lists(com.google.common.collect.Lists) IdmFormProjectionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormProjectionService) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) BaseFaceType(eu.bcvsolutions.idm.core.eav.api.domain.BaseFaceType) Direction(org.springframework.data.domain.Sort.Direction) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) IdmAutomaticRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Assert.assertNull(org.junit.Assert.assertNull) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) Ignore(org.junit.Ignore) AutomaticRoleAttributeRuleComparison(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) Ignore(org.junit.Ignore) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)8 IdmIdentity_ (eu.bcvsolutions.idm.core.model.entity.IdmIdentity_)8 List (java.util.List)7 Test (org.junit.Test)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)5 UUID (java.util.UUID)5 AutomaticRoleAttributeRuleComparison (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison)4 AutomaticRoleAttributeRuleType (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType)4 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)4 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)4 IdmAutomaticRoleAttributeService (eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeService)4 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)4 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)4 Assert (org.junit.Assert)4 Lists (com.google.common.collect.Lists)3 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)3