【问题标题】:How to ensafe ActiveDirectory authentication in ASP.NET如何确保 ASP.NET 中的 Active Directory 身份验证
【发布时间】:2015-08-20 03:45:01
【问题描述】:

我有一个用于某种管理的网站。它只能在域网络中使用,并且必须非常安全。这就是我决定使用现有域身份验证的原因。我已打开 Windows 身份验证和模拟。现在,当我打开这个网站时,用户已经获得了WindowsIdentity 的授权。

第一个问题是如何安全地检查域组内的用户身份。我的意思是,如果用户通过非域帐户进行身份验证,我不应该让他进入。
例如,用户使用他的本地计算机管理员用户登录到 Windows,打开我的网站,User.Identity.IsAuthenticated 是否为真(因为他是 Windows 用户,无论如何)?也许,我应该检查某种证书、来源或所有者。如何确定我们的用户属于我们的域并且不是入侵者?

第二个问题是:我需要确定一个用户是否属于某个组。我有一个组的 ID:S-1-5-21-1455132813-...。是否可以使用此 ID 来识别组?我只是不确定这些 ID 有多静态。也许,有更合适的方法来检查它。

现在,我是这样做的:

private readonly _allowedGroupId; // read from a config

var wi = WindowsIdentity.GetCurrent();
if (wi.IsAuthenticated && wi.Groups.Any(x => x.Value == _allowedGroupId))
{
    // authorized
}

【问题讨论】:

    标签: c# asp.net asp.net-mvc authentication active-directory


    【解决方案1】:

    要检查 Windows 角色,您应该使用角色管理器:

    <roleManager enabled="true" defaultProvider="WindowsProvider">
      <providers>
        <clear/>
        <add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
      </providers>
    </roleManager>
    

    并检查代码中的角色:

    Roles.IsUserInRole(@"domain\active_directory_role_name")
    

    【讨论】:

    • 耶!这正是我一直在寻找的。另外,我在System.DirectoryServices 中发现了很多有趣的东西:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-25
    相关资源
    最近更新 更多