refactor: 重构代码单点登录移动到UseBootstrapAdmin方法中
#Comment 依赖组件升级 Bootstrap.Security.Mvc 升级到2.2.7 Longbow.Web 升级到2.2.12
This commit is contained in:
parent
5a16cd6c36
commit
9050818d99
|
@ -14,7 +14,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.6" />
|
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.7" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.2" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.2" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.9" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.9" />
|
||||||
|
|
|
@ -3,9 +3,7 @@ using Bootstrap.Security.Filter;
|
||||||
using Longbow.Web;
|
using Longbow.Web;
|
||||||
using Longbow.Web.SignalR;
|
using Longbow.Web.SignalR;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
@ -63,13 +61,10 @@ namespace Bootstrap.Admin
|
||||||
services.AddDbAdapter();
|
services.AddDbAdapter();
|
||||||
services.AddIPLocator(DictHelper.ConfigIPLocator);
|
services.AddIPLocator(DictHelper.ConfigIPLocator);
|
||||||
services.AddOnlineUsers();
|
services.AddOnlineUsers();
|
||||||
var dataProtectionBuilder = services.AddDataProtection(op => op.ApplicationDiscriminator = Configuration["ApplicationDiscriminator"])
|
|
||||||
.SetApplicationName(Configuration["ApplicationName"])
|
|
||||||
.PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPath"]));
|
|
||||||
if (Configuration["DisableAutomaticKeyGeneration"] == "True") dataProtectionBuilder.DisableAutomaticKeyGeneration();
|
|
||||||
services.AddSignalR().AddJsonProtocalDefault();
|
services.AddSignalR().AddJsonProtocalDefault();
|
||||||
services.AddSignalRExceptionFilterHandler<SignalRHub>(async (client, ex) => await SignalRManager.Send(client, ex));
|
services.AddSignalRExceptionFilterHandler<SignalRHub>(async (client, ex) => await SignalRManager.Send(client, ex));
|
||||||
services.AddResponseCompression();
|
services.AddResponseCompression();
|
||||||
|
services.AddBootstrapAdminAuthentication();
|
||||||
services.AddMvc(options =>
|
services.AddMvc(options =>
|
||||||
{
|
{
|
||||||
options.Filters.Add<BootstrapAdminAuthorizeFilter>();
|
options.Filters.Add<BootstrapAdminAuthorizeFilter>();
|
||||||
|
@ -81,11 +76,6 @@ namespace Bootstrap.Admin
|
||||||
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||||
JsonConvert.DefaultSettings = () => options.SerializerSettings;
|
JsonConvert.DefaultSettings = () => options.SerializerSettings;
|
||||||
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||||
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
|
|
||||||
{
|
|
||||||
options.Cookie.Path = "/";
|
|
||||||
if (!string.IsNullOrEmpty(Configuration["Domain"])) options.Cookie.Domain = Configuration["Domain"];
|
|
||||||
});
|
|
||||||
services.AddApiVersioning(option =>
|
services.AddApiVersioning(option =>
|
||||||
{
|
{
|
||||||
option.DefaultApiVersion = new ApiVersion(1, 0);
|
option.DefaultApiVersion = new ApiVersion(1, 0);
|
||||||
|
@ -132,8 +122,7 @@ namespace Bootstrap.Admin
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseResponseCompression();
|
app.UseResponseCompression();
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
app.UseAuthentication();
|
app.UseBootstrapAdminAuthentication(RoleHelper.RetrieveRolesByUserName, RoleHelper.RetrieveRolesByUrl, AppHelper.RetrievesByUserName);
|
||||||
app.UseBootstrapAdminAuthorization(RoleHelper.RetrieveRolesByUserName, RoleHelper.RetrieveRolesByUrl, AppHelper.RetrievesByUserName);
|
|
||||||
app.UseOnlineUsers(callback: TraceHelper.Save);
|
app.UseOnlineUsers(callback: TraceHelper.Save);
|
||||||
app.UseCacheManagerCorsHandler();
|
app.UseCacheManagerCorsHandler();
|
||||||
app.UseSignalR(routes => { routes.MapHub<SignalRHub>("/NotiHub"); });
|
app.UseSignalR(routes => { routes.MapHub<SignalRHub>("/NotiHub"); });
|
||||||
|
|
|
@ -17,9 +17,6 @@
|
||||||
},
|
},
|
||||||
"SwaggerPathBase": "",
|
"SwaggerPathBase": "",
|
||||||
"AllowOrigins": "http://localhost:49185",
|
"AllowOrigins": "http://localhost:49185",
|
||||||
"Domain": null,
|
|
||||||
"KeyPath": "..\\keys",
|
|
||||||
"DisableAutomaticKeyGeneration": false,
|
|
||||||
"LongbowCache": {
|
"LongbowCache": {
|
||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"CorsItems": [
|
"CorsItems": [
|
||||||
|
|
|
@ -51,17 +51,6 @@
|
||||||
],
|
],
|
||||||
"SwaggerPathBase": "/BA",
|
"SwaggerPathBase": "/BA",
|
||||||
"AllowOrigins": "http://localhost,http://argo.zylweb.cn",
|
"AllowOrigins": "http://localhost,http://argo.zylweb.cn",
|
||||||
"Domain": null,
|
|
||||||
"KeyPath": "..\\keys",
|
|
||||||
"ApplicationName": "__bd__",
|
|
||||||
"ApplicationDiscriminator": "BootstrapAdmin",
|
|
||||||
"DisableAutomaticKeyGeneration": false,
|
|
||||||
"TokenValidateOption": {
|
|
||||||
"Issuer": "BA",
|
|
||||||
"Audience": "api",
|
|
||||||
"Expires": 5,
|
|
||||||
"SecurityKey": "BootstrapAdmin-V1.1"
|
|
||||||
},
|
|
||||||
"Sentry" : {
|
"Sentry" : {
|
||||||
"Dsn": "https://70bdfff562e84fa7b9a43d65924ab9ad@sentry.io/1469396"
|
"Dsn": "https://70bdfff562e84fa7b9a43d65924ab9ad@sentry.io/1469396"
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.4" />
|
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.4" />
|
||||||
<PackageReference Include="Longbow.Cache" Version="2.2.10" />
|
<PackageReference Include="Longbow.Cache" Version="2.2.10" />
|
||||||
<PackageReference Include="Longbow.Data" Version="2.3.2" />
|
<PackageReference Include="Longbow.Data" Version="2.3.2" />
|
||||||
<PackageReference Include="Longbow.Web" Version="2.2.11" />
|
<PackageReference Include="Longbow.Web" Version="2.2.12" />
|
||||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.4" />
|
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.6" />
|
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.7" />
|
||||||
<PackageReference Include="Longbow.Logging" Version="2.2.7" />
|
<PackageReference Include="Longbow.Logging" Version="2.2.7" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using Bootstrap.Client.DataAccess;
|
using Bootstrap.Client.DataAccess;
|
||||||
using Longbow.Configuration;
|
using Longbow.Configuration;
|
||||||
|
using Microsoft.AspNetCore;
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
using System;
|
using System;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
|
@ -18,15 +19,21 @@ namespace Bootstrap.Client.Models
|
||||||
public HeaderBarModel(IIdentity identity)
|
public HeaderBarModel(IIdentity identity)
|
||||||
{
|
{
|
||||||
var user = UserHelper.RetrieveUserByUserName(identity.Name);
|
var user = UserHelper.RetrieveUserByUserName(identity.Name);
|
||||||
Icon = $"{ConfigurationManager.AppSettings["AuthHost"]}/{DictHelper.RetrieveIconFolderPath().Trim('~', '/')}/{user.Icon}";
|
|
||||||
DisplayName = user.DisplayName;
|
DisplayName = user.DisplayName;
|
||||||
UserName = user.UserName;
|
UserName = user.UserName;
|
||||||
SettingsUrl = DictHelper.RetrieveSettingsUrl();
|
SettingsUrl = DictHelper.RetrieveSettingsUrl();
|
||||||
ProfilesUrl = DictHelper.RetrieveProfilesUrl();
|
ProfilesUrl = DictHelper.RetrieveProfilesUrl();
|
||||||
NotisUrl = DictHelper.RetrieveNotisUrl();
|
NotisUrl = DictHelper.RetrieveNotisUrl();
|
||||||
var uriBuilder = new UriBuilder(ConfigurationManager.AppSettings["AuthHost"]);
|
|
||||||
uriBuilder.Path = uriBuilder.Path == "/" ? CookieAuthenticationDefaults.LogoutPath.Value : uriBuilder.Path + CookieAuthenticationDefaults.LogoutPath;
|
// set LogoutUrl
|
||||||
|
var authHost = ConfigurationManager.Get<BootstrapAdminOptions>().AuthHost;
|
||||||
|
var uriBuilder = new UriBuilder(authHost);
|
||||||
|
uriBuilder.Path = uriBuilder.Path == "/" ? CookieAuthenticationDefaults.LogoutPath.Value : $"{uriBuilder.Path.TrimEnd('/')}{CookieAuthenticationDefaults.LogoutPath.Value}";
|
||||||
LogoutUrl = uriBuilder.ToString();
|
LogoutUrl = uriBuilder.ToString();
|
||||||
|
|
||||||
|
// set Icon
|
||||||
|
var icon = $"/{DictHelper.RetrieveIconFolderPath().Trim('~', '/')}/{user.Icon}";
|
||||||
|
Icon = $"{authHost.TrimEnd('/')}{icon}";
|
||||||
if (!string.IsNullOrEmpty(user.Css)) Theme = user.Css;
|
if (!string.IsNullOrEmpty(user.Css)) Theme = user.Css;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
using Bootstrap.Client.DataAccess;
|
using Bootstrap.Client.DataAccess;
|
||||||
using Bootstrap.Security.DataAccess;
|
using Bootstrap.Security.DataAccess;
|
||||||
using Bootstrap.Security.Filter;
|
using Bootstrap.Security.Filter;
|
||||||
using Longbow.Web;
|
using Longbow.Web;
|
||||||
using Longbow.Web.SignalR;
|
using Longbow.Web.SignalR;
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
@ -14,7 +12,6 @@ using Microsoft.Extensions.DependencyInjection;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json.Serialization;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace Bootstrap.Client
|
namespace Bootstrap.Client
|
||||||
{
|
{
|
||||||
|
@ -41,12 +38,9 @@ namespace Bootstrap.Client
|
||||||
services.AddConfigurationManager(Configuration);
|
services.AddConfigurationManager(Configuration);
|
||||||
services.AddCacheManager(Configuration);
|
services.AddCacheManager(Configuration);
|
||||||
services.AddDbAdapter();
|
services.AddDbAdapter();
|
||||||
var dataProtectionBuilder = services.AddDataProtection(op => op.ApplicationDiscriminator = Configuration["ApplicationDiscriminator"])
|
|
||||||
.SetApplicationName(Configuration["ApplicationName"])
|
|
||||||
.PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPath"]));
|
|
||||||
if (Configuration["DisableAutomaticKeyGeneration"] == "True") dataProtectionBuilder.DisableAutomaticKeyGeneration();
|
|
||||||
services.AddSignalR().AddJsonProtocalDefault();
|
services.AddSignalR().AddJsonProtocalDefault();
|
||||||
services.AddResponseCompression();
|
services.AddResponseCompression();
|
||||||
|
services.AddBootstrapAdminAuthentication();
|
||||||
services.AddMvc(options =>
|
services.AddMvc(options =>
|
||||||
{
|
{
|
||||||
options.Filters.Add<BootstrapAdminAuthorizeFilter>();
|
options.Filters.Add<BootstrapAdminAuthorizeFilter>();
|
||||||
|
@ -57,12 +51,6 @@ namespace Bootstrap.Client
|
||||||
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||||
JsonConvert.DefaultSettings = () => options.SerializerSettings;
|
JsonConvert.DefaultSettings = () => options.SerializerSettings;
|
||||||
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||||
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
|
|
||||||
{
|
|
||||||
options.Cookie.Path = "/";
|
|
||||||
if (!string.IsNullOrEmpty(Configuration["Domain"])) options.Cookie.Domain = Configuration["Domain"];
|
|
||||||
options.RebuildRedirectUri(Configuration["AuthHost"]);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
|
@ -84,8 +72,7 @@ namespace Bootstrap.Client
|
||||||
app.UseResponseCompression();
|
app.UseResponseCompression();
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
app.UseCookiePolicy();
|
app.UseCookiePolicy();
|
||||||
app.UseAuthentication();
|
app.UseBootstrapAdminAuthentication(RoleHelper.RetrieveRolesByUserName, RoleHelper.RetrieveRolesByUrl, DbHelper.RetrieveAppsByUserName);
|
||||||
app.UseBootstrapAdminAuthorization(RoleHelper.RetrieveRolesByUserName, RoleHelper.RetrieveRolesByUrl, DbHelper.RetrieveAppsByUserName);
|
|
||||||
app.UseCacheManagerCorsHandler();
|
app.UseCacheManagerCorsHandler();
|
||||||
app.UseSignalR(routes => { routes.MapHub<SignalRHub>("/NotiHub"); });
|
app.UseSignalR(routes => { routes.MapHub<SignalRHub>("/NotiHub"); });
|
||||||
app.UseMvc(routes =>
|
app.UseMvc(routes =>
|
||||||
|
|
|
@ -30,8 +30,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"KeyPath": "..\\keys",
|
"BootstrapAdminOptions": {
|
||||||
"AuthHost": "http://localhost:50852",
|
"AuthHost": "http://localhost:50852"
|
||||||
"AllowOrigins": "http://localhost:50852",
|
},
|
||||||
"Domain": null
|
"AllowOrigins": "http://localhost:50852"
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,13 +29,10 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"AppId": 2,
|
"AppId": 2,
|
||||||
"AuthHost": "http://argo.zylweb.cn/BA",
|
"BootstrapAdminOptions": {
|
||||||
"Domain": null,
|
"AuthHost": "http://argo.zylweb.cn/BA"
|
||||||
|
},
|
||||||
"AllowOrigins": "http://localhost,http://argo.zylweb.cn",
|
"AllowOrigins": "http://localhost,http://argo.zylweb.cn",
|
||||||
"KeyPath": "..\\keys",
|
|
||||||
"ApplicationName": "__bd__",
|
|
||||||
"ApplicationDiscriminator": "BootstrapAdmin",
|
|
||||||
"DisableAutomaticKeyGeneration": true,
|
|
||||||
"LongbowCache": {
|
"LongbowCache": {
|
||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"CacheItems": [
|
"CacheItems": [
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<PackageReference Include="Longbow.Data" Version="2.3.2" />
|
<PackageReference Include="Longbow.Data" Version="2.3.2" />
|
||||||
<PackageReference Include="Longbow.Logging" Version="2.2.7" />
|
<PackageReference Include="Longbow.Logging" Version="2.2.7" />
|
||||||
<PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" />
|
<PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" />
|
||||||
<PackageReference Include="Longbow.Web" Version="2.2.11" />
|
<PackageReference Include="Longbow.Web" Version="2.2.12" />
|
||||||
<PackageReference Include="Longbow.Cache" Version="2.2.10" />
|
<PackageReference Include="Longbow.Cache" Version="2.2.10" />
|
||||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.4" />
|
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.4" />
|
||||||
<PackageReference Include="PetaPoco.Extensions" Version="1.0.5" />
|
<PackageReference Include="PetaPoco.Extensions" Version="1.0.5" />
|
||||||
|
|
Loading…
Reference in New Issue