【问题标题】:Asp.Net MVC SSO - Deny Access to DB UserAsp.Net MVC SSO - 拒绝访问数据库用户
【发布时间】:2020-09-20 19:28:27
【问题描述】:

我正在将 SSO 引入旧版应用程序。我需要管理的一项现有功能是检查用户是否可以在登录后访问应用程序。以前,如果他们登录,他们的帐户将根据 db 表进行检查,他们将被注销系统一条消息说,如果他们的访问被拒绝,他们必须联系支持人员。如果可能,我正在寻找新的 SSO 登录时相同的功能。因此,下面的代码的 sn-p。任何建议将不胜感激。

 Notifications = new OpenIdConnectAuthenticationNotifications
            {
                AuthenticationFailed = OnAuthenticationFailed,
                SecurityTokenValidated = (context) =>
                {
                    ClaimsIdentity identity = context.AuthenticationTicket.Identity;

                    // check the database if the user is locked from accessing the system
                    var userEmail = identity.FindFirst("preferred_username").Value;

                    var currentUser = UsersTable.Where(user => user.Email == userEmail);

                    if (currentUser != null ) 
                    {
                        if (currentUser.AccessLocked)
                        {
                            at this point I need to prevent the user for using the system. My preferred option would be to
                            Force logout, and redirect back to the login page, with a message saying that user access is locked

                            The other option 
                            // 2 - Add Roles on each of the controller (IsActive) and add a Claim Role Type for a user who does have access
                            identity.AddClaim(new Claim(ClaimTypes.Role, "IsActive"));
                            I have tried this, but I get stuck in a authorisation loop when the user doesn not have the Role
                        }
                    }
                }
            }

【问题讨论】:

    标签: asp.net-mvc azure-active-directory single-sign-on openid-connect


    【解决方案1】:

    集成 SSO 后的不同之处在于您现在有两步行为:

    • 身份验证外包给多个应用的​​ SSO 系统,用户可能只拥有其中一部分的权限
    • 然后您应用应用程序特定授权来查看用户是否有权使用特定应用程序或特定视图

    最标准的解决方案是避免让用户退出,这可能会导致重定向循环或其他技术复杂性。相反,您应该致力于将此类用户重定向到应用内的拒绝访问页面

    按照您的建议,在 C# 中,我将使用基于过滤器 + 声明的解决方案来实现这些目标。但是,您需要避免使用“身份验证过滤器”,它的失败操作是重定向用户。

    【讨论】:

    • 谢谢加里。我解决了这个问题。我在声明中添加了一个角色类型、一个 AuthorizeAttribute 子类和一个拒绝访问页面。完美地完成工作
    猜你喜欢
    • 2014-06-14
    • 2012-06-20
    • 2017-05-30
    • 2014-12-21
    • 2015-12-26
    • 1970-01-01
    • 2015-05-28
    • 2018-06-24
    • 2012-01-27
    相关资源
    最近更新 更多