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