use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class SysSystemController method getAvailableRemoteConnectors.
/**
* Rest endpoints return available remote connectors.
* If entity hasn't set for remote or isn't exists return empty map of connectors
*
* @param backendId
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "{backendId}/search/remote")
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_READ + "')")
@ApiOperation(value = "Get available remote connectors", nickname = "getAvailableRemoteConnectors", tags = { SysSystemController.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 = "") }) }, notes = "Supported remote conectors (by remote server configuration).")
public ResponseEntity<Map<String, Set<IcConnectorInfo>>> getAvailableRemoteConnectors(@ApiParam(value = "System's uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
SysSystemDto dto = this.getDto(backendId);
Map<String, Set<IcConnectorInfo>> infos = new HashMap<>();
// if entity hasn't set up for remote return empty map
if (dto == null || !dto.isRemote()) {
return new ResponseEntity<Map<String, Set<IcConnectorInfo>>>(infos, HttpStatus.OK);
}
Assert.notNull(dto.getConnectorServer());
//
try {
for (IcConfigurationService config : icConfiguration.getIcConfigs().values()) {
SysConnectorServerDto server = dto.getConnectorServer();
server.setPassword(this.confidentialStorage.getGuardedString(dto.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD));
infos.put(config.getFramework(), config.getAvailableRemoteConnectors(server));
}
} catch (IcInvalidCredentialException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_INVALID_CREDENTIAL, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcServerNotFoundException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_NOT_FOUND, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcCantConnectException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_CANT_CONNECT, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcRemoteServerException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_UNEXPECTED_ERROR, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
}
//
return new ResponseEntity<Map<String, Set<IcConnectorInfo>>>(infos, HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class SysSystemController method getConnectorFormValues.
/**
* Returns filled connector configuration
* or throws exception with code {@code CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND}, when system is wrong configured
*
* @param backendId
* @return
*/
@ResponseBody
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_READ + "')")
@RequestMapping(value = "/{backendId}/connector-form-values", method = RequestMethod.GET)
@ApiOperation(value = "Connector configuration - read values", nickname = "getConnectorFormValues", tags = { SysSystemController.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 Resource<?> getConnectorFormValues(@ApiParam(value = "System's uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
SysSystemDto entity = getDto(backendId);
if (entity == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
IdmFormDefinitionDto formDefinition = getConnectorFormDefinition(entity);
return formDefinitionController.getFormValues(entity, formDefinition);
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class SysSystemController method generateSchema.
@ResponseBody
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_UPDATE + "')")
@RequestMapping(value = "/{backendId}/generate-schema", method = RequestMethod.POST)
@ApiOperation(value = "Generate system schema", nickname = "generateSystemSchema", tags = { SysSystemController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_UPDATE, description = "") }) }, notes = "Genetares schema by system's connector configuration")
public ResponseEntity<?> generateSchema(@ApiParam(value = "System's uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
SysSystemDto system = getDto(backendId);
if (system == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
systemService.generateSchema(system);
return new ResponseEntity<>(toResource(system), HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemMappingService method validate.
/**
* Validate system mapping
*
* @param id(UUID
* system mapping)
*/
@Override
public void validate(UUID id) {
Assert.notNull(id);
//
Map<String, Object> errors = new HashMap<>();
SysSystemMappingDto systemMapping = this.get(id);
List<SysSystemAttributeMappingDto> attributesList = getAttributeMappingService().findBySystemMapping(systemMapping);
//
errors = validateIdentifier(errors, systemMapping, attributesList);
errors = validateSynchronizationContracts(errors, systemMapping, attributesList);
if (!errors.isEmpty()) {
throw new ResultCodeException(AccResultCode.SYSTEM_MAPPING_VALIDATION, errors);
}
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemService method generateSchema.
@Override
@Transactional
public List<SysSchemaObjectClassDto> generateSchema(SysSystemDto system) {
Assert.notNull(system);
Assert.notNull(system.getId());
// Find connector identification persisted in system
IcConnectorKey connectorKey = system.getConnectorKey();
if (connectorKey == null) {
throw new ResultCodeException(AccResultCode.CONNECTOR_KEY_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// Find connector configuration persisted in system
IcConnectorConfiguration connectorConfig = getConnectorConfiguration(system);
if (connectorConfig == null) {
throw new ResultCodeException(AccResultCode.CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// Call IC module and find schema for given connector key and
// configuration
IcSchema icSchema = icConfigurationFacade.getSchema(system.getConnectorInstance(), connectorConfig);
if (icSchema == null) {
throw new ResultCodeException(AccResultCode.CONNECTOR_SCHEMA_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// Load existing object class from system
SysSchemaObjectClassFilter objectClassFilter = new SysSchemaObjectClassFilter();
objectClassFilter.setSystemId(system.getId());
List<SysSchemaObjectClassDto> sysObjectClassesInSystem = null;
Page<SysSchemaObjectClassDto> page = objectClassService.find(objectClassFilter, null);
sysObjectClassesInSystem = page.getContent();
// Convert IC schema to ACC entities
List<SysSchemaObjectClassDto> sysObjectClasses = new ArrayList<SysSchemaObjectClassDto>();
List<SysSchemaAttributeDto> sysAttributes = new ArrayList<SysSchemaAttributeDto>();
for (IcObjectClassInfo objectClass : icSchema.getDeclaredObjectClasses()) {
// __ACCOUNT__ and __GROUP__
if (!(objectClass.getType().startsWith("__") && objectClass.getType().endsWith("__"))) {
continue;
}
SysSchemaObjectClassDto sysObjectClass = null;
// values from resource
if (sysObjectClassesInSystem != null) {
Optional<SysSchemaObjectClassDto> objectClassSame = sysObjectClassesInSystem.stream().filter(objectClassInSystem -> {
//
return objectClassInSystem.getObjectClassName().equals(objectClass.getType());
}).findFirst();
if (objectClassSame.isPresent()) {
sysObjectClass = objectClassSame.get();
}
}
// Convert IC object class to ACC (if is null, then will be created
// new instance)
sysObjectClass = convertIcObjectClassInfo(objectClass, sysObjectClass);
sysObjectClass.setSystem(system.getId());
// object class may not exist
sysObjectClass = schemaObjectClassService.save(sysObjectClass);
sysObjectClasses.add(sysObjectClass);
List<SysSchemaAttributeDto> attributesInSystem = null;
// Load existing attributes for existing object class in system
if (sysObjectClass.getId() != null) {
SysSchemaAttributeFilter attFilter = new SysSchemaAttributeFilter();
attFilter.setSystemId(system.getId());
attFilter.setObjectClassId(sysObjectClass.getId());
Page<SysSchemaAttributeDto> attributesInSystemPage = attributeService.find(attFilter, null);
attributesInSystem = attributesInSystemPage.getContent();
}
for (IcAttributeInfo attribute : objectClass.getAttributeInfos()) {
// If will be IC and ACC attribute same (same name), then we
// will do only refresh object values from resource
SysSchemaAttributeDto sysAttribute = null;
if (attributesInSystem != null) {
Optional<SysSchemaAttributeDto> sysAttributeOptional = attributesInSystem.stream().filter(a -> {
return a.getName().equals(attribute.getName());
}).findFirst();
if (sysAttributeOptional.isPresent()) {
sysAttribute = sysAttributeOptional.get();
}
}
sysAttribute = convertIcAttributeInfo(attribute, sysAttribute);
sysAttribute.setObjectClass(sysObjectClass.getId());
sysAttributes.add(sysAttribute);
}
}
// Persist generated schema to system
sysObjectClasses = (List<SysSchemaObjectClassDto>) objectClassService.saveAll(sysObjectClasses);
attributeService.saveAll(sysAttributes);
return sysObjectClasses;
}
Aggregations