Skip to content

Commit

Permalink
Merge pull request #6 from aamburn/master
Browse files Browse the repository at this point in the history
ISSUE 4: Authentication Denied Error and 6.9.0 Release
  • Loading branch information
MattPeterson1 authored Apr 26, 2021
2 parents 4cb3ab2 + ce9223a commit cbd1978
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 75 deletions.
2 changes: 1 addition & 1 deletion src/Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OneIdentity.SafeguardDotNet" Version="6.8.2" />
<PackageReference Include="OneIdentity.SafeguardDotNet" Version="6.9.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
<PackageReference Include="System.DirectoryServices" Version="4.7.0" />
</ItemGroup>
Expand Down
18 changes: 14 additions & 4 deletions src/Common/SafeguardRestApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SafeguardAssetAccount>(response);
}

public SafeguardUser GetCurrentUser()
{
var response = Connection.InvokeMethod(Service.Core, Method.Get, "Me");
var response = InvokeMethod(Service.Core, Method.Get, "Me");
return JsonConvert.DeserializeObject<SafeguardUser>(response);
}

Expand All @@ -35,13 +35,13 @@ public List<SafeguardEventSubscription> 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<List<SafeguardEventSubscription>>(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()
Expand Down Expand Up @@ -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<string, string> parameters = null, IDictionary<string, string> 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;
Expand Down
18 changes: 11 additions & 7 deletions src/Service/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Topshelf" publicKeyToken="b800c4cfcdeea87b" culture="neutral" />
Expand All @@ -74,31 +74,31 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.7.0" newVersion="3.1.7.0" />
<bindingRedirect oldVersion="0.0.0.0-3.1.13.0" newVersion="3.1.13.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.7.0" newVersion="3.1.7.0" />
<bindingRedirect oldVersion="0.0.0.0-3.1.13.0" newVersion="3.1.13.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.7.0" newVersion="3.1.7.0" />
<bindingRedirect oldVersion="0.0.0.0-3.1.13.0" newVersion="3.1.13.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Options" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.7.0" newVersion="3.1.7.0" />
<bindingRedirect oldVersion="0.0.0.0-3.1.13.0" newVersion="3.1.13.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.7.0" newVersion="3.1.7.0" />
<bindingRedirect oldVersion="0.0.0.0-3.1.13.0" newVersion="3.1.13.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.7.0" newVersion="3.1.7.0" />
<bindingRedirect oldVersion="0.0.0.0-3.1.13.0" newVersion="3.1.13.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
Expand All @@ -108,6 +108,10 @@
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
39 changes: 38 additions & 1 deletion src/Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
{
Expand All @@ -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 <file path>: 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 <name>: prompts for configuration file path, launches configuration workflow, " +
Expand All @@ -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});
}
}
}
4 changes: 2 additions & 2 deletions src/Service/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Loading

0 comments on commit cbd1978

Please sign in to comment.