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())));
}
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())));
}
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());
}
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;
}
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);
}
Aggregations