Skip to content

Commit

Permalink
change policy types to an enum. Detect OS version to set the WID conn…
Browse files Browse the repository at this point in the history
…ection string
  • Loading branch information
Douglas Bienstock authored and Douglas Bienstock committed Mar 5, 2019
1 parent 0457899 commit 2d503fe
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
48 changes: 29 additions & 19 deletions ADFSDump/ReadDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ public static class DatabaseReader
public static Dictionary<string, RelyingParty>.ValueCollection ReadConfigurationDb()
{
SqlConnection conn = null;
string connectionString = "";
var os = Environment.OSVersion;
if ((os.Version.Major == 6 && os.Version.Minor <= 1) || os.Version.Major < 6)
{
// we are on 2008 R2 or below which means legacy
connectionString = WidConnectionStringLegacy;
}
else
{
connectionString = WidConnectionString;
}
try
{
conn = new SqlConnection(WidConnectionString);
conn = new SqlConnection(connectionString);
conn.Open();
} catch (SqlException)
{
try
{
conn = new SqlConnection(WidConnectionStringLegacy);
conn.Open();
} catch(SqlException x)
{
Console.WriteLine($"!!! Error connecting to WID. Are you sure AD FS is configured for WID?\n {x}");
}

} catch (Exception e)
} catch (Exception e)
{
Console.WriteLine($"!!! Error connecting to WID.\n {e}");
Environment.Exit(1);
Expand Down Expand Up @@ -189,12 +189,22 @@ private static Dictionary<string, RelyingParty>.ValueCollection ReadWid(string d
if (rps.Keys.Contains(scopeId) && !string.IsNullOrEmpty(rule))
{

int ruleType = (int)reader["PolicyUsage"];
if (ruleType == 4) { rps[scopeId].StrongAuthRules = rule; }
else if (ruleType == 3) { rps[scopeId].OnBehalfAuthRules = rule; }
else if (ruleType == 2) { rps[scopeId].ActAsAuthRules = rule; }
else if (ruleType == 1) { rps[scopeId].AuthRules = rule; }
else { rps[scopeId].IssuanceRules = rule; }
PolicyType ruleType = (PolicyType)reader["PolicyUsage"];
switch (ruleType)
{
case PolicyType.StrongAuthAuthorizationRules:
rps[scopeId].StrongAuthRules = rule;
break;
case PolicyType.OnBehalfAuthorizationRules:
rps[scopeId].OnBehalfAuthRules = rule;
break;
case PolicyType.ActAsAuthorizationRules:
rps[scopeId].AuthRules = rule;
break;
case PolicyType.IssuanceRules:
rps[scopeId].IssuanceRules = rule;
break;
}

}

Expand Down
9 changes: 9 additions & 0 deletions ADFSDump/RelyingPartyTrust.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

namespace ADFSDump.RelyingPartyTrust
{
public enum PolicyType
{
IssuanceRules,
AuthorizationRules,
ActAsAuthorizationRules,
OnBehalfAuthorizationRules,
StrongAuthAuthorizationRules
}

public class RelyingParty
{
public string Id
Expand Down

0 comments on commit 2d503fe

Please sign in to comment.