Search in sources :

Example 46 with VsRequestDto

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

the class RoleRequestCheckSystemStateProcessor method process.

@Override
public EventResult<IdmRoleRequestDto> process(EntityEvent<IdmRoleRequestDto> event) {
    IdmRoleRequestDto request = event.getContent();
    Assert.notNull(request, "Request is required.");
    Assert.notNull(request.getId(), "Request identifier is required.");
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setRoleRequestId(request.getId());
    // Some active requests for that request has state IN_PROGRESS -> we will wait for execution of all requests!
    requestFilter.setState(VsRequestState.IN_PROGRESS);
    List<VsRequestDto> inprogressRequests = requestService.find(requestFilter, null).getContent();
    if (inprogressRequests.size() > 0) {
        OperationResultDto systemResult = new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(VsResultCode.ROLE_REQUEST_VS_REQUEST_IN_PROGRESS, ImmutableMap.of("systems", this.getSystems(inprogressRequests)))).build();
        request.setSystemState(systemResult);
        DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
        return result;
    }
    requestFilter.setState(null);
    long countAllRequests = requestService.count(requestFilter);
    requestFilter.setOnlyArchived(Boolean.TRUE);
    long countArchives = requestService.count(requestFilter);
    // Nothing was done
    if (countAllRequests == 0) {
        DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
        return result;
    }
    // Everything was done (in VS)
    if (countAllRequests == countArchives && countArchives > 0) {
        request.setSystemState(new OperationResultDto(OperationState.EXECUTED));
        requestFilter.setOnlyArchived(Boolean.TRUE);
        requestFilter.setState(VsRequestState.CANCELED);
        // Check rejected requests - if exists some rejected request, we need to save this
        // information to role-concepts using role with this system.
        List<VsRequestDto> rejectedRequests = requestService.find(requestFilter, null).getContent();
        if (!rejectedRequests.isEmpty()) {
            List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(request.getId());
            rejectedRequests.forEach(vsRequest -> {
                Assert.notNull(vsRequest.getSystem(), "System is required.");
                UUID systemId = vsRequest.getSystem();
                List<IdmConceptRoleRequestDto> rejectedConcepts = roleSystemService.getConceptsForSystem(concepts, systemId);
                rejectedConcepts.forEach(concept -> {
                    OperationResultDto systemResult = new OperationResultDto.Builder(OperationState.CANCELED).setModel(new DefaultResultModel(VsResultCode.ROLE_REQUEST_VS_REQUEST_REJECTED, ImmutableMap.of("system", requestService.getSystem(vsRequest).getCode()))).build();
                    concept.setSystemState(systemResult);
                    // Save role concept
                    conceptRoleRequestService.save(concept);
                });
            });
        }
    }
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) UUID(java.util.UUID) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 47 with VsRequestDto

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

the class BasicVirtualConnector method delete.

@Override
public void delete(IcUidAttribute uid, IcObjectClass objectClass) {
    Assert.notNull(objectClass, "Object class cannot be null!");
    String uidValue = validateAndGetUid(uid);
    if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
        throw new IcException("Only ACCOUNT object class is supported now!");
    }
    // Create and execute request
    VsRequestDto request = createRequest(objectClass, null, (String) uidValue, VsOperationType.DELETE);
    requestService.execute(request);
}
Also used : IcException(eu.bcvsolutions.idm.ic.exception.IcException) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto)

Example 48 with VsRequestDto

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

the class BasicVirtualConnector method create.

@Override
public IcUidAttribute create(IcObjectClass objectClass, List<IcAttribute> attributes) {
    Assert.notNull(objectClass, "Object class cannot be null!");
    Assert.notNull(attributes, "Attributes cannot be null!");
    if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
        throw new IcException("Only ACCOUNT object class is supported now!");
    }
    IcAttribute uidAttribute = geAttribute(attributes, IcAttributeInfo.NAME);
    if (uidAttribute == null) {
        throw new IcException("UID attribute was not found!");
    }
    Object uidValue = uidAttribute.getValue();
    if (!(uidValue instanceof String)) {
        throw new IcException(MessageFormat.format("UID attribute value [{0}] must be String!", uidValue));
    }
    // Create and execute request
    VsRequestDto request = createRequest(objectClass, attributes, (String) uidValue, VsOperationType.CREATE);
    return requestService.execute(request);
}
Also used : IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto)

Example 49 with VsRequestDto

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

the class VsRequestCancelBulkActionTest method testCancelRequestWithoutReason.

@Test(expected = ResultCodeException.class)
public void testCancelRequestWithoutReason() {
    IdmIdentityDto implementer = helper.createIdentity();
    IdmIdentityDto identity = helper.createIdentity();
    IdmRoleDto roleForVs = helper.createRole();
    SysSystemDto system = this.createVirtualSystem(implementer, null);
    helper.createRoleSystem(roleForVs, system);
    helper.createIdentityRole(identity, roleForVs);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(system.getId());
    requestFilter.setUid(identity.getUsername());
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    VsRequestDto request = requests.get(0);
    Assert.assertEquals(identity.getUsername(), request.getUid());
    Assert.assertEquals(VsOperationType.CREATE, request.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
    VsAccountDto account = accountService.findByUidSystem(identity.getUsername(), system.getId());
    Assert.assertNull("Account must be null, because request was not realized yet!", account);
    // We try cancel the request
    IdmBulkActionDto bulkAction = this.findBulkAction(VsRequest.class, VsRequestCancelBulkAction.NAME);
    bulkAction.setIdentifiers(Sets.newHashSet(request.getId()));
    // Reason is null -> request cannot be cancelled.
    Map<String, Object> properties = new HashMap<>();
    properties.put(VsRequestCancelBulkAction.REASON, null);
    bulkAction.setProperties(properties);
    bulkActionManager.processAction(bulkAction);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) HashMap(java.util.HashMap) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 50 with VsRequestDto

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

the class CommonVsRequestControllerRestTest method prepareDto.

@Override
protected VsRequestDto prepareDto() {
    VsRequestDto dto = new VsRequestDto();
    SysSystemDto virtualSystem = helper.createVirtualSystem(helper.createName());
    dto.setSystem(virtualSystem.getId());
    dto.setUid(helper.createName());
    dto.setConnectorKey("mock");
    dto.setOperationType(VsOperationType.CREATE);
    dto.setState(VsRequestState.CONCEPT);
    // 
    return dto;
}
Also used : VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Aggregations

VsRequestDto (eu.bcvsolutions.idm.vs.dto.VsRequestDto)50 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)37 VsRequestFilter (eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter)37 Test (org.junit.Test)35 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)29 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)27 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)26 VsAccountDto (eu.bcvsolutions.idm.vs.dto.VsAccountDto)24 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)19 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)13 VsConnectorObjectDto (eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto)7 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)6 UUID (java.util.UUID)6 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)5 ArrayList (java.util.ArrayList)5 SysSystemEntityFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter)4 IcConnectorConfiguration (eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration)4 IcObjectClass (eu.bcvsolutions.idm.ic.api.IcObjectClass)4 IcException (eu.bcvsolutions.idm.ic.exception.IcException)4 IcResultsHandler (eu.bcvsolutions.idm.ic.filter.api.IcResultsHandler)4