From d5ffd884d24e693039c506790a749cc6f6da05ae Mon Sep 17 00:00:00 2001 From: aamburn Date: Wed, 21 Apr 2021 16:46:32 -0500 Subject: [PATCH 1/2] ISSUE 4: Authorization is Denied error. Changes to handle expired SPP auth token by refreshing the token with SafeguardDotNet. Additional changes include upgrading to the latest version of SafeguardDotNet and adding a new command line parameter to specify log level. --- src/Common/Common.csproj | 2 +- src/Common/SafeguardRestApiClient.cs | 18 ++++-- src/Service/App.config | 18 +++--- src/Service/Program.cs | 39 +++++++++++- src/Service/Service.csproj | 89 +++++++++++++++------------- src/Service/packages.config | 43 +++++++------- 6 files changed, 136 insertions(+), 73 deletions(-) diff --git a/src/Common/Common.csproj b/src/Common/Common.csproj index 44384ce..73098b9 100644 --- a/src/Common/Common.csproj +++ b/src/Common/Common.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/Common/SafeguardRestApiClient.cs b/src/Common/SafeguardRestApiClient.cs index 60ac54c..301c791 100644 --- a/src/Common/SafeguardRestApiClient.cs +++ b/src/Common/SafeguardRestApiClient.cs @@ -19,13 +19,13 @@ public SafeguardRestApiClient(ISafeguardConnection connection) public SafeguardAssetAccount GetAssetAccount(string assetAccountId) { - var response = Connection.InvokeMethod(Service.Core, Method.Get, $"AssetAccounts/{assetAccountId}"); + var response = InvokeMethod(Service.Core, Method.Get, $"AssetAccounts/{assetAccountId}"); return JsonConvert.DeserializeObject(response); } public SafeguardUser GetCurrentUser() { - var response = Connection.InvokeMethod(Service.Core, Method.Get, "Me"); + var response = InvokeMethod(Service.Core, Method.Get, "Me"); return JsonConvert.DeserializeObject(response); } @@ -35,13 +35,13 @@ public List GetEventSubscriptionsForUser(SafeguardUs { {"filter",$"UserId eq {user.Id}"} }; - var response = Connection.InvokeMethod(Service.Core, Method.Get, "EventSubscribers", null, parameters); + var response = InvokeMethod(Service.Core, Method.Get, "EventSubscribers", null, parameters); return JsonConvert.DeserializeObject>(response); } public void CreateEventSubscription(SafeguardEventSubscription eventSubscription) { - Connection.InvokeMethod(Service.Core, Method.Post, "EventSubscribers", JsonConvert.SerializeObject(eventSubscription)); + InvokeMethod(Service.Core, Method.Post, "EventSubscribers", JsonConvert.SerializeObject(eventSubscription)); } public ISafeguardEventListener GetEventListener() @@ -71,6 +71,16 @@ public static bool ValidateSafeguardApplianceAddress(string addr, out JObject re return false; } + private string InvokeMethod(Service service, Method method, string endpoint, string body = null, IDictionary parameters = null, IDictionary additionalHeaders = null, TimeSpan? timeout=null) + { + if (Connection.GetAccessTokenLifetimeRemaining() <= 0) + { + Log.Information("Access Token Expired. Re-authenticating to Safeguard."); + Connection.RefreshAccessToken(); + } + return Connection.InvokeMethod(service, method, endpoint, body, parameters, additionalHeaders, timeout); + } + ISafeguardConnection Connection { get; diff --git a/src/Service/App.config b/src/Service/App.config index d8dc669..0d72028 100644 --- a/src/Service/App.config +++ b/src/Service/App.config @@ -58,7 +58,7 @@ - + @@ -74,15 +74,15 @@ - + - + - + @@ -90,15 +90,15 @@ - + - + - + @@ -108,6 +108,10 @@ + + + + \ No newline at end of file diff --git a/src/Service/Program.cs b/src/Service/Program.cs index 42564b4..b847545 100644 --- a/src/Service/Program.cs +++ b/src/Service/Program.cs @@ -77,6 +77,42 @@ public static void Main() Config.InstallService(v); } }); + x.AddCommandLineDefinition("loglevel", v => + { + var loggerConfig = new LoggerConfiguration(); + + try + { + switch (v) + { + case "information": + loggerConfig = loggerConfig.MinimumLevel.Information(); + break; + case "warning": + loggerConfig = loggerConfig.MinimumLevel.Warning(); + break; + case "debug": + loggerConfig = loggerConfig.MinimumLevel.Debug(); + break; + case "error": + loggerConfig = loggerConfig.MinimumLevel.Error(); + break; + case "verbose": + loggerConfig = loggerConfig.MinimumLevel.Verbose(); + break; + } + + Log.Logger = loggerConfig.WriteTo.Console() + .WriteTo.EventLog(AppName, manageEventSource: true) + .CreateLogger(); + } + catch (SecurityException) + { + Log.Logger = loggerConfig.WriteTo.Console().CreateLogger(); + Log.Warning("Unable to access Windows Event Log. Logging console only"); + } + + }); x.EnableStartParameters(); x.WithStartParameter("ConfigFile", f => { @@ -96,6 +132,7 @@ private static string BuildHelpDoc() "Active Roles JIT Access for Safeguard Command-Line Reference\n" + "------------------------------\n\n"; var test = "\t-test : tests the current configuration\n\n"; + var loglevel = "\t-loglevel : sets the log level for the application. Options: information, warning, debug, error, verbose. Defaults to information.\n\n"; var config = "\t-config : launches configuration workflow and tests configuration. If no file path is provided, the default is used.\n\n"; var installAndConfigureService = "\t-installAndConfigureService : launches configuration workflow, tests configuration, and installs service.\n\n"; var installAndConfigureInstance = "\t-installAndConfigureInstance : prompts for configuration file path, launches configuration workflow, " + @@ -104,7 +141,7 @@ private static string BuildHelpDoc() var footer = "\n------------------------------\n"; - return string.Concat(new String[]{header,test,config,installAndConfigureService,installAndConfigureInstance,configFile,footer}); + return string.Concat(new String[]{header,test,loglevel,config,installAndConfigureService,installAndConfigureInstance,configFile,footer}); } } } diff --git a/src/Service/Service.csproj b/src/Service/Service.csproj index 8c2c32d..6199090 100644 --- a/src/Service/Service.csproj +++ b/src/Service/Service.csproj @@ -40,65 +40,71 @@ ..\packages\Microsoft.AspNet.SignalR.Client.2.4.1\lib\net45\Microsoft.AspNet.SignalR.Client.dll - - ..\packages\Microsoft.AspNetCore.Connections.Abstractions.3.1.7\lib\netstandard2.0\Microsoft.AspNetCore.Connections.Abstractions.dll + + ..\packages\Microsoft.AspNetCore.Connections.Abstractions.3.1.13\lib\netstandard2.0\Microsoft.AspNetCore.Connections.Abstractions.dll - - ..\packages\Microsoft.AspNetCore.Http.Connections.Client.3.1.7\lib\netstandard2.0\Microsoft.AspNetCore.Http.Connections.Client.dll + + ..\packages\Microsoft.AspNetCore.Http.Connections.Client.3.1.13\lib\netstandard2.0\Microsoft.AspNetCore.Http.Connections.Client.dll - - ..\packages\Microsoft.AspNetCore.Http.Connections.Common.3.1.7\lib\netstandard2.0\Microsoft.AspNetCore.Http.Connections.Common.dll + + ..\packages\Microsoft.AspNetCore.Http.Connections.Common.3.1.13\lib\netstandard2.0\Microsoft.AspNetCore.Http.Connections.Common.dll - - ..\packages\Microsoft.AspNetCore.Http.Features.3.1.7\lib\netstandard2.0\Microsoft.AspNetCore.Http.Features.dll + + ..\packages\Microsoft.AspNetCore.Http.Features.3.1.13\lib\netstandard2.0\Microsoft.AspNetCore.Http.Features.dll - - ..\packages\Microsoft.AspNetCore.SignalR.Client.3.1.7\lib\netstandard2.0\Microsoft.AspNetCore.SignalR.Client.dll + + ..\packages\Microsoft.AspNetCore.SignalR.Client.3.1.13\lib\netstandard2.0\Microsoft.AspNetCore.SignalR.Client.dll - - ..\packages\Microsoft.AspNetCore.SignalR.Client.Core.3.1.7\lib\netstandard2.0\Microsoft.AspNetCore.SignalR.Client.Core.dll + + ..\packages\Microsoft.AspNetCore.SignalR.Client.Core.3.1.13\lib\netstandard2.0\Microsoft.AspNetCore.SignalR.Client.Core.dll - - ..\packages\Microsoft.AspNetCore.SignalR.Common.3.1.7\lib\netstandard2.0\Microsoft.AspNetCore.SignalR.Common.dll + + ..\packages\Microsoft.AspNetCore.SignalR.Common.3.1.13\lib\netstandard2.0\Microsoft.AspNetCore.SignalR.Common.dll - - ..\packages\Microsoft.AspNetCore.SignalR.Protocols.Json.3.1.7\lib\netstandard2.0\Microsoft.AspNetCore.SignalR.Protocols.Json.dll + + ..\packages\Microsoft.AspNetCore.SignalR.Protocols.Json.3.1.13\lib\netstandard2.0\Microsoft.AspNetCore.SignalR.Protocols.Json.dll + + + ..\packages\Microsoft.AspNetCore.WebUtilities.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.WebUtilities.dll ..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.1\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll - - ..\packages\Microsoft.Extensions.Configuration.3.1.7\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll + + ..\packages\Microsoft.Extensions.Configuration.3.1.13\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll + + + ..\packages\Microsoft.Extensions.Configuration.Abstractions.3.1.13\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll - - ..\packages\Microsoft.Extensions.Configuration.Abstractions.3.1.7\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll + + ..\packages\Microsoft.Extensions.Configuration.Binder.3.1.13\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll - - ..\packages\Microsoft.Extensions.Configuration.Binder.3.1.7\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll + + ..\packages\Microsoft.Extensions.DependencyInjection.3.1.13\lib\net461\Microsoft.Extensions.DependencyInjection.dll - - ..\packages\Microsoft.Extensions.DependencyInjection.3.1.7\lib\net461\Microsoft.Extensions.DependencyInjection.dll + + ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.3.1.13\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll - - ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.3.1.7\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + ..\packages\Microsoft.Extensions.Logging.3.1.13\lib\netstandard2.0\Microsoft.Extensions.Logging.dll - - ..\packages\Microsoft.Extensions.Logging.3.1.7\lib\netstandard2.0\Microsoft.Extensions.Logging.dll + + ..\packages\Microsoft.Extensions.Logging.Abstractions.3.1.13\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll - - ..\packages\Microsoft.Extensions.Logging.Abstractions.3.1.7\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll + + ..\packages\Microsoft.Extensions.Options.3.1.13\lib\netstandard2.0\Microsoft.Extensions.Options.dll - - ..\packages\Microsoft.Extensions.Options.3.1.7\lib\netstandard2.0\Microsoft.Extensions.Options.dll + + ..\packages\Microsoft.Extensions.Primitives.3.1.13\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll - - ..\packages\Microsoft.Extensions.Primitives.3.1.7\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll + + ..\packages\Microsoft.Net.Http.Headers.2.2.0\lib\netstandard2.0\Microsoft.Net.Http.Headers.dll - - ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\OneIdentity.SafeguardDotNet.6.8.2\lib\netstandard2.0\OneIdentity.SafeguardDotNet.dll + + ..\packages\OneIdentity.SafeguardDotNet.6.9.0\lib\netstandard2.0\OneIdentity.SafeguardDotNet.dll ..\packages\RestSharp.106.11.7\lib\net452\RestSharp.dll @@ -124,12 +130,15 @@ - - ..\packages\System.IO.Pipelines.4.7.1\lib\netstandard2.0\System.IO.Pipelines.dll + + ..\packages\System.IO.Pipelines.4.7.4\lib\net461\System.IO.Pipelines.dll ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll + diff --git a/src/Service/packages.config b/src/Service/packages.config index 8dc06c5..e06954b 100644 --- a/src/Service/packages.config +++ b/src/Service/packages.config @@ -1,27 +1,30 @@  - - - - - - - - + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + + @@ -29,7 +32,7 @@ - + From ce9223a80db91c06534a1966b175ab7e6d6c152a Mon Sep 17 00:00:00 2001 From: aamburn Date: Wed, 21 Apr 2021 16:57:37 -0500 Subject: [PATCH 2/2] Updating version info --- src/Service/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Service/Properties/AssemblyInfo.cs b/src/Service/Properties/AssemblyInfo.cs index 3ab6944..455f904 100644 --- a/src/Service/Properties/AssemblyInfo.cs +++ b/src/Service/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("6.8.0.0")] -[assembly: AssemblyFileVersion("6.8.0.0")] +[assembly: AssemblyVersion("6.9.0.0")] +[assembly: AssemblyFileVersion("6.9.0.0")]