Prepare Data History Provider 2.7 integration update

- modularize Citrix and agent integrations and add remote desktop endpoints
- extend ticket overview, ticket links, token validation, and staged relation handling
- update configuration, licensing, project, signing, and publish artifacts
This commit is contained in:
Meik
2026-07-20 09:31:52 +02:00
parent a3357e2a36
commit ccc48c521a
62 changed files with 5267 additions and 2521 deletions

View File

@@ -1,11 +1,16 @@
using C4IT.FASD.Base;
using C4IT.Logging;
using C4IT.Security;
using System;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using C4IT.FASD.Base;
using C4IT.Logging;
using C4IT.Security;
using Newtonsoft.Json.Linq;
using static C4IT.DataHistoryProvider.cDataHistoryCollectorTokenCache;
using static C4IT.Logging.cLogManager;
namespace C4IT.DataHistoryProvider
@@ -29,6 +34,7 @@ namespace C4IT.DataHistoryProvider
public string secret;
public DateTime validUntil;
public DateTime renewUntil;
public string IdRemote;
public bool IsValid()
{
@@ -36,6 +42,7 @@ namespace C4IT.DataHistoryProvider
return false;
if (validUntil < DateTime.UtcNow + TimeSpan.FromMinutes(cDataHistoryCollector.constMinutesUntilTokenIsInvalid))
return false;
return true;
}
@@ -52,7 +59,8 @@ namespace C4IT.DataHistoryProvider
name2 = name2,
secret = _sec,
validUntil = validUntil,
renewUntil = renewUntil
renewUntil = renewUntil,
IdRemote = IdRemote
};
return _ret;
@@ -132,6 +140,9 @@ namespace C4IT.DataHistoryProvider
{
dicToken.Clear();
var _toDelete = new List<cTokenInfo>();
var _toUpdate = new List<cTokenInfo>();
using (var _reader = await DataHistorySqlHelper.GetDataReaderAsync(DbConn, Query, null, Token))
{
if (_reader != null)
@@ -139,7 +150,6 @@ namespace C4IT.DataHistoryProvider
{
if (_reader.HasRows)
{
var _toDelete = new List<cTokenInfo>();
while (await _reader.ReadAsync())
{
try
@@ -156,13 +166,22 @@ namespace C4IT.DataHistoryProvider
_entry.secret = cSecurePassword.Instance.Decode(_secret);
_entry.validUntil = _reader.IsDBNull(5) ? DateTime.MinValue : _reader.GetDateTime(5);
_entry.renewUntil = _reader.IsDBNull(6) ? DateTime.MinValue : _reader.GetDateTime(6);
_entry.IdRemote = _reader.IsDBNull(7) ? null : _reader.GetString(7);
int valid = -1;
if (_entry.IsValid())
valid = await Collector.ValidateTokenInfo(_entry);
if (valid < 0)
_toDelete.Add(_entry);
else
{
if (!privInsert(_entry, false))
_toDelete.Add(_entry);
if (valid > 0)
_toUpdate.Add(_entry);
}
else
_toDelete.Add(_entry);
}
catch (Exception E)
{
@@ -178,9 +197,18 @@ namespace C4IT.DataHistoryProvider
{
cLogManager.DefaultLogger.LogException(E);
}
}
if (_toUpdate.Count > 0)
{
foreach (var entry in _toUpdate)
{
var _secEnc = entry.secret;
if (!HasTokenTypeLongLifetime(entry.type))
_secEnc = cSecurePassword.Instance.Encode(entry.secret);
await SaveToDbAsync(entry, _secEnc, requestInfo, LogDeep + 1, Token);
}
}
}
catch (Exception E)
{
@@ -204,6 +232,54 @@ namespace C4IT.DataHistoryProvider
}
}
private async Task SaveToDbAsync(cTokenInfo _tokenInfo, string secEnc, cF4sdWebRequestInfo requestInfo, int LogDeep, CancellationToken Token)
{
MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }
var sqlerror = 0;
var sqlStartTime = DateTime.UtcNow;
if (!DataHistorySqlHelper.GetWellKnownSqlStatement("InsertOrUpdateExternalToken", out var Query))
return;
try
{
var Params = new Dictionary<string, object>()
{
{ "Id", _tokenInfo.id },
{ "Type", (int)_tokenInfo.type },
{ "Name", _tokenInfo.name },
{ "Name2", _tokenInfo.name2 },
{ "Secret", secEnc },
{ "ValidUntil", _tokenInfo.validUntil },
{ "RenewUntil", _tokenInfo.renewUntil },
{ "IdRemote", _tokenInfo.IdRemote },
};
using (var Conn = new cDbConnection(Collector.mainDbConnection))
{
if (!Conn.IsOpen)
{
LogEntry($"Could not open main database '{Collector.mainDbConnection.Database}', aborting query'", LogLevels.Error);
return;
}
await DataHistorySqlHelper.ExecuteAsync(Conn, Query, Params, requestInfo, Token);
}
}
catch (Exception E)
{
sqlerror = E.HResult;
LogException(E);
}
finally
{
if (CM != null) LogMethodEnd(CM);
}
}
public async Task SetAsync(cF4SDTokenRegistration _tokenRegistration, cF4SDTokenValidityPeriod validityPeriod, CancellationToken Token, cF4sdWebRequestInfo requestInfo, int LogDeep)
{
MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }
@@ -229,50 +305,23 @@ namespace C4IT.DataHistoryProvider
renewUntil = validityPeriod.renewUntil
};
if (!DataHistorySqlHelper.GetWellKnownSqlStatement("InsertOrUpdateExternalToken", out var Query))
return;
var Params = new Dictionary<string, object>()
{
{ "Id", _tokenInfo.id },
{ "Type", (int)_tokenInfo.type },
{ "Name", _tokenInfo.name },
{ "Name2", _tokenInfo.name2 },
{ "Secret", _secEnc },
{ "ValidUntil", _tokenInfo.validUntil },
{ "RenewUntil", _tokenInfo.renewUntil },
};
var sqlerror = 0;
var sqlStartTime = DateTime.UtcNow;
await TokenCacheCriticalSection.EnterAsync();
try
{
await SaveToDbAsync(_tokenInfo, _secEnc, requestInfo, LogDeep + 1, Token);
privInsert(_tokenInfo, true);
using (var Conn = new cDbConnection(Collector.mainDbConnection))
{
if (!Conn.IsOpen)
{
LogEntry($"Could not open main database '{Collector.mainDbConnection.Database}', aborting query'", LogLevels.Error);
return;
}
await DataHistorySqlHelper.ExecuteAsync(Conn, Query, Params, requestInfo, Token);
}
}
catch (Exception E)
{
sqlerror = E.HResult;
LogException(E);
}
finally
{
TokenCacheCriticalSection.Leave();
}
}
catch (Exception E)
{