Skip to content

Commit 014b577

Browse files
Update for release 3.3.0.11 (#284)
- Migrate from ProvisioningAPI to Graph API - Fixed some typos - Merged PR for Windows Server 2025 support: #269 - Implemented filtering of ASR Rule based on presence of exchange - Updated readme.md --------- Signed-off-by: HerbieSmith-Netwrix <Herbert.Smith@netwrix.com>
1 parent efd9dde commit 014b577

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1213
-530
lines changed

ADWS/ADWSConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ private void EnumerateInternalWithADWS(string distinguishedName, string filter,
421421
}
422422
}
423423
}
424-
throw new PingCastleException("An ADWS exception occured (fault:" + ex.Message + ";reason:" + ex.Reason + ").\r\nADWS is a faster protocol than LDAP but bound to a default 30 minutes limitation. If this error persists, we recommand to force the LDAP protocol. Run PingCastle with the following switches: --protocol LDAPOnly --interactive");
424+
throw new PingCastleException("An ADWS exception occured (fault:" + ex.Message + ";reason:" + ex.Reason + ").\r\nADWS is a faster protocol than LDAP but bound to a default 30 minutes limitation. If this error persists, we recommend to force the LDAP protocol. Run PingCastle with the following switches: --protocol LDAPOnly --interactive");
425425
}
426426
Trace.WriteLine("[" + DateTime.Now.ToLongTimeString() + "]Pull successful");
427427
if (pullResponse.EndOfSequence != null)

Bot/Bot.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using PingCastle.Data;
22
using PingCastle.Healthcheck;
3+
using PingCastle.PingCastleLicense;
34
using PingCastle.Report;
45
using PingCastle.Rules;
56
using System;
@@ -195,7 +196,7 @@ private BotInputOutput ToHtml(BotInputOutput input)
195196
{
196197
HealthcheckData healthcheckData = DataHelper<HealthcheckData>.LoadXml(ms, "bot", null);
197198
var endUserReportGenerator = new ReportHealthCheckSingle();
198-
var license = LicenseManager.Validate(typeof(Program), new Program()) as ADHealthCheckingLicense;
199+
var license = LicenseCache.Instance.GetLicense();
199200
var report = endUserReportGenerator.GenerateReportFile(healthcheckData, license, healthcheckData.GetHumanReadableFileName());
200201

201202
var o = new BotInputOutput();

Cloud/Analyzer/Analyzer.cs

Lines changed: 278 additions & 165 deletions
Large diffs are not rendered by default.

Cloud/Credentials/CertificateCredential.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace PingCastle.Cloud.Credentials
2424
{
2525
public class CertificateCredential : IDisposable, IAzureCredential
2626
{
27+
public bool ForceRefreshByRefreshToken { get; set; }
2728
private CertificateCredential()
2829
{
2930

Cloud/Credentials/CredentialBase.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,44 @@ public CredentialBase(string tenantid)
2727

2828
Dictionary<Type, Token> cache = new Dictionary<Type, Token>();
2929
public Token LastTokenQueried { get; protected set; }
30+
31+
public bool ForceRefreshByRefreshToken { get; set; }
32+
3033
public async Task<Token> GetToken<T>() where T : IAzureService
3134
{
32-
Token token;
3335
if (cache.ContainsKey(typeof(T)))
3436
{
35-
token = cache[typeof(T)];
37+
var caschedToken = cache[typeof(T)];
38+
39+
var networkLatency = 5;
40+
var expiresOn = DateTimeOffset.FromUnixTimeSeconds(caschedToken.expires_on).AddSeconds(-networkLatency);
41+
42+
if (expiresOn <= DateTime.UtcNow || ForceRefreshByRefreshToken)
43+
{
44+
caschedToken = await TokenFactory.RefreshToken<T>(tenantId, caschedToken);
45+
UpdateTokenCache<T>(caschedToken);
46+
}
47+
48+
return caschedToken;
49+
}
50+
51+
var newToken = await TokenFactory.GetToken<T>(this);
52+
UpdateTokenCache<T>(newToken);
3653

37-
// TODO refresh
54+
return newToken;
55+
}
3856

39-
return token;
57+
private void UpdateTokenCache<T>(Token token) where T : IAzureService
58+
{
59+
if (token.expires_on == 0)
60+
{
61+
token.expires_on = (uint)((DateTimeOffset)DateTime.UtcNow.AddSeconds(token.expires_in)).ToUnixTimeSeconds();
4062
}
41-
token = await TokenFactory.GetToken<T>(this);
63+
4264
LastTokenQueried = token;
4365
cache[typeof(T)] = token;
44-
return token;
4566
}
67+
4668
string tenantId;
4769
public string Tenantid
4870
{

Cloud/Credentials/IAzureCredential.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ public interface IAzureCredential
2020
string TenantidToQuery { get; set; }
2121
Task<Token> GetToken<T>() where T : IAzureService;
2222
Token LastTokenQueried { get; }
23+
bool ForceRefreshByRefreshToken { get; set; }
2324
}
2425
}

Cloud/Data/HealthCheckCloudData.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,6 @@ string ComputeIntegrity()
330330

331331
public string ProvisionDirectorySynchronizationStatus { get; set; }
332332

333-
public List<string> ProvisionCompanyTags { get; set; }
334-
335-
public string ProvisionCompanyType { get; set; }
336-
337333
public bool? ProvisionPasswordSynchronizationEnabled { get; set; }
338334

339335
public List<string> ProvisionAuthorizedServiceInstances { get; set; }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using Microsoft.Kiota.Abstractions.Authentication;
7+
using PingCastle.Cloud.Credentials;
8+
using PingCastle.Cloud.RESTServices.Azure;
9+
10+
namespace PingCastle.Cloud.MsGraph
11+
{
12+
public class AzureCredentialTokenProvider<T> : IAccessTokenProvider where T : IAzureService
13+
{
14+
private readonly IAzureCredential _credential;
15+
16+
public AzureCredentialTokenProvider(IAzureCredential credential)
17+
{
18+
_credential = credential;
19+
}
20+
21+
public async Task<string> GetAuthorizationTokenAsync(Uri uri, Dictionary<string, object> additionalAuthenticationContext = default, CancellationToken cancellationToken = default)
22+
{
23+
Trace.WriteLine($"ACTP: the token has been requested {uri}");
24+
var token = await _credential.GetToken<T>();
25+
return token.access_token;
26+
}
27+
28+
public AllowedHostsValidator AllowedHostsValidator => new AllowedHostsValidator();
29+
}
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using PingCastle.Cloud.Credentials;
2+
3+
namespace PingCastle.Cloud.MsGraph
4+
{
5+
public static class GraphApiClientFactory
6+
{
7+
public static IGraphApiClient Create(IAzureCredential credential)
8+
{
9+
var client = GraphServiceClientFactory.Create<MsGraphApiFacade>(credential);
10+
return new MsGraphApiFacade(client);
11+
}
12+
}
13+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Microsoft.Graph;
2+
using Microsoft.Graph.Beta;
3+
using Microsoft.Kiota.Abstractions.Authentication;
4+
using PingCastle.Cloud.Credentials;
5+
using PingCastle.Cloud.RESTServices.Azure;
6+
7+
namespace PingCastle.Cloud.MsGraph
8+
{
9+
public static class GraphServiceClientFactory
10+
{
11+
public static GraphServiceClient Create(string accessToken)
12+
{
13+
return Create(new SimpleAccessTokenProvider(accessToken));
14+
}
15+
16+
public static GraphServiceClient Create<T>(IAzureCredential credential) where T : IAzureService
17+
{
18+
return Create(new AzureCredentialTokenProvider<T>(credential));
19+
}
20+
21+
public static GraphServiceClient Create(IAccessTokenProvider tokenProvider)
22+
{
23+
var authProvider = new BaseBearerTokenAuthenticationProvider(tokenProvider);
24+
var httpClient = GraphClientFactory.Create(authProvider, version: "beta");
25+
26+
return new GraphServiceClient(httpClient);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)