use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class IdmAuditController method toFilter.
@Override
protected IdmAuditFilter toFilter(MultiValueMap<String, Object> parameters) {
// We must check if map contains list of changed attributes, because mapped doesn't works with list and zero values.
List<String> changedAttributesList = null;
if (parameters.containsKey("changedAttributesList")) {
List<Object> remove = parameters.remove("changedAttributesList");
changedAttributesList = remove.stream().map(o -> Objects.toString(o.toString())).collect(Collectors.toList());
}
// entity id decorator
String entityId = getParameterConverter().toString(parameters, "entityId");
List<String> entityTypes = getParameterConverter().toStrings(parameters, "type");
UUID entityUuid = null;
if (CollectionUtils.isNotEmpty(entityTypes) && StringUtils.isNotEmpty(entityId)) {
// try to find entity by Codeable identifier
String entityType = entityTypes.get(0);
AbstractDto entity = getLookupService().lookupDto(entityType, entityId);
if (entity != null) {
entityUuid = entity.getId();
parameters.remove("entityId");
} else {
LOG.debug("Entity type [{}] with identifier [{}] does not found, raw entityId will be used as uuid.", entityType, entityId);
// Better exception for FE.
try {
DtoUtils.toUuid(entityId);
} catch (ClassCastException ex) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", entityId), ex);
}
}
}
IdmAuditFilter filter = super.toFilter(parameters);
filter.setTypes(entityTypes);
filter.setChangedAttributesList(changedAttributesList);
if (entityUuid != null) {
filter.setEntityId(entityUuid);
}
//
return filter;
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class DefaultLongPollingManager method checkDeferredRequests.
@Override
public void checkDeferredRequests(Class<? extends AbstractDto> type) {
Assert.notNull(type, "Class type cannot be null!");
this.suspendedRequests.stream().filter(request -> request.getResult().isSetOrExpired()).forEach(request -> {
this.suspendedRequests.remove(request);
});
//
this.suspendedRequests.stream().filter(//
request -> type.equals(request.getType())).forEach(request -> {
//
LongPollingSubscriber subscriber = null;
if (this.registredSubscribers.containsKey(request.getEntityId())) {
subscriber = this.registredSubscribers.get(request.getEntityId());
} else {
subscriber = new LongPollingSubscriber(request.getEntityId(), type);
}
CheckLongPollingResult checkResultCallback = request.getCheckResultCallback();
if (checkResultCallback != null) {
subscriber.setLastUsingSubscriber(ZonedDateTime.now());
checkResultCallback.checkDeferredResult(request.getResult(), subscriber);
}
});
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class DefaultVsRequestService method toDto.
@Override
protected VsRequestDto toDto(VsRequest entity, VsRequestDto dto, VsRequestFilter filter) {
dto = super.toDto(entity, dto, filter);
if (dto != null && dto.getSystem() != null && dto.getUid() != null && filter != null && filter.isIncludeOwner()) {
// Load and set target entity. For loading a target entity is using sync
// executor. Owner loading is processed only if filter "includeOwner" is present!
AbstractDto targetEntity = findTargetEntity(dto);
if (targetEntity != null) {
dto.setTargetEntity(targetEntity);
dto.setTargetEntityType(targetEntity.getClass().getName());
}
}
return dto;
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractDto in project CzechIdMng by bcvsolutions.
the class GeneralEntityExport method getAuthoritiesForEntity.
@Override
@SuppressWarnings("rawtypes")
protected List<String> getAuthoritiesForEntity() {
ReadWriteDtoService<AbstractDto, BaseFilter> service = getService();
if (!(service instanceof AuthorizableService)) {
// Service is not authorizable => only super admin can use report.
return Lists.newArrayList(IdmGroupPermission.APP_ADMIN);
}
AuthorizableService authorizableService = (AuthorizableService) service;
AuthorizableType authorizableType = authorizableService.getAuthorizableType();
if (authorizableType == null) {
// Service is authorizable but group is not specified => only super admin can use report.
return Lists.newArrayList(IdmGroupPermission.APP_ADMIN);
}
boolean readPermissionFound = authorizableType.getGroup().getPermissions().stream().filter(permission -> IdmBasePermission.READ == permission).findFirst().isPresent();
if (!readPermissionFound) {
// By default only super admin can use report.
return Lists.newArrayList(IdmGroupPermission.APP_ADMIN);
}
// If exist, read permission for that type will be returned.
return Lists.newArrayList(MessageFormat.format("{0}{1}{2}", authorizableType.getGroup().getName(), IdmBasePermission.SEPARATOR, IdmBasePermission.READ.name()));
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractDto 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;
}
Aggregations