authentication - Blazor - 使用带有本地 DB 存储库的 ADFS 保护:如何/何时挂钩 SQL
问题描述
我有一个 Blazer Server 应用程序,它现在使用来自本地 ADFS 服务器的身份验证。确定用户后,我现在需要加载他们的权限。我们认为这不能通过 ADFS 服务器的声明来提供,因此希望在数据库中进行配置,但需要了解如何/何时获取此信息。
关于挂钩到 ADFS,我的代码如下(欢迎提出任何改进建议)
App.razor
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<h1>Sorry</h1>
<p>You're not authorized to reach this page.</p>
<p>You may need to log in as a different user.</p>
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<h1>Sorry</h1>
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
appsettings.Development.json
{
"DetailedErrors": "true",
"ConnectionStrings": {
"MyDB": "Data Source=x.x.x.x;Initial Catalog=xxxxx;user id=me;password=sshhh;Persist Security Info=False;"
},
"Ida": {
"ADFSMetadata": "https://adfs.ourServer.com/FederationMetadata/2007-06/FederationMetadata.xml",
"Wtrealm": "https://localhost:44323/"
}
}
Startup.cs(仅显示安全相关代码)
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.WsFederation;
public class Startup
{
public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
.....
app.UseAuthentication();
app.Use(async (context, next) =>
{
context.Response.Headers.Add("X-Frame-Options", "DENY");
var user = context.User;
if (user?.Identities.HasNoItems(identity => identity.IsAuthenticated) ?? true)
{
await context.ChallengeAsync(WsFederationDefaults.AuthenticationScheme).ConfigureAwait(false);
}
if (next != null)
{
await next().ConfigureAwait(false);
}
});
....
}
...
public void ConfigureServices(IServiceCollection services)
{
var wtrealm = this.Configuration.GetSection("Ida:Wtrealm").Value;
var metadataAddress = this.Configuration.GetSection("Ida:ADFSMetadata").Value;
services
.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = WsFederationDefaults.AuthenticationScheme;
})
.AddWsFederation(options =>
{
options.Wtrealm = wtrealm ;
options.MetadataAddress = metadataAddress;
options.UseTokenLifetime = false;
})
.AddCookie();
....
}
}
关于上面的代码有什么建议吗?当用户进入我们的站点(任何页面)时,他们会自动被推送到 ADFS 服务器进行身份验证。似乎还可以,但会阻止用户注销....
因此,我们从 ADFS 中获得了一些标识用户的声明,例如他们的 UPN 名称。我的想法是去数据库并加载该用户拥有的所有角色/权限/权限。
- 我应该在我的代码中的哪个位置放置这样的代码
- 该数据库当前由另一个使用较旧的“成员”表的应用程序使用。我想使用一些更新的东西,身份模型?我不能冒险破坏其他应用程序的安全性。我应该将安全性存储在新数据库中吗?
任何指针都将是最受欢迎的......假设我是这方面的新手。
解决方案
执行此操作的常用方法是为 ADFS编写自定义属性提供程序。
然后您可以从数据库中获取您想要的角色并将它们添加到声明中。
推荐阅读
- angular - 在 viewchild 上以编程方式触发的事件不起作用
- android - 如何在 Google Play 中管理不同企业客户的应用发布版本?
- c++ - 片段着色器是否适用于顶点、片段或像素?
- java - Facing ambiguity in spring constructors, second constructor is getting called
- reactjs - Preact 路由中的延迟加载不起作用
- wpf - 如何让讲述人阅读 WPF 弹出窗口中的文本?
- homebrew - K 框架安装在 MacBookPro 19 OS X Mojave 10.14.6 上反复失败
- r - 桑基图 R 中的百分比
- sql - 两个日期之间的记录 Oracle SQL
- javascript - 如果具有 X 类的对象也具有 Y 类,则执行