Search in sources :

Example 1 with VsRequestFilter

use of eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter in project CzechIdMng by bcvsolutions.

the class SystemDeleteProcessor method process.

@Override
public EventResult<SysSystemDto> process(EntityEvent<SysSystemDto> event) {
    SysSystemDto system = event.getContent();
    Assert.notNull(system);
    // 
    // If exists unresolved vs request, then is not possible to delete
    // system
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(system.getId());
    requestFilter.setState(VsRequestState.IN_PROGRESS);
    if (requestService.find(requestFilter, null).getTotalElements() > 0) {
        throw new ResultCodeException(VsResultCode.VS_SYSTEM_DELETE_FAILED_HAS_REQUEST, ImmutableMap.of("system", system.getName()));
    }
    // Delete archived vs requests
    requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(system.getId());
    requestFilter.setOnlyArchived(Boolean.TRUE);
    requestService.find(requestFilter, null).forEach(entity -> {
        requestService.delete(entity);
    });
    // Delete vs account
    VsAccountFilter accountFilter = new VsAccountFilter();
    accountFilter.setSystemId(system.getId());
    accountService.find(accountFilter, null).forEach(entity -> {
        accountService.delete(entity);
    });
    // Delete vs account form definition
    if (system.getConnectorKey() != null) {
        String virtualSystemKey = MessageFormat.format("{0}:systemId={1}", system.getConnectorKey().getFullName(), system.getId());
        IdmFormDefinitionDto definition = this.formDefinitionService.findOneByTypeAndCode(VsAccount.class.getName(), virtualSystemKey);
        if (definition != null) {
            formDefinitionService.delete(definition);
        }
    }
    // Delete vs implementers
    VsSystemImplementerFilter implementerFilter = new VsSystemImplementerFilter();
    implementerFilter.setSystemId(system.getId());
    systemImplementerService.find(implementerFilter, null).forEach(entity -> {
        systemImplementerService.delete(entity);
    });
    return new DefaultEventResult<>(event, this);
}
Also used : VsAccount(eu.bcvsolutions.idm.vs.entity.VsAccount) VsSystemImplementerFilter(eu.bcvsolutions.idm.vs.dto.filter.VsSystemImplementerFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) VsAccountFilter(eu.bcvsolutions.idm.vs.dto.filter.VsAccountFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 2 with VsRequestFilter

use of eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter in project CzechIdMng by bcvsolutions.

the class VsRequestController method toFilter.

@Override
protected VsRequestFilter toFilter(MultiValueMap<String, Object> parameters) {
    VsRequestFilter filter = new VsRequestFilter();
    filter.setText(getParameterConverter().toString(parameters, "text"));
    filter.setState(getParameterConverter().toEnum(parameters, "state", VsRequestState.class));
    filter.setSystemId(getParameterConverter().toUuid(parameters, "systemId"));
    filter.setUid(getParameterConverter().toString(parameters, "uid"));
    filter.setCreatedAfter(getParameterConverter().toDateTime(parameters, "createdAfter"));
    filter.setCreatedBefore(getParameterConverter().toDateTime(parameters, "createdBefore"));
    filter.setOnlyArchived(getParameterConverter().toBoolean(parameters, "onlyArchived"));
    return filter;
}
Also used : VsRequestState(eu.bcvsolutions.idm.vs.domain.VsRequestState) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter)

Example 3 with VsRequestFilter

use of eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter in project CzechIdMng by bcvsolutions.

the class DefaultVsRequestService method internalExecute.

@Override
public IcUidAttribute internalExecute(VsRequestDto request) {
    request.setState(VsRequestState.REALIZED);
    Assert.notNull(request.getConfiguration(), "Request have to contains connector configuration!");
    Assert.notNull(request.getConnectorKey(), "Request have to contains connector key!");
    // Find connector by request
    VsVirtualConnector virtualConnector = getVirtualConnector(request);
    IcUidAttribute result = null;
    // Save the request
    this.save(request);
    switch(request.getOperationType()) {
        case CREATE:
            {
                result = virtualConnector.internalCreate(request.getConnectorObject().getObjectClass(), request.getConnectorObject().getAttributes());
                break;
            }
        case UPDATE:
            {
                VsAccountDto account = accountService.findByUidSystem(request.getUid(), request.getSystem());
                if (account == null) {
                    throw new VsException(VsResultCode.VS_REQUEST_UPDATING_ACCOUNT_NOT_EXIST, ImmutableMap.of("uid", request.getUid()));
                }
                result = virtualConnector.internalUpdate(new IcUidAttributeImpl(null, request.getUid(), null), request.getConnectorObject().getObjectClass(), request.getConnectorObject().getAttributes());
                break;
            }
        case DELETE:
            {
                VsAccountDto account = accountService.findByUidSystem(request.getUid(), request.getSystem());
                if (account == null) {
                    throw new VsException(VsResultCode.VS_REQUEST_DELETING_ACCOUNT_NOT_EXIST, ImmutableMap.of("uid", request.getUid()));
                }
                virtualConnector.internalDelete(new IcUidAttributeImpl(null, request.getUid(), null), request.getConnectorObject().getObjectClass());
                // All unresolved request created before this delete request will be
                // canceled
                VsRequestFilter filter = new VsRequestFilter();
                filter.setCreatedBefore(request.getCreated());
                filter.setUid(request.getUid());
                filter.setSystemId(request.getSystem());
                filter.setState(VsRequestState.IN_PROGRESS);
                // Unresolved request created before this request
                List<VsRequestDto> beforeRequests = this.find(filter, null).getContent();
                beforeRequests.forEach(beforeRequest -> {
                    String reason = MessageFormat.format("Request [{0}] was canceled (by SYSTEM), because 'after' delete request [{1}] was realized!", beforeRequest.getId(), request.getId());
                    this.cancel(beforeRequest, reason);
                    LOG.info(reason);
                });
                break;
            }
        default:
            throw new IcException(MessageFormat.format("Unsupported operation type [{0}]", request.getOperationType()));
    }
    return result;
}
Also used : SysSystem_(eu.bcvsolutions.idm.acc.entity.SysSystem_) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) StringUtils(org.apache.commons.lang3.StringUtils) VsRequestEvent(eu.bcvsolutions.idm.vs.event.VsRequestEvent) VsVirtualConnector(eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector) IcConnectorInstance(eu.bcvsolutions.idm.ic.api.IcConnectorInstance) Predicate(javax.persistence.criteria.Predicate) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Sort(org.springframework.data.domain.Sort) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsConnectorObjectDto(eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto) DynamicCorsConfiguration(eu.bcvsolutions.idm.core.config.domain.DynamicCorsConfiguration) VsOperationType(eu.bcvsolutions.idm.vs.domain.VsOperationType) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) VsRequest_(eu.bcvsolutions.idm.vs.entity.VsRequest_) ImmutableMap(com.google.common.collect.ImmutableMap) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) IcConnector(eu.bcvsolutions.idm.ic.api.IcConnector) List(java.util.List) VsRequest(eu.bcvsolutions.idm.vs.entity.VsRequest) CzechIdMIcConnectorService(eu.bcvsolutions.idm.ic.czechidm.service.impl.CzechIdMIcConnectorService) IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) VsRequestRealizationProcessor(eu.bcvsolutions.idm.vs.event.processor.VsRequestRealizationProcessor) BasicVirtualConfiguration(eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConfiguration) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) VsSystemImplementerService(eu.bcvsolutions.idm.vs.service.api.VsSystemImplementerService) VsRequestRepository(eu.bcvsolutions.idm.vs.repository.VsRequestRepository) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) VsAttributeValueDto(eu.bcvsolutions.idm.vs.dto.VsAttributeValueDto) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) VsResultCode(eu.bcvsolutions.idm.vs.exception.VsResultCode) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) CollectionUtils(org.apache.commons.collections.CollectionUtils) IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) Service(org.springframework.stereotype.Service) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) VsRequestEventType(eu.bcvsolutions.idm.vs.event.VsRequestEvent.VsRequestEventType) AbstractReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService) Direction(org.springframework.data.domain.Sort.Direction) Root(javax.persistence.criteria.Root) IcAttributeInfo(eu.bcvsolutions.idm.ic.api.IcAttributeInfo) IcConnectorInstanceImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorInstanceImpl) CzechIdMIcConfigurationService(eu.bcvsolutions.idm.ic.czechidm.service.impl.CzechIdMIcConfigurationService) VsAttributeDto(eu.bcvsolutions.idm.vs.dto.VsAttributeDto) Logger(org.slf4j.Logger) VsValueChangeType(eu.bcvsolutions.idm.vs.domain.VsValueChangeType) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsAccountService(eu.bcvsolutions.idm.vs.service.api.VsAccountService) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) VsException(eu.bcvsolutions.idm.vs.exception.VsException) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) VirtualSystemModuleDescriptor(eu.bcvsolutions.idm.vs.VirtualSystemModuleDescriptor) VsRequestState(eu.bcvsolutions.idm.vs.domain.VsRequestState) VirtualSystemGroupPermission(eu.bcvsolutions.idm.vs.domain.VirtualSystemGroupPermission) VsRequestService(eu.bcvsolutions.idm.vs.service.api.VsRequestService) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) IcException(eu.bcvsolutions.idm.ic.exception.IcException) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) VsException(eu.bcvsolutions.idm.vs.exception.VsException) IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) List(java.util.List) ArrayList(java.util.ArrayList) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) VsVirtualConnector(eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector)

Example 4 with VsRequestFilter

use of eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter in project CzechIdMng by bcvsolutions.

the class DefaultVsRequestService method findDuplicities.

/**
 * Find duplicity requests. All request in state IN_PROGRESS for same UID and
 * system. For all operation types.
 *
 * @param request
 * @return
 */
@Override
public List<VsRequestDto> findDuplicities(String uid, UUID systemId) {
    VsRequestFilter filter = new VsRequestFilter();
    filter.setUid(uid);
    filter.setSystemId(systemId);
    filter.setState(VsRequestState.IN_PROGRESS);
    Sort sort = new Sort(Direction.DESC, VsRequest_.created.getName());
    return this.find(filter, new PageRequest(0, Integer.MAX_VALUE, sort)).getContent();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Sort(org.springframework.data.domain.Sort) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter)

Example 5 with VsRequestFilter

use of eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter in project CzechIdMng by bcvsolutions.

the class VsReqeustServiceTest method disableRequestTest.

@Test
public void disableRequestTest() {
    SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
    IdmIdentityDto identity = helper.createIdentity(USER_ONE_NAME);
    this.assignRoleSystem(system, identity, ROLE_ONE_NAME);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(system.getId());
    requestFilter.setUid(USER_ONE_NAME);
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    VsRequestDto request = requests.get(0);
    Assert.assertEquals(USER_ONE_NAME, request.getUid());
    Assert.assertEquals(VsOperationType.CREATE, request.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
    VsAccountDto account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
    Assert.assertNull("Account must be null, because request was not realized yet!", account);
    // We try realize the request
    super.logout();
    loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
    request = requestService.realize(request);
    Assert.assertEquals(VsRequestState.REALIZED, request.getState());
    account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
    Assert.assertNotNull("Account cannot be null, because request was realized!", account);
    Assert.assertEquals(Boolean.TRUE, account.isEnable());
    super.logout();
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    // Disable the identity
    identity.setState(IdentityState.DISABLED_MANUALLY);
    identityService.save(identity);
    // Find created requests
    requests = requestService.find(requestFilter, null).getContent().stream().filter(r -> VsRequestState.IN_PROGRESS == r.getState()).collect(Collectors.toList());
    Assert.assertEquals(1, requests.size());
    request = requests.get(0);
    Assert.assertEquals(USER_ONE_NAME, request.getUid());
    Assert.assertEquals(VsOperationType.UPDATE, request.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
    // We try realize the request
    super.logout();
    loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
    request = requestService.realize(request);
    Assert.assertEquals(VsRequestState.REALIZED, request.getState());
    account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
    Assert.assertNotNull("Account cannot be null, because request was realized!", account);
    Assert.assertEquals(Boolean.FALSE, account.isEnable());
}
Also used : VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

VsRequestFilter (eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter)14 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)12 VsRequestDto (eu.bcvsolutions.idm.vs.dto.VsRequestDto)11 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)10 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)10 Test (org.junit.Test)10 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)9 VsAccountDto (eu.bcvsolutions.idm.vs.dto.VsAccountDto)9 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)7 VsConnectorObjectDto (eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto)4 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)3 SysSystemEntityFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter)2 SysSystemService (eu.bcvsolutions.idm.acc.service.api.SysSystemService)2 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)2 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)2 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)2 IcConnectorConfiguration (eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration)2 VsRequestState (eu.bcvsolutions.idm.vs.domain.VsRequestState)2 ArrayList (java.util.ArrayList)2 PageRequest (org.springframework.data.domain.PageRequest)2