Search in sources :

Example 6 with IcServerNotFoundException

use of eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException in project CzechIdMng by bcvsolutions.

the class DefaultConnectorManager method findConnectorKey.

@Override
public IcConnectorKey findConnectorKey(ConnectorTypeDto connectorType) {
    Assert.notNull(connectorType, "Connector type cannot be null!");
    String connectorName = connectorType.getConnectorName();
    Assert.notNull(connectorName, "Connector name cannot be null!");
    UUID remoteServer = connectorType.getRemoteServer();
    // 
    if (remoteServer == null) {
        // local
        Map<String, Set<IcConnectorInfo>> availableLocalConnectors = icConfiguration.getAvailableLocalConnectors();
        if (availableLocalConnectors == null) {
            return null;
        }
        List<IcConnectorInfo> connectorInfos = Lists.newArrayList();
        for (Set<IcConnectorInfo> icConnectorInfos : availableLocalConnectors.values()) {
            connectorInfos.addAll(icConnectorInfos);
        }
        IcConnectorInfo connectorInfo = connectorInfos.stream().filter(info -> connectorName.equals(info.getConnectorKey().getConnectorName())).findFirst().orElse(null);
        return connectorInfo != null ? connectorInfo.getConnectorKey() : null;
    }
    // remote connector
    try {
        SysConnectorServerDto connectorServer = remoteServerService.get(remoteServer);
        if (connectorServer == null) {
            return null;
        }
        for (IcConfigurationService config : icConfiguration.getIcConfigs().values()) {
            connectorServer.setPassword(remoteServerService.getPassword(connectorServer.getId()));
            Set<IcConnectorInfo> availableRemoteConnectors = config.getAvailableRemoteConnectors(connectorServer);
            if (CollectionUtils.isNotEmpty(availableRemoteConnectors)) {
                IcConnectorInfo connectorInfo = availableRemoteConnectors.stream().filter(info -> connectorName.equals(info.getConnectorKey().getConnectorName())).findFirst().orElse(null);
                if (connectorInfo != null) {
                    return connectorInfo.getConnectorKey();
                }
            }
        }
    } catch (IcInvalidCredentialException e) {
        ExceptionUtils.log(LOG, new ResultCodeException(AccResultCode.REMOTE_SERVER_INVALID_CREDENTIAL, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e));
    } catch (IcServerNotFoundException e) {
        ExceptionUtils.log(LOG, new ResultCodeException(AccResultCode.REMOTE_SERVER_NOT_FOUND, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e));
    } catch (IcCantConnectException e) {
        ExceptionUtils.log(LOG, new ResultCodeException(AccResultCode.REMOTE_SERVER_CANT_CONNECT, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e));
    } catch (IcRemoteServerException e) {
        ExceptionUtils.log(LOG, new ResultCodeException(AccResultCode.REMOTE_SERVER_UNEXPECTED_ERROR, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e));
    }
    return null;
}
Also used : Set(java.util.Set) IcServerNotFoundException(eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException) IcInvalidCredentialException(eu.bcvsolutions.idm.ic.exception.IcInvalidCredentialException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IcConfigurationService(eu.bcvsolutions.idm.ic.service.api.IcConfigurationService) IcCantConnectException(eu.bcvsolutions.idm.ic.exception.IcCantConnectException) IcRemoteServerException(eu.bcvsolutions.idm.ic.exception.IcRemoteServerException) UUID(java.util.UUID) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto)

Aggregations

IcCantConnectException (eu.bcvsolutions.idm.ic.exception.IcCantConnectException)6 IcInvalidCredentialException (eu.bcvsolutions.idm.ic.exception.IcInvalidCredentialException)6 IcRemoteServerException (eu.bcvsolutions.idm.ic.exception.IcRemoteServerException)6 IcServerNotFoundException (eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException)6 SysConnectorServerDto (eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto)5 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)5 IcConfigurationService (eu.bcvsolutions.idm.ic.service.api.IcConfigurationService)5 Set (java.util.Set)5 IcConnectorInfo (eu.bcvsolutions.idm.ic.api.IcConnectorInfo)3 ApiOperation (io.swagger.annotations.ApiOperation)3 HashMap (java.util.HashMap)3 ResponseEntity (org.springframework.http.ResponseEntity)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Lists (com.google.common.collect.Lists)2 AccModuleDescriptor (eu.bcvsolutions.idm.acc.AccModuleDescriptor)2 AccGroupPermission (eu.bcvsolutions.idm.acc.domain.AccGroupPermission)2 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)2 ConnectorTypeDto (eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto)2