Search in sources :

Example 41 with IdmEntityStateDto

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

the class IdmEntityStateControllerRestTest method testFindByCreated.

@Test
public void testFindByCreated() {
    UUID ownerOne = UUID.randomUUID();
    UUID ownerTwo = UUID.randomUUID();
    String ownerType = getHelper().createName();
    // 
    IdmEntityStateDto state = prepareDto();
    state.setOwnerId(ownerOne);
    state.setOwnerType(ownerType);
    IdmEntityStateDto stateOne = entityStateService.save(state);
    // 
    getHelper().waitForResult(null, 2, 1);
    // 
    state = prepareDto();
    state.setOwnerId(ownerTwo);
    state.setOwnerType(ownerType);
    IdmEntityStateDto stateTwo = entityStateService.save(state);
    // 
    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    parameters.set("createdFrom", stateOne.getCreated().truncatedTo(ChronoUnit.MILLIS).toString());
    parameters.set("ownerType", ownerType);
    List<IdmEntityStateDto> results = find(parameters);
    Assert.assertEquals(2, results.size());
    Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateOne.getId())));
    Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateTwo.getId())));
    // nanos are not persisted into db ...
    parameters.set("createdFrom", stateTwo.getCreated().truncatedTo(ChronoUnit.MILLIS).toString());
    results = find(parameters);
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateTwo.getId())));
    // 
    parameters.remove("createdFrom");
    parameters.set("createdTill", stateTwo.getCreated().truncatedTo(ChronoUnit.MILLIS).plus(1, ChronoUnit.MILLIS).toString());
    results = find(parameters);
    Assert.assertEquals(2, results.size());
    Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateOne.getId())));
    Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateTwo.getId())));
    // 
    parameters.set("createdTill", stateOne.getCreated().truncatedTo(ChronoUnit.MILLIS).plus(1, ChronoUnit.MILLIS).toString());
    results = find(parameters);
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateOne.getId())));
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Lists(com.google.common.collect.Lists) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) IdmEntityStateService(eu.bcvsolutions.idm.core.api.service.IdmEntityStateService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) MultiValueMap(org.springframework.util.MultiValueMap) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) UUID(java.util.UUID) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) ChronoUnit(java.time.temporal.ChronoUnit) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) UUID(java.util.UUID) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 42 with IdmEntityStateDto

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

the class IdmEntityStateControllerRestTest method testFindByOwnerAsCodeable.

/**
 * Find by owner as codeable
 */
@Test
public void testFindByOwnerAsCodeable() {
    IdmIdentityDto ownerOne = getHelper().createIdentity((GuardedString) null);
    UUID ownerTwo = UUID.randomUUID();
    // 
    IdmEntityStateDto state = prepareDto();
    state.setOwnerId(ownerOne.getId());
    state.setOwnerType(entityEventManager.getOwnerType(ownerOne));
    IdmEntityStateDto stateOne = entityStateService.save(state);
    // 
    state = prepareDto();
    state.setOwnerId(ownerTwo);
    state.setOwnerType(entityEventManager.getOwnerType(ownerOne));
    // other
    entityStateService.save(state);
    // 
    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    parameters.set("ownerId", ownerOne.getUsername());
    parameters.set("ownerType", entityEventManager.getOwnerType(ownerOne));
    // 
    List<IdmEntityStateDto> results = find(parameters);
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(stateOne.getId())));
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Lists(com.google.common.collect.Lists) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) IdmEntityStateService(eu.bcvsolutions.idm.core.api.service.IdmEntityStateService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) MultiValueMap(org.springframework.util.MultiValueMap) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) UUID(java.util.UUID) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) ChronoUnit(java.time.temporal.ChronoUnit) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 43 with IdmEntityStateDto

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

the class ContractSliceManagerTest method setDirtyStateAndReferentialIntegrityTest.

@Test
public void setDirtyStateAndReferentialIntegrityTest() {
    IdmIdentityDto identity = this.getHelper().createIdentity();
    // remove all contracts
    List<IdmIdentityContractDto> allByIdentity = contractService.findAllByIdentity(identity.getId());
    allByIdentity.forEach(contract -> {
        contractService.delete(contract);
    });
    IdmContractSliceDto slice = new IdmContractSliceDto();
    slice.setContractCode("test");
    slice.setIdentity(identity.getId());
    slice.setValidFrom(LocalDate.now().minusDays(5));
    slice.setValidTill(LocalDate.now().plusDays(5));
    slice.setContractValidFrom(LocalDate.now().minusDays(5));
    slice.setMain(true);
    EventContext<IdmContractSliceDto> context = contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.CREATE, slice, ImmutableMap.of(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, Boolean.TRUE)));
    IdmContractSliceDto sliceDto = context.getContent();
    // slice has skip recalculation and dirty state isn't create
    allByIdentity = contractService.findAllByIdentity(identity.getId());
    assertTrue(allByIdentity.isEmpty());
    List<IdmEntityStateDto> dirtyStates = findDirtyStatesForSlice(sliceDto.getId());
    assertFalse(dirtyStates.isEmpty());
    assertEquals(1, dirtyStates.size());
    contractSliceService.delete(sliceDto);
    dirtyStates = findDirtyStatesForSlice(sliceDto.getId());
    assertTrue(dirtyStates.isEmpty());
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 44 with IdmEntityStateDto

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

the class AdUserConnectorType method load.

@Override
public ConnectorTypeDto load(ConnectorTypeDto connectorType) {
    super.load(connectorType);
    if (!connectorType.isReopened()) {
        connectorType.getMetadata().put(REGENERATE_SCHEMA_SWITCH, Boolean.TRUE.toString());
        return connectorType;
    }
    connectorType.getMetadata().put(REGENERATE_SCHEMA_SWITCH, Boolean.FALSE.toString());
    // Load the system.
    SysSystemDto systemDto = (SysSystemDto) connectorType.getEmbedded().get(SYSTEM_DTO_KEY);
    Assert.notNull(systemDto, "System must exists!");
    connectorType.getMetadata().put(SYSTEM_NAME, systemDto.getName());
    Map<String, String> metadata = connectorType.getMetadata();
    IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(systemDto);
    // Find attribute with port.
    metadata.put(PORT, getValueFromConnectorInstance(PORT, systemDto, connectorFormDef));
    // Find attribute with host.
    metadata.put(HOST, getValueFromConnectorInstance(HOST, systemDto, connectorFormDef));
    // Find attribute with user.
    metadata.put(USER, getValueFromConnectorInstance(PRINCIPAL, systemDto, connectorFormDef));
    // Find attribute with ssl switch.
    metadata.put(SSL_SWITCH, getValueFromConnectorInstance(SSL, systemDto, connectorFormDef));
    IdmFormDefinitionDto operationOptionsFormDefinition = this.getSystemService().getOperationOptionsConnectorFormDefinition(systemDto);
    if (operationOptionsFormDefinition != null) {
        // Find attribute with domain.
        metadata.put(DOMAIN_KEY, getValueFromConnectorInstance(DOMAIN_KEY, systemDto, operationOptionsFormDefinition));
        // Find attribute with container with existed users.
        metadata.put(USER_SEARCH_CONTAINER_KEY, getValueFromConnectorInstance(USER_SEARCH_CONTAINER_KEY, systemDto, operationOptionsFormDefinition));
        // Find attribute with container with new users.
        metadata.put(NEW_USER_CONTAINER_KEY, getValueFromConnectorInstance(NEW_USER_CONTAINER_KEY, systemDto, operationOptionsFormDefinition));
        // Find attribute with container with deleted users.
        metadata.put(DELETE_USER_CONTAINER_KEY, getValueFromConnectorInstance(DELETE_USER_CONTAINER_KEY, systemDto, operationOptionsFormDefinition));
    }
    // Load the provisioning mapping.
    SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
    mappingFilter.setSystemId(systemDto.getId());
    mappingFilter.setOperationType(SystemOperationType.PROVISIONING);
    SysSystemMappingDto mappingDto = systemMappingService.find(mappingFilter, null).getContent().stream().min(Comparator.comparing(SysSystemMappingDto::getCreated)).orElse(null);
    if (mappingDto != null) {
        connectorType.getEmbedded().put(DefaultConnectorType.MAPPING_DTO_KEY, mappingDto);
        connectorType.getMetadata().put(MAPPING_ID, mappingDto.getId().toString());
        connectorType.getMetadata().put(PROTECTED_MODE_SWITCH_KEY, String.valueOf(mappingDto.isProtectionEnabled()));
    }
    // Load the sync mapping.
    SysSystemMappingFilter syncMappingFilter = new SysSystemMappingFilter();
    syncMappingFilter.setSystemId(systemDto.getId());
    syncMappingFilter.setOperationType(SystemOperationType.SYNCHRONIZATION);
    SysSystemMappingDto syncMappingDto = systemMappingService.find(syncMappingFilter, null).getContent().stream().min(Comparator.comparing(SysSystemMappingDto::getCreated)).orElse(null);
    if (syncMappingDto != null) {
        connectorType.getMetadata().put(MAPPING_SYNC_ID, syncMappingDto.getId().toString());
    }
    // Load the pairing sync (beware by name!).
    SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
    syncFilter.setSystemId(systemDto.getId());
    syncFilter.setName(PAIRING_SYNC_NAME);
    AbstractSysSyncConfigDto syncDto = syncConfigService.find(syncFilter, null).getContent().stream().min(Comparator.comparing(AbstractDto::getCreated)).orElse(null);
    if (syncDto != null) {
        connectorType.getMetadata().put(PAIRING_SYNC_ID, syncDto.getId().toString());
    }
    IdmEntityStateFilter entityStateFilter = new IdmEntityStateFilter();
    entityStateFilter.setOwnerId(systemDto.getId());
    entityStateFilter.setOwnerType(entityStateManager.getOwnerType(systemDto.getClass()));
    entityStateFilter.setResultCode(AccResultCode.WIZARD_AD_CREATED_TEST_USER_DN.getCode());
    IdmEntityStateDto entityStateDto = entityStateManager.findStates(entityStateFilter, null).stream().findFirst().orElse(null);
    Object dn = null;
    if (entityStateDto != null && entityStateDto.getResult() != null && entityStateDto.getResult().getModel() != null && entityStateDto.getResult().getModel().getParameters() != null) {
        dn = entityStateDto.getResult().getModel().getParameters().get(TEST_CREATED_USER_DN_KEY);
    }
    if (dn instanceof String) {
        String testUserDN = (String) dn;
        connectorType.getMetadata().put(ENTITY_STATE_WITH_TEST_CREATED_USER_DN_KEY, entityStateDto.getId().toString());
        connectorType.getMetadata().put(TEST_CREATED_USER_DN_KEY, testUserDN);
    }
    // Load a schema.
    SysSchemaObjectClassFilter schemaFilter = new SysSchemaObjectClassFilter();
    schemaFilter.setSystemId(systemDto.getId());
    schemaFilter.setObjectClassName(getSchemaType());
    SysSchemaObjectClassDto schemaDto = schemaObjectClassService.find(schemaFilter, null).getContent().stream().findFirst().orElse(null);
    if (schemaDto != null) {
        connectorType.getMetadata().put(SCHEMA_ID_KEY, schemaDto.getId().toString());
    }
    return connectorType;
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) SysSchemaObjectClassFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaObjectClassFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter)

Example 45 with IdmEntityStateDto

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

the class AdUserConnectorType method executeAssignTestUserToGroup.

/**
 * Execute permission test for assign user to group.
 */
protected void executeAssignTestUserToGroup(ConnectorTypeDto connectorType) {
    String systemId = connectorType.getMetadata().get(SYSTEM_DTO_KEY);
    Assert.notNull(systemId, "System ID cannot be null!");
    SysSystemDto systemDto = this.getSystemService().get(systemId);
    connectorType.getEmbedded().put(SYSTEM_DTO_KEY, systemDto);
    IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(systemDto);
    String port = getValueFromConnectorInstance(PORT, systemDto, connectorFormDef);
    String host = getValueFromConnectorInstance(HOST, systemDto, connectorFormDef);
    String user = getValueFromConnectorInstance(PRINCIPAL, systemDto, connectorFormDef);
    boolean ssl = Boolean.parseBoolean(getValueFromConnectorInstance(SSL, systemDto, connectorFormDef));
    String password = getConfidentialValueFromConnectorInstance(CREDENTIALS, systemDto, connectorFormDef);
    String testUser = connectorType.getMetadata().get(TEST_USERNAME_KEY);
    Assert.notNull(testUser, "Test username cannot be null!");
    String entityStateId = connectorType.getMetadata().get(ENTITY_STATE_WITH_TEST_CREATED_USER_DN_KEY);
    Assert.notNull(entityStateId, "Entity state ID with created test user DN cannot be null!");
    // Find Domain Users group DN.
    String groupDN = this.findDn("(&(CN=Domain Guests)(objectClass=group))", port, host, user, password, ssl);
    if (Strings.isBlank(groupDN)) {
        throw new ResultCodeException(AccResultCode.WIZARD_AD_GROUP_NOT_FOUND, ImmutableMap.of("dn", groupDN));
    }
    // As protection against unauthorized deletion of a user other than the one
    // created, the DN will be loaded from the entity state.
    IdmEntityStateDto entityStateDto = entityStateService.get(entityStateId);
    Assert.notNull(entityStateDto, "Entity state with created test user DN cannot be null!");
    ResultModel model = entityStateDto.getResult().getModel();
    Object dn = model.getParameters().get(TEST_CREATED_USER_DN_KEY);
    Assert.isTrue(dn instanceof String, "Test domain users cannot be null!");
    String testUserDN = (String) dn;
    // Assign test user to the group.
    assignTestUserToGroup(testUserDN, groupDN, port, host, user, password, ssl);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Aggregations

IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)77 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)43 Test (org.junit.Test)41 UUID (java.util.UUID)40 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)33 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)30 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)30 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)24 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)23 List (java.util.List)21 Autowired (org.springframework.beans.factory.annotation.Autowired)21 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)20 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)19 Transactional (org.springframework.transaction.annotation.Transactional)19 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)18 Lists (com.google.common.collect.Lists)15 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)15 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)15 Assert (org.junit.Assert)14 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)13