Search in sources :

Example 1 with IcConfigurationService

use of eu.bcvsolutions.idm.ic.service.api.IcConfigurationService 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);
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) IcServerNotFoundException(eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException) IcInvalidCredentialException(eu.bcvsolutions.idm.ic.exception.IcInvalidCredentialException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) ResponseEntity(org.springframework.http.ResponseEntity) IcConfigurationService(eu.bcvsolutions.idm.ic.service.api.IcConfigurationService) IcCantConnectException(eu.bcvsolutions.idm.ic.exception.IcCantConnectException) IcRemoteServerException(eu.bcvsolutions.idm.ic.exception.IcRemoteServerException) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SysConnectorServerDto (eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto)1 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 SysSystem (eu.bcvsolutions.idm.acc.entity.SysSystem)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 IcCantConnectException (eu.bcvsolutions.idm.ic.exception.IcCantConnectException)1 IcInvalidCredentialException (eu.bcvsolutions.idm.ic.exception.IcInvalidCredentialException)1 IcRemoteServerException (eu.bcvsolutions.idm.ic.exception.IcRemoteServerException)1 IcServerNotFoundException (eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException)1 IcConfigurationService (eu.bcvsolutions.idm.ic.service.api.IcConfigurationService)1 ApiOperation (io.swagger.annotations.ApiOperation)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1