Compare commits
4 Commits
eac1ab3929
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| b08d88ee0f | |||
| 58f228dc6f | |||
| a68cb68c5c | |||
| f78b8dfd9e |
@@ -4,14 +4,16 @@
|
|||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Version>1.0.0-beta</Version>
|
<Version>1.0.1-beta</Version>
|
||||||
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
<AssemblyVersion>1.0.1.0</AssemblyVersion>
|
||||||
<FileVersion>1.0.0.0</FileVersion>
|
<FileVersion>1.0.1.0</FileVersion>
|
||||||
<InformationalVersion>1.0.0-beta</InformationalVersion>
|
<InformationalVersion>1.0.1-beta</InformationalVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="8.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="8.0.0" />
|
||||||
|
<PackageReference Include="NLog" Version="6.1.1" />
|
||||||
|
<PackageReference Include="NLog.Web.AspNetCore" Version="6.1.2" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
106
Program.cs
106
Program.cs
@@ -1,34 +1,44 @@
|
|||||||
using Microsoft.AspNetCore.Authentication.Negotiate;
|
using Microsoft.AspNetCore.Authentication.Negotiate;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
using NLog;
|
||||||
|
using NLog.Web;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
|
||||||
|
logger.Info("Logging initialized!");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
if (!builder.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
builder.Logging.ClearProviders();
|
||||||
|
builder.Host.UseNLog();
|
||||||
|
}
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
|
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
|
||||||
.AddNegotiate();
|
.AddNegotiate();
|
||||||
builder.Services.AddAuthorization();
|
builder.Services.AddAuthorization();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen(options =>
|
builder.Services.AddSwaggerGen(options =>
|
||||||
{
|
|
||||||
options.SwaggerDoc("v1", new OpenApiInfo
|
|
||||||
{
|
{
|
||||||
Title = "FakeNTLMServer",
|
options.SwaggerDoc("v1", new OpenApiInfo
|
||||||
Version = "v1",
|
{
|
||||||
Description = "NTLM/Negotiate authentication test server"
|
Title = "FakeNTLMServer",
|
||||||
});
|
Version = "v1",
|
||||||
|
Description = "NTLM/Negotiate authentication test server"
|
||||||
|
});
|
||||||
|
|
||||||
options.AddSecurityDefinition("Negotiate", new OpenApiSecurityScheme
|
options.AddSecurityDefinition("Negotiate", new OpenApiSecurityScheme
|
||||||
{
|
{
|
||||||
Type = SecuritySchemeType.Http,
|
Type = SecuritySchemeType.Http,
|
||||||
Scheme = "Negotiate",
|
Scheme = "Negotiate",
|
||||||
Description = "Windows Authentication (NTLM/Kerberos). Credentials are sent automatically by the browser."
|
Description = "Windows Authentication (NTLM/Kerberos). Credentials are sent automatically by the browser."
|
||||||
});
|
});
|
||||||
|
|
||||||
options.AddSecurityRequirement(new OpenApiSecurityRequirement
|
options.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
new OpenApiSecurityScheme
|
new OpenApiSecurityScheme
|
||||||
@@ -43,30 +53,36 @@ builder.Services.AddSwaggerGen(options =>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var xmlFile = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
var xmlFile = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||||
if (File.Exists(xmlPath))
|
if (File.Exists(xmlPath))
|
||||||
options.IncludeXmlComments(xmlPath);
|
options.IncludeXmlComments(xmlPath);
|
||||||
});
|
|
||||||
|
|
||||||
var app = builder.Build();
|
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
|
||||||
if (app.Environment.IsDevelopment() || app.Configuration.GetValue<bool>("EnableSwagger"))
|
|
||||||
{
|
|
||||||
app.UseSwagger();
|
|
||||||
app.UseSwaggerUI(options =>
|
|
||||||
{
|
|
||||||
// Enable sending credentials (NTLM tokens) with Swagger UI requests
|
|
||||||
options.ConfigObject.AdditionalItems["withCredentials"] = true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
// Configure the HTTP request pipeline.
|
||||||
|
if (app.Environment.IsDevelopment() || app.Configuration.GetValue<bool>("EnableSwagger"))
|
||||||
|
{
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI(options =>
|
||||||
|
{
|
||||||
|
// Enable sending credentials (NTLM tokens) with Swagger UI requests
|
||||||
|
options.ConfigObject.AdditionalItems["withCredentials"] = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
app.UseAuthentication();
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
|
app.Run();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
app.UseHttpsRedirection();
|
{
|
||||||
|
logger.Error(ex, "Stopped program because of exception");
|
||||||
app.UseAuthentication();
|
throw;
|
||||||
app.UseAuthorization();
|
}
|
||||||
|
|
||||||
app.MapControllers();
|
|
||||||
|
|
||||||
app.Run();
|
|
||||||
@@ -11,5 +11,48 @@
|
|||||||
"Protocols": "Http1"
|
"Protocols": "Http1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"EnableSwagger": true
|
"EnableSwagger": true,
|
||||||
|
"NLog": {
|
||||||
|
"throwConfigExceptions": true,
|
||||||
|
"variables": {
|
||||||
|
"logDirectory": "E:\\LogFiles\\Digital Data\\FakeNTLMServer",
|
||||||
|
"logFileNamePrefix": "${shortdate}-FakeNTLMServer"
|
||||||
|
},
|
||||||
|
"targets": {
|
||||||
|
"infoLogs": {
|
||||||
|
"type": "File",
|
||||||
|
"fileName": "${logDirectory}\\${logFileNamePrefix}-Info.log",
|
||||||
|
"maxArchiveDays": 30
|
||||||
|
},
|
||||||
|
"errorLogs": {
|
||||||
|
"type": "File",
|
||||||
|
"fileName": "${logDirectory}\\${logFileNamePrefix}-Error.log",
|
||||||
|
"maxArchiveDays": 30
|
||||||
|
},
|
||||||
|
"criticalLogs": {
|
||||||
|
"type": "File",
|
||||||
|
"fileName": "${logDirectory}\\${logFileNamePrefix}-Critical.log",
|
||||||
|
"maxArchiveDays": 30
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Trace, Debug, Info, Warn, Error and *Fatal*
|
||||||
|
"rules": [
|
||||||
|
{
|
||||||
|
"logger": "*",
|
||||||
|
"minLevel": "Info",
|
||||||
|
"maxLevel": "Warn",
|
||||||
|
"writeTo": "infoLogs"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"logger": "*",
|
||||||
|
"level": "Error",
|
||||||
|
"writeTo": "errorLogs"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"logger": "*",
|
||||||
|
"level": "Fatal",
|
||||||
|
"writeTo": "criticalLogs"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user