Search in sources :

Example 31 with AbstractDto

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;
}
Also used : AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmAuditFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter) UUID(java.util.UUID)

Example 32 with AbstractDto

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);
        }
    });
}
Also used : ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) DeferredResult(org.springframework.web.context.request.async.DeferredResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Scheduled(org.springframework.scheduling.annotation.Scheduled) ModifiedFromFilter(eu.bcvsolutions.idm.core.api.dto.filter.ModifiedFromFilter) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ReadDtoService(eu.bcvsolutions.idm.core.api.service.ReadDtoService) Service(org.springframework.stereotype.Service) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) CheckLongPollingResult(eu.bcvsolutions.idm.core.model.service.api.CheckLongPollingResult) Map(java.util.Map) LongPollingManager(eu.bcvsolutions.idm.core.model.service.api.LongPollingManager) Sort(org.springframework.data.domain.Sort) Direction(org.springframework.data.domain.Sort.Direction) DeferredResultWrapper(eu.bcvsolutions.idm.core.rest.DeferredResultWrapper) Logger(org.slf4j.Logger) AbstractEntity_(eu.bcvsolutions.idm.core.api.entity.AbstractEntity_) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PageRequest(org.springframework.data.domain.PageRequest) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) UUID(java.util.UUID) LongPollingSubscriber(eu.bcvsolutions.idm.core.rest.LongPollingSubscriber) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) Lazy(org.springframework.context.annotation.Lazy) Queue(java.util.Queue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Assert(org.springframework.util.Assert) LongPollingSubscriber(eu.bcvsolutions.idm.core.rest.LongPollingSubscriber) CheckLongPollingResult(eu.bcvsolutions.idm.core.model.service.api.CheckLongPollingResult)

Example 33 with AbstractDto

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;
}
Also used : AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto)

Example 34 with AbstractDto

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()));
}
Also used : AuthorizableService(eu.bcvsolutions.idm.core.security.api.service.AuthorizableService) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter)

Example 35 with AbstractDto

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

Aggregations

AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)54 UUID (java.util.UUID)28 Test (org.junit.Test)16 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)15 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)13 HashMap (java.util.HashMap)12 List (java.util.List)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Assert (org.springframework.util.Assert)11 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)10 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 Map (java.util.Map)10 Service (org.springframework.stereotype.Service)10 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)9 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 IntrospectionException (java.beans.IntrospectionException)9 Field (java.lang.reflect.Field)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ImmutableMap (com.google.common.collect.ImmutableMap)8