use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto 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.eav.api.dto.IdmFormDefinitionDto 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);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class AdGroupConnectorTypeTest method createMemberSystem.
private SysSystemDto createMemberSystem() {
ConnectorType connectorType = connectorManager.getConnectorType(MockAdUserConnectorType.NAME);
ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
SysSystemDto systemDto = createSystem(this.getHelper().createName(), connectorTypeDto);
connectorTypeDto.getMetadata().put(MockAdUserConnectorType.SYSTEM_DTO_KEY, systemDto.getId().toString());
String newUserContainerMock = this.getHelper().createName();
connectorTypeDto.getMetadata().put(MockAdUserConnectorType.NEW_USER_CONTAINER_KEY, newUserContainerMock);
String userContainerMock = this.getHelper().createName();
connectorTypeDto.getMetadata().put(MockAdUserConnectorType.USER_SEARCH_CONTAINER_KEY, userContainerMock);
String deletedUserContainerMock = this.getHelper().createName();
connectorTypeDto.getMetadata().put(MockAdUserConnectorType.DELETE_USER_CONTAINER_KEY, deletedUserContainerMock);
String domainMock = this.getHelper().createName();
connectorTypeDto.getMetadata().put(MockAdUserConnectorType.DOMAIN_KEY, domainMock);
connectorTypeDto.setWizardStepName(MockAdUserConnectorType.STEP_FOUR);
// Generate mock schema.
generateMockMemberSchema(systemDto);
// Execute step four.
connectorManager.execute(connectorTypeDto);
// Check containers on the system's operationOptions.
systemDto = systemService.get(systemDto.getId());
IdmFormDefinitionDto operationOptionsFormDefinition = systemService.getOperationOptionsConnectorFormDefinition(systemDto);
String newUserContainer = getValueFromConnectorInstance(MockAdUserConnectorType.NEW_USER_CONTAINER_KEY, systemDto, operationOptionsFormDefinition);
assertEquals(newUserContainerMock, newUserContainer);
String deletedUserContainer = getValueFromConnectorInstance(MockAdUserConnectorType.DELETE_USER_CONTAINER_KEY, systemDto, operationOptionsFormDefinition);
// Protected mode is not active -> delete user container should be null.
assertNull(deletedUserContainer);
String searchUserContainer = getValueFromConnectorInstance(MockAdUserConnectorType.USER_SEARCH_CONTAINER_KEY, systemDto, operationOptionsFormDefinition);
assertEquals(userContainerMock, searchUserContainer);
String domain = getValueFromConnectorInstance(MockAdUserConnectorType.DOMAIN_KEY, systemDto, operationOptionsFormDefinition);
assertEquals(domainMock, domain);
// Check created schema attributes.
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(systemDto.getId());
List<SysSchemaAttributeDto> attributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
assertTrue(attributes.stream().anyMatch(attribute -> IcAttributeInfo.NAME.equals(attribute.getName())));
assertTrue(attributes.stream().anyMatch(attribute -> IcAttributeInfo.PASSWORD.equals(attribute.getName())));
assertTrue(attributes.stream().anyMatch(attribute -> IcAttributeInfo.ENABLE.equals(attribute.getName())));
assertTrue(attributes.stream().anyMatch(attribute -> MockAdUserConnectorType.LDAP_GROUPS_ATTRIBUTE.equals(attribute.getName())));
assertTrue(attributes.stream().anyMatch(attribute -> MockAdUserConnectorType.SAM_ACCOUNT_NAME_ATTRIBUTE.equals(attribute.getName())));
// Check created schema attributes.
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemId(systemDto.getId());
List<SysSystemAttributeMappingDto> attributeMappingDtos = attributeMappingService.find(attributeMappingFilter, null).getContent();
assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> IcAttributeInfo.NAME.equals(attribute.getName())));
assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> IcAttributeInfo.PASSWORD.equals(attribute.getName())));
assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> IcAttributeInfo.ENABLE.equals(attribute.getName())));
assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> MockAdUserConnectorType.LDAP_GROUPS_ATTRIBUTE.equals(attribute.getName())));
assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> MockAdUserConnectorType.LDAP_GROUPS_ATTRIBUTE.equals(attribute.getName()) && AttributeMappingStrategyType.MERGE == attribute.getStrategyType()));
assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> MockAdUserConnectorType.SAM_ACCOUNT_NAME_ATTRIBUTE.equals(attribute.getName())));
return systemDto;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class AdUserConnectorTypeTest method testReopenSystemWithoutOptionsAttributes.
@Test
public void testReopenSystemWithoutOptionsAttributes() {
ConnectorType connectorType = connectorManager.getConnectorType(MockAdUserConnectorType.NAME);
ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
SysSystemDto systemDto = createSystem(this.getHelper().createName(), connectorTypeDto);
connectorTypeDto.getMetadata().put(MockAdUserConnectorType.SYSTEM_DTO_KEY, systemDto.getId().toString());
IdmFormDefinitionDto operationOptionsConnectorFormDefinition = systemService.getOperationOptionsConnectorFormDefinition(systemDto);
// Try to find attribute for one of container. If exist -> change code = simulate delete.
IdmFormAttributeDto userSearchContainerAttribute = operationOptionsConnectorFormDefinition.getMappedAttributeByCode(MockAdUserConnectorType.USER_SEARCH_CONTAINER_KEY);
if (userSearchContainerAttribute != null) {
userSearchContainerAttribute.setCode(getHelper().createName());
formService.saveAttribute(userSearchContainerAttribute);
}
connectorType = connectorManager.getConnectorType(MockAdUserConnectorType.NAME);
connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
connectorTypeDto.setReopened(true);
connectorTypeDto.getEmbedded().put(MockAdUserConnectorType.SYSTEM_DTO_KEY, systemDto);
connectorTypeDto.getMetadata().put(MockAdUserConnectorType.SYSTEM_DTO_KEY, systemDto.getId().toString());
ConnectorTypeDto loadedConnectorTypeDto = connectorManager.load(connectorTypeDto);
assertNotNull(loadedConnectorTypeDto);
// Clean
systemService.delete(systemDto);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultFormService method saveAttributeValues.
/**
* Save single attribute values. Main business logic is here => all method ends here.
*
* @param ownerEntity
* @param attribute
* @param previousValues
* @param newValues
* @param permission
* @return
*/
private List<IdmFormValueDto> saveAttributeValues(FormableEntity ownerEntity, IdmFormAttributeDto attribute, List<IdmFormValueDto> previousValues, List<IdmFormValueDto> newValues, BasePermission... permission) {
//
IdmFormDefinitionDto formDefinition = getCachedDefinition(attribute.getFormDefinition());
FormValueService<FormableEntity> formValueService = getFormValueService(ownerEntity);
List<IdmFormValueDto> results = new ArrayList<>();
// ordered by seq
Map<UUID, IdmFormValueDto> unprocessedPreviousValues = new LinkedHashMap<>();
if (CollectionUtils.isNotEmpty(previousValues)) {
previousValues.forEach(previousValue -> {
unprocessedPreviousValues.put(previousValue.getId(), previousValue);
});
}
//
if (newValues == null || newValues.isEmpty()) {
// confidential values has to removed directly, they could not be sent with form (only changed values)
if (!attribute.isConfidential()) {
// delete previous attributes
unprocessedPreviousValues.values().forEach(value -> {
formValueService.delete(value, permission);
if (value.getPersistentType() == PersistentType.ATTACHMENT) {
// delete attachment - permissions are evaluated before
attachmentManager.deleteAttachments(value.getId(), attachmentManager.getOwnerType(formValueService.getEntityClass()));
}
LOG.trace("FormValue [{}:{}] for owner [{}] was deleted", value.getFormAttribute(), value.getId(), ownerEntity);
});
}
return results;
}
//
if (!attribute.isMultiple() && newValues.size() > 1) {
throw new IllegalArgumentException(MessageFormat.format("Form attribute [{0}:{1}] does not support multivalue, sent [{2}] values.", formDefinition.getCode(), attribute.getCode(), newValues.size()));
}
//
// compare values
IdmFormValueDto[] sortedPreviousValues = resolvePreviousValues(unprocessedPreviousValues, newValues);
for (short index = 0; index < newValues.size(); index++) {
IdmFormValueDto previousValue = sortedPreviousValues[index];
IdmFormValueDto newValue = newValues.get(index);
//
if (previousValue == null) {
if (newValue.getOwnerId() != null && !newValue.getOwnerId().equals(ownerEntity.getId())) {
// owner was changed, new value will be created => prevent to move (update) value into new owner.
newValue.setId(null);
DtoUtils.clearAuditFields(newValue);
//
// FIXME: move deep copy of attachments an confidential storage here.
}
newValue.setOwnerAndAttribute(ownerEntity, attribute);
newValue.setSeq(index);
//
if (!newValue.isNull()) {
// null values are not saved
newValue = formValueService.save(newValue, permission);
//
if (newValue.getPersistentType() == PersistentType.ATTACHMENT) {
// update attachment - set current owner, if temporary owner is given
IdmAttachmentDto attachment = attachmentManager.get(newValue.getUuidValue());
if (attachment != null && attachment.getOwnerType().equals(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE)) {
attachment.setOwnerType(attachmentManager.getOwnerType(formValueService.getEntityClass()));
attachment.setOwnerId(newValue.getId());
// permissions are evaluated above
attachmentManager.save(attachment);
}
}
results.add(newValue);
LOG.trace("FormValue [{}:{}] for owner [{}] was created.", attribute.getCode(), newValue.getId(), ownerEntity);
}
} else {
// confidential value is always updated - only new values are sent from client
if (newValue.isConfidential() || !previousValue.isEquals(newValue)) {
UUID previousUuidValue = previousValue.getUuidValue();
// set value for the previous value
previousValue.setValues(newValue);
// attribute persistent type could be changed
previousValue.setOwnerAndAttribute(ownerEntity, attribute);
previousValue.setSeq(index);
if (!previousValue.isNull()) {
// null values are not saved
previousValue = formValueService.save(previousValue, permission);
//
if (previousValue.getPersistentType() == PersistentType.ATTACHMENT) {
// fill attachments version and owners
IdmAttachmentDto previousAttachment = previousUuidValue == null ? null : attachmentManager.get(previousUuidValue);
// update attachment - set current owner, if temporary owner is given
IdmAttachmentDto attachment = attachmentManager.get(previousValue.getUuidValue());
if (attachment != null && attachment.getOwnerType().equals(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE)) {
attachment.setOwnerType(attachmentManager.getOwnerType(formValueService.getEntityClass()));
attachment.setOwnerId(previousValue.getId());
if (previousAttachment != null) {
if (previousAttachment.getParent() != null) {
attachment.setParent(previousAttachment.getParent());
} else {
attachment.setParent(previousAttachment.getId());
}
attachment.setVersionNumber(previousAttachment.getVersionNumber() + 1);
attachment.setVersionLabel(attachment.getVersionNumber() + ".0");
}
// permissions are evaluated above
attachment = attachmentManager.save(attachment);
if (previousAttachment != null) {
previousAttachment.setNextVersion(attachment.getId());
attachmentManager.save(previousAttachment);
}
}
}
results.add(previousValue);
LOG.trace("FormValue [{}:{}] for owner [{}] was updated.", attribute.getCode(), previousValue.getId(), ownerEntity);
} else {
formValueService.delete(previousValue, permission);
if (previousValue.getPersistentType() == PersistentType.ATTACHMENT) {
// delete attachment - permissions are evaluated before
attachmentManager.deleteAttachments(previousValue.getId(), attachmentManager.getOwnerType(formValueService.getEntityClass()));
}
LOG.trace("FormValue [{}:{}] for owner [{}] was deleted.", attribute.getCode(), previousValue.getId(), ownerEntity);
}
} else {
results.add(previousValue);
LOG.trace("FormValue [{}:{}] for owner [{}] was preserved unchanged.", attribute.getCode(), previousValue.getId(), ownerEntity);
}
}
}
// remove unprocessed values
// confidential property will be removed too => none or all confidential values have to be given for multiple attributes
unprocessedPreviousValues.values().forEach(value -> {
formValueService.delete(value, permission);
if (value.getPersistentType() == PersistentType.ATTACHMENT) {
// delete attachment - permissions are evaluated before
attachmentManager.deleteAttachments(value.getId(), attachmentManager.getOwnerType(formValueService.getEntityClass()));
}
LOG.trace("FormValue [{}:{}] for owner [{}] was deleted", value.getFormAttribute(), value.getId(), ownerEntity);
});
return results;
}
Aggregations