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