Skip to content

Commit

Permalink
Now, I am corresponding to #77 and #111.
Browse files Browse the repository at this point in the history
  • Loading branch information
daisukenishino2 committed Jun 20, 2019
1 parent cae74f9 commit 62c4f5b
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 135 deletions.
123 changes: 43 additions & 80 deletions root/programs/CommonLibrary/Extensions/Sts/IssuedTokenProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,48 @@ namespace MultiPurposeAuthSite.Extensions.Sts
public class IssuedTokenProvider
{
/// <summary>
/// OAuth2RevocationProvider
/// IssuedTokenBean
/// (メモリストア用)
/// </summary>
private class IssuedTokenBean
{
/// <summary>Value</summary>
public string Value = "";
/// <summary>ClientID</summary>
public string ClientID = "";
/// <summary>Audience</summary>
public string Audience = "";
/// <summary>CreatedDate</summary>
public DateTime CreatedDate = DateTime.MinValue;
}

/// <summary>
/// IssuedTokenProvider
/// ConcurrentDictionaryは、.NET 4.0の新しいスレッドセーフなHashtable
/// </summary>
private static ConcurrentDictionary<string, DateTime> IssuedTokens = new ConcurrentDictionary<string, DateTime>();
private static ConcurrentDictionary<string, IssuedTokenBean>
IssuedTokens = new ConcurrentDictionary<string, IssuedTokenBean>();

#region Create

/// <summary>Create</summary>
/// <param name="jti">string</param>
public static void Create(string jti)
/// <param name="value">string</param>
/// <param name="clientID">string</param>
/// <param name="audience">string</param>
public static void Create(string jti, string value, string clientID, string audience)
{
switch (Config.UserStoreType)
{
case EnumUserStoreType.Memory:
IssuedTokenProvider.IssuedTokens.TryAdd(jti, DateTime.Now);
IssuedTokenProvider.IssuedTokens.TryAdd(
jti,
new IssuedTokenBean() {
Value = value,
ClientID = clientID,
Audience = audience,
CreatedDate = DateTime.Now,
});
break;

case EnumUserStoreType.SqlServer:
Expand All @@ -78,24 +105,30 @@ public static void Create(string jti)
case EnumUserStoreType.SqlServer:

cnn.Execute(
"INSERT INTO [OAuth2Revocation] ([Jti], [CreatedDate]) VALUES (@Jti, @CreatedDate)",
new { Jti = jti, CreatedDate = DateTime.Now });
"INSERT INTO [IssuedToken]" +
" ([Jti], [Value], [ClientID], [Audience], [CreatedDate])" +
" VALUES (@Jti, @Value, @ClientID, @Audience, @CreatedDate)",
new { Jti = jti, Value = value, ClientID = clientID, Audience = audience, CreatedDate = DateTime.Now });

break;

case EnumUserStoreType.ODPManagedDriver:

cnn.Execute(
"INSERT INTO \"OAuth2Revocation\" (\"Jti\", \"CreatedDate\") VALUES (:Jti, :CreatedDate)",
new { Jti = jti, CreatedDate = DateTime.Now });
"INSERT INTO \"IssuedToken\"" +
" (\"Jti\", \"Value\", \"ClientID\", \"Audience\", \"CreatedDate\")" +
" VALUES (:Jti, :Value, :ClientID, :Audience, :CreatedDate)",
new { Jti = jti, Value = value, ClientID = clientID, Audience = audience, CreatedDate = DateTime.Now });

break;

case EnumUserStoreType.PostgreSQL:

cnn.Execute(
"INSERT INTO \"oauth2revocation\" (\"jti\", \"createddate\") VALUES (@Jti, @CreatedDate)",
new { Jti = jti, CreatedDate = DateTime.Now });
"INSERT INTO \"issuedtoken\"" +
" (\"jti\", \"value\", \"clientid\", \"audience\", \"createddate\")" +
" VALUES (@Jti, @Value, @ClientID, @Audience, @CreatedDate)",
new { Jti = jti, Value = value, ClientID = clientID, Audience = audience, CreatedDate = DateTime.Now });

break;
}
Expand All @@ -106,75 +139,5 @@ public static void Create(string jti)
}

#endregion

#region Get(Reference)

/// <summary>Get</summary>
/// <param name="jti">string</param>
/// <returns>DateTime?</returns>
public static DateTime? Get(string jti)
{
DateTime? datetime = null;

switch (Config.UserStoreType)
{
case EnumUserStoreType.Memory:

DateTime temp = DateTime.MinValue;
if (IssuedTokenProvider.IssuedTokens.TryGetValue(jti, out temp))
{
datetime = temp;
}

break;

case EnumUserStoreType.SqlServer:
case EnumUserStoreType.ODPManagedDriver:
case EnumUserStoreType.PostgreSQL: // DMBMS

using (IDbConnection cnn = DataAccess.CreateConnection())
{
cnn.Open();

switch (Config.UserStoreType)
{
case EnumUserStoreType.SqlServer:

datetime = cnn.ExecuteScalar<DateTime>(
"SELECT [CreatedDate] FROM [OAuth2Revocation] WHERE [Jti] = @Jti", new { Jti = jti });

break;

case EnumUserStoreType.ODPManagedDriver:

datetime = cnn.ExecuteScalar<DateTime>(
"SELECT \"CreatedDate\" FROM \"OAuth2Revocation\" WHERE \"Jti\" = :Jti", new { Jti = jti });

break;

case EnumUserStoreType.PostgreSQL:

datetime = cnn.ExecuteScalar<DateTime>(
"SELECT \"createddate\" FROM \"oauth2revocation\" WHERE \"jti\" = @Jti", new { Jti = jti });

break;
}
}

break;
}

// {0001/01/01 00:00} チェック
if (datetime == DateTime.MinValue)
{
return null;
}
else
{
return datetime;
}
}

#endregion
}
}
82 changes: 50 additions & 32 deletions root/programs/CommonLibrary/Extensions/Sts/RequestObjectProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,42 @@ namespace MultiPurposeAuthSite.Extensions.Sts
/// </summary>
public class RequestObjectProvider
{
/// <summary>
/// RequestObjectBean
/// (メモリストア用)
/// </summary>
private class RequestObjectBean
{
/// <summary>Value</summary>
public string Value = "";
/// <summary>CreatedDate</summary>
public DateTime CreatedDate = DateTime.MinValue;
}

/// <summary>
/// RequestObjects
/// ConcurrentDictionaryは、.NET 4.0の新しいスレッドセーフなHashtable
/// </summary>
private static ConcurrentDictionary<string, DateTime> RequestObjects = new ConcurrentDictionary<string, DateTime>();
private static ConcurrentDictionary<string, RequestObjectBean>
RequestObjects = new ConcurrentDictionary<string, RequestObjectBean>();

#region Create

/// <summary>Create</summary>
/// <param name="jti">string</param>
public static void Create(string jti)
/// <param name="urn">string</param>
/// <param name="value">string</param>
public static void Create(string urn, string value)
{
switch (Config.UserStoreType)
{
case EnumUserStoreType.Memory:
RequestObjectProvider.RequestObjects.TryAdd(jti, DateTime.Now);

RequestObjectProvider.RequestObjects.TryAdd(
urn,
new RequestObjectBean{
Value = value,
CreatedDate = DateTime.Now
});
break;

case EnumUserStoreType.SqlServer:
Expand All @@ -78,24 +98,30 @@ public static void Create(string jti)
case EnumUserStoreType.SqlServer:

cnn.Execute(
"INSERT INTO [OAuth2Revocation] ([Jti], [CreatedDate]) VALUES (@Jti, @CreatedDate)",
new { Jti = jti, CreatedDate = DateTime.Now });
"INSERT INTO [RequestObject]" +
" ([Urn], [Value], [CreatedDate])" +
" VALUES (@Urn, @Value, @CreatedDate)",
new { Urn = urn, Value = value, CreatedDate = DateTime.Now });

break;

case EnumUserStoreType.ODPManagedDriver:

cnn.Execute(
"INSERT INTO \"OAuth2Revocation\" (\"Jti\", \"CreatedDate\") VALUES (:Jti, :CreatedDate)",
new { Jti = jti, CreatedDate = DateTime.Now });
"INSERT INTO \"RequestObject\"" +
" (\"Urn\", \"Value\", \"CreatedDate\")" +
" VALUES (:Urn, :Value, :CreatedDate)",
new { Urn = urn, Value = value, CreatedDate = DateTime.Now });

break;

case EnumUserStoreType.PostgreSQL:

cnn.Execute(
"INSERT INTO \"oauth2revocation\" (\"jti\", \"createddate\") VALUES (@Jti, @CreatedDate)",
new { Jti = jti, CreatedDate = DateTime.Now });
"INSERT INTO \"requestobject\"" +
" (\"urn\", \"value\", \"createddate\")" +
" VALUES (@Urn, @Value, @CreatedDate)",
new { Urn = urn, Value = value, CreatedDate = DateTime.Now });

break;
}
Expand All @@ -110,20 +136,20 @@ public static void Create(string jti)
#region Get(Reference)

/// <summary>Get</summary>
/// <param name="jti">string</param>
/// <returns>DateTime?</returns>
public static DateTime? Get(string jti)
/// <param name="urn">string</param>
/// <returns>RequestObject</returns>
public static string Get(string urn)
{
DateTime? datetime = null;
string requestObjectValue = "";

switch (Config.UserStoreType)
{
case EnumUserStoreType.Memory:

DateTime temp = DateTime.MinValue;
if (RequestObjectProvider.RequestObjects.TryGetValue(jti, out temp))
RequestObjectBean requestObject = null;
if (RequestObjectProvider.RequestObjects.TryGetValue(urn, out requestObject))
{
datetime = temp;
requestObjectValue = requestObject.Value;
}

break;
Expand All @@ -140,22 +166,22 @@ public static void Create(string jti)
{
case EnumUserStoreType.SqlServer:

datetime = cnn.ExecuteScalar<DateTime>(
"SELECT [CreatedDate] FROM [OAuth2Revocation] WHERE [Jti] = @Jti", new { Jti = jti });
requestObjectValue = cnn.ExecuteScalar<string>(
"SELECT [Value] FROM [RequestObject] WHERE [Urn] = @Urn", new { Urn = urn });

break;

case EnumUserStoreType.ODPManagedDriver:

datetime = cnn.ExecuteScalar<DateTime>(
"SELECT \"CreatedDate\" FROM \"OAuth2Revocation\" WHERE \"Jti\" = :Jti", new { Jti = jti });
requestObjectValue = cnn.ExecuteScalar<string>(
"SELECT \"Value\" FROM \"RequestObject\" WHERE \"Urn\" = :Urn", new { Urn = urn });

break;

case EnumUserStoreType.PostgreSQL:

datetime = cnn.ExecuteScalar<DateTime>(
"SELECT \"createddate\" FROM \"oauth2revocation\" WHERE \"jti\" = @Jti", new { Jti = jti });
requestObjectValue = cnn.ExecuteScalar<string>(
"SELECT \"value\" FROM \"requestobject\" WHERE \"urn\" = @Urn", new { Urn = urn });

break;
}
Expand All @@ -164,15 +190,7 @@ public static void Create(string jti)
break;
}

// {0001/01/01 00:00} チェック
if (datetime == DateTime.MinValue)
{
return null;
}
else
{
return datetime;
}
return requestObjectValue;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public class RevocationProvider
/// OAuth2RevocationProvider
/// ConcurrentDictionaryは、.NET 4.0の新しいスレッドセーフなHashtable
/// </summary>
private static ConcurrentDictionary<string, DateTime> OAuth2Revocation = new ConcurrentDictionary<string, DateTime>();
private static ConcurrentDictionary<string, DateTime>
OAuth2Revocation = new ConcurrentDictionary<string, DateTime>();

#region Create

Expand Down
Loading

0 comments on commit 62c4f5b

Please sign in to comment.