Search in sources :

Example 76 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class SystemMappingSaveProcessor method process.

@Override
public EventResult<SysSystemMappingDto> process(EntityEvent<SysSystemMappingDto> event) {
    SysSystemMappingDto dto = event.getContent();
    // it is not possible get schema from embedded - new entity
    SysSchemaObjectClassDto schema = schemaObjectClassService.get(dto.getObjectClass());
    SysSystemDto system = DtoUtils.getEmbedded(schema, SysSchemaObjectClass_.system, SysSystemDto.class);
    // for tree type is possible has more than one provisioning, both only for one tree type
    if (dto.getOperationType() == SystemOperationType.PROVISIONING) {
        // check if exists mapping
        List<SysSystemMappingDto> anotherMapping = getMapping(dto.getEntityType(), schema.getSystem(), dto.getTreeType());
        // if list not empty throw error with duplicate mapping
        if (anotherMapping.stream().filter(mapping -> {
            return !mapping.getId().equals(dto.getId());
        }).findFirst().isPresent()) {
            throw new ResultCodeException(AccResultCode.SYSTEM_MAPPING_FOR_ENTITY_EXISTS, ImmutableMap.of("system", system.getName(), "entityType", dto.getEntityType()));
        }
    }
    // 
    SysSystemMappingDto result = systemMappingService.saveInternal(dto);
    // update content
    event.setContent(result);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 77 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class PrepareConnectorObjectProcessor method process.

/**
 * Prepare provisioning operation execution
 */
@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
    SysProvisioningOperationDto provisioningOperation = event.getContent();
    SysSystemDto system = systemService.get(provisioningOperation.getSystem());
    IcObjectClass objectClass = provisioningOperation.getProvisioningContext().getConnectorObject().getObjectClass();
    SysSystemEntityDto systemEntity = provisioningOperationService.getByProvisioningOperation(provisioningOperation);
    String uid = systemEntity.getUid();
    boolean isWish = systemEntity.isWish();
    LOG.debug("Start preparing attribubes for provisioning operation [{}] for object with uid [{}] and connector object [{}]", provisioningOperation.getOperationType(), uid, objectClass.getType());
    // Find connector identification persisted in system
    if (system.getConnectorKey() == null) {
        throw new ProvisioningException(AccResultCode.CONNECTOR_KEY_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
    }
    // load connector configuration
    IcConnectorConfiguration connectorConfig = systemService.getConnectorConfiguration(system);
    if (connectorConfig == null) {
        throw new ProvisioningException(AccResultCode.CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
    }
    // 
    try {
        IcConnectorObject existsConnectorObject = null;
        // call the connector and auto mapping is not allowed.
        if (!(isWish && !provisioningConfiguration.isAllowedAutoMappingOnExistingAccount())) {
            IcUidAttribute uidAttribute = new IcUidAttributeImpl(null, uid, null);
            existsConnectorObject = connectorFacade.readObject(system.getConnectorInstance(), connectorConfig, objectClass, uidAttribute);
        }
        if (existsConnectorObject == null) {
            processCreate(provisioningOperation);
        } else {
            processUpdate(provisioningOperation, connectorConfig, existsConnectorObject);
        }
        // 
        LOG.debug("Preparing attribubes for provisioning operation [{}] for object with uid [{}] and connector object [{}] is sucessfully completed", provisioningOperation.getOperationType(), uid, objectClass.getType());
        // set back to event content
        provisioningOperation = provisioningOperationService.save(provisioningOperation);
        event.setContent(provisioningOperation);
        return new DefaultEventResult<>(event, this);
    } catch (Exception ex) {
        ResultModel resultModel;
        if (ex instanceof ResultCodeException) {
            resultModel = ((ResultCodeException) ex).getError().getError();
        } else {
            resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_PREPARE_ACCOUNT_ATTRIBUTES_FAILED, ImmutableMap.of("name", uid, "system", system.getName(), "operationType", provisioningOperation.getOperationType(), "objectClass", objectClass.getType()));
        }
        LOG.error(resultModel.toString(), ex);
        provisioningOperation.setResult(new OperationResult.Builder(OperationState.EXCEPTION).setModel(resultModel).setCause(ex).build());
        // 
        provisioningOperation = provisioningOperationService.save(provisioningOperation);
        // 
        notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder().setModel(resultModel).build());
        // set back to event content
        event.setContent(provisioningOperation);
        return new DefaultEventResult<>(event, this, true);
    }
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)

Example 78 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class AccAccountController method getConnectorObject.

@ResponseBody
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_READ + "')")
@RequestMapping(value = "/{backendId}/connector-object", method = RequestMethod.GET)
@ApiOperation(value = "Connector object for the account. Contains only attributes for witch have a schema attribute definitons.", nickname = "getConnectorObject", response = IcConnectorObject.class, tags = { SysSystemEntityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }) })
public ResponseEntity<IcConnectorObject> getConnectorObject(@ApiParam(value = "Account's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
    AccAccountDto account = this.getDto(backendId);
    if (account == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    IcConnectorObject connectorObject = ((AccAccountService) getService()).getConnectorObject(account, IdmBasePermission.READ);
    if (connectorObject == null) {
        return new ResponseEntity<IcConnectorObject>(HttpStatus.NO_CONTENT);
    }
    return new ResponseEntity<IcConnectorObject>(connectorObject, HttpStatus.OK);
}
Also used : AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) ResponseEntity(org.springframework.http.ResponseEntity) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 79 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class SysProvisioningBatchController method retry.

@ResponseBody
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_ADMIN + "')")
@RequestMapping(value = "/{backendId}/retry", method = RequestMethod.PUT)
@ApiOperation(value = "Retry provisioning batch", nickname = "retryProvisioningBatch", tags = { SysProvisioningBatchController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_ADMIN, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_ADMIN, description = "") }) }, notes = "Retry all provisioning operations in given batch - retry all active operations in queue grouped by system entity ordered by incomming date.")
public ResponseEntity<?> retry(@ApiParam(value = "Provisioning batch's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
    SysProvisioningBatchDto batch = getDto(backendId);
    if (batch == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    provisioningExecutor.execute(batch);
    return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 80 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class SysProvisioningBatchController method cancel.

@ResponseBody
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_ADMIN + "')")
@RequestMapping(value = "/{backendId}/cancel", method = RequestMethod.PUT)
@ApiOperation(value = "Cance provisioning batch", nickname = "cancelProvisioningBatch", tags = { SysProvisioningBatchController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_ADMIN, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_ADMIN, description = "") }) }, notes = "Cancel all provisioning operations in given batch - cancel all active operations in queue grouped by system entity.")
public ResponseEntity<Void> cancel(@ApiParam(value = "Provisioning batch's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
    SysProvisioningBatchDto batch = getDto(backendId);
    if (batch == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    provisioningExecutor.cancel(batch);
    return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)162 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)48 ApiOperation (io.swagger.annotations.ApiOperation)47 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)47 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)44 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)33 Test (org.junit.Test)31 ResponseEntity (org.springframework.http.ResponseEntity)22 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)20 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)17 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)17 Transactional (org.springframework.transaction.annotation.Transactional)17 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)15 UUID (java.util.UUID)15 ArrayList (java.util.ArrayList)14 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)13 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)12 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)12 IOException (java.io.IOException)12 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)10