use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method clearStateExecutorTest.
@Test
public void clearStateExecutorTest() {
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(1));
slice.setValidTill(LocalDate.now().plusDays(5));
slice.setContractValidFrom(LocalDate.now().minusDays(50));
slice.setMain(true);
IdmContractSliceDto sliceTwo = new IdmContractSliceDto();
sliceTwo.setContractCode("test");
sliceTwo.setIdentity(identity.getId());
sliceTwo.setValidFrom(LocalDate.now().minusDays(10));
sliceTwo.setValidTill(LocalDate.now().minusDays(2));
sliceTwo.setContractValidFrom(LocalDate.now().minusDays(50));
sliceTwo.setMain(true);
EventContext<IdmContractSliceDto> eventContextOne = contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.CREATE, slice, ImmutableMap.of(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, Boolean.TRUE)));
EventContext<IdmContractSliceDto> eventContextTwo = contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.CREATE, sliceTwo, ImmutableMap.of(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, Boolean.TRUE)));
// slice has skip recalculation and dirty state isn't create
allByIdentity = contractService.findAllByIdentity(identity.getId());
assertTrue(allByIdentity.isEmpty());
List<IdmEntityStateDto> dirtyStates = findDirtyStatesForSlice(null);
assertFalse(dirtyStates.isEmpty());
assertEquals(2, dirtyStates.size());
ClearDirtyStateForContractSliceTaskExecutor executor = new ClearDirtyStateForContractSliceTaskExecutor();
OperationResult result = longRunningTaskManager.executeSync(executor);
assertEquals(OperationState.EXECUTED, result.getState());
dirtyStates = findDirtyStatesForSlice(null);
assertTrue(dirtyStates.isEmpty());
assertEquals(0, dirtyStates.size());
allByIdentity = contractService.findAllByIdentity(identity.getId());
assertEquals(1, allByIdentity.size());
IdmIdentityContractDto contractDto = allByIdentity.get(0);
assertTrue(contractDto.getControlledBySlices());
assertEquals(LocalDate.now().minusDays(50), contractDto.getValidFrom());
// Delete unused slices
contractSliceService.delete(eventContextOne.getContent());
contractSliceService.delete(eventContextTwo.getContent());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method skipRecalculationTest.
@Test
public void skipRecalculationTest() {
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> eventContext = contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.CREATE, slice, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
// slice has skip recalculation and dirty state isn't create
allByIdentity = contractService.findAllByIdentity(identity.getId());
assertTrue(allByIdentity.isEmpty());
List<IdmEntityStateDto> dirtyStates = findDirtyStatesForSlice(null);
assertTrue(dirtyStates.isEmpty());
// Delete unused slice
contractSliceService.delete(eventContext.getContent());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmEntityStateServiceIntegrationTest method testReferentialIntegrity.
@Test
public void testReferentialIntegrity() {
IdmEntityEventDto entityEvent = new IdmEntityEventDto();
entityEvent.setOwnerType("empty");
entityEvent.setEventType("empty");
entityEvent.setOwnerId(UUID.randomUUID());
entityEvent.setInstanceId("empty");
entityEvent.setResult(new OperationResultDto(OperationState.BLOCKED));
entityEvent.setPriority(PriorityType.NORMAL);
entityEvent = entityEventService.save(entityEvent);
//
Assert.assertNotNull(entityEvent.getId());
//
IdmEntityStateDto entityState = new IdmEntityStateDto(entityEvent);
entityState.setResult(new OperationResultDto(OperationState.BLOCKED));
entityState = entityStateService.save(entityState);
//
Assert.assertNotNull(entityState.getId());
//
entityEventService.delete(entityEvent);
//
Assert.assertNull(entityEventService.get(entityEvent));
Assert.assertNull(entityStateService.get(entityState));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class AdUserConnectorType method executeDeleteUserTest.
/**
* Execute permission test for delete user from AD.
*/
protected void executeDeleteUserTest(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 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!");
// 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 testDomainUsers = (String) dn;
// Delete test user from AD.
deleteTestUser(testDomainUsers, port, host, user, password, ssl);
// Delete entity state.
entityStateService.delete(entityStateDto);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class AdUserConnectorType method executeCreateUserTest.
/**
* Execute test for check permissions for create account/user on the AD.
*/
protected void executeCreateUserTest(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 usersContainer = connectorType.getMetadata().get(TEST_USER_CONTAINER_KEY);
Assert.notNull(usersContainer, "Test user container cannot be null!");
// Check exist of container on the AD.
String usersContainerDN = this.findDn(MessageFormat.format("(&(distinguishedName={0})(|(objectClass=container)(objectClass=organizationalUnit)))", usersContainer), port, host, user, password, ssl);
if (Strings.isBlank(usersContainerDN)) {
throw new ResultCodeException(AccResultCode.WIZARD_AD_CONTAINER_NOT_FOUND, ImmutableMap.of("dn", usersContainer));
}
String createdUserDN = createTestUser(testUser, usersContainerDN, port, host, user, password, ssl);
// As protection against unauthorized deletion of a user other than the one
// created, the DN on the BE will be in the entity state.
IdmEntityStateDto entityStateWithTestUser = createEntityStateWithTestUser(systemDto, createdUserDN);
connectorType.getMetadata().put(ENTITY_STATE_WITH_TEST_CREATED_USER_DN_KEY, entityStateWithTestUser.getId().toString());
connectorType.getMetadata().put(TEST_CREATED_USER_DN_KEY, createdUserDN);
}
Aggregations