init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
|
@ -0,0 +1,76 @@
|
|||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using Kreta.Web.Logging.Logger;
|
||||
|
||||
namespace Kreta.User.WebApi.RequestResponseLogger
|
||||
{
|
||||
class AuthenticateRequestBodyRenderer : LoggingFieldRenderer
|
||||
{
|
||||
const string SecretLogValue = "***";
|
||||
|
||||
const string Password = nameof(Password);
|
||||
|
||||
const string UserName = nameof(UserName);
|
||||
|
||||
public override void Render(string fieldName, LoggingFieldRendererContext context)
|
||||
{
|
||||
var contentBodyString = context.GetFieldValue(fieldName) as string;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(contentBodyString))
|
||||
{
|
||||
try
|
||||
{
|
||||
string userName = null;
|
||||
|
||||
NameValueCollection contentBodyElements = HttpUtility.ParseQueryString(contentBodyString);
|
||||
|
||||
foreach (string key in contentBodyElements.AllKeys)
|
||||
{
|
||||
if (string.Equals(key, Password, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
contentBodyElements[key] = SecretLogValue;
|
||||
}
|
||||
|
||||
if (string.Equals(key, UserName, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
userName = contentBodyElements[key];
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(userName))
|
||||
{
|
||||
var requestUserIdentifier = new StringBuilder(userName.ToUpper());
|
||||
|
||||
var requestUri = context.GetFieldValue(RequestResponseLoggingFields.Request.Uri) as string;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(requestUri))
|
||||
{
|
||||
requestUserIdentifier.Append('/');
|
||||
|
||||
try
|
||||
{
|
||||
var uri = new Uri(requestUri);
|
||||
requestUserIdentifier.Append(uri.Authority.Split('.')[0]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
requestUserIdentifier.Append($"[{ex.Message}]");
|
||||
}
|
||||
}
|
||||
|
||||
context.SetFieldValue(RequestResponseLoggingFields.Request.User, requestUserIdentifier.ToString());
|
||||
}
|
||||
|
||||
context.SetFieldValue(fieldName, contentBodyElements.ToString());
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
context.SetFieldValue(fieldName, ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue