如何从Web应用程序中的客户端计算机获取AD凭据?

时间:2008-10-10 17:27:30

标签: asp.net .net web-applications authentication active-directory

是否可以在Web应用程序中从客户端计算机上获取用户的activedirectory凭据?

为了澄清,我正在设计一个将在客户的Intranet上托管的Web应用程序。

要求在访问应用程序时不提示应用程序的用户提供凭据,而是应该自动获取登录到客户端计算机的用户凭据,而无需用户交互。

4 个答案:

答案 0 :(得分:5)

绝对。这对于Intranet应用程序尤其有用。

由于你没有指定你的环境,我认为它是.NET,但这当然不是唯一可行的方法。

使用LDAP可以轻松查询Active Directory。如果您使用的是.NET,则可以执行this code example或以下示例中的操作。你也可以在SQL environments内完成。

如果您只需要Windows来处理身份验证,则可以为Windows Authentication设置.NET Web应用程序。确保在IIS中为您的应用程序turn off Anonymous Logins。完成后,您将能够访问用户的Windows登录名并使用它进行进一步的安全检查(例如,他们在AD中的group/role membership)。

您还可以使用Enterprise Library的Security Application Block

之类的东西来简化整个混乱

这是一个简短的C#示例:(转换为VB.NET here

using System.DirectoryServices;

/// <summary>
/// Gets the email address, if defined, of a user from Active Directory.
/// </summary>
/// <param name="userid">The userid of the user in question.  Make
/// sure the domain has been stripped first!</param>
/// <returns>A string containing the user's email address, or null
/// if one was not defined or found.</returns>
public static string GetEmail(string userid)
{
    DirectorySearcher searcher;
    SearchResult result;
    string email;

    // Check first if there is a slash in the userid
    // If there is, domain has not been stripped
    if (!userid.Contains("\\"))
    {
        searcher = new DirectorySearcher();
        searcher.Filter = String.Format("(SAMAccountName={0})", userid);
        searcher.PropertiesToLoad.Add("mail");
        result = searcher.FindOne();
        if (result != null)
        {
            email = result.Properties["mail"][0].ToString();
        }
    }

    return email;
}

您不必指定域控制器。对DirectorySearcher执行empty / default构造函数会导致它尝试自动查找 - 事实上,这是the preferred method

答案 1 :(得分:1)

也许.NET有更直接的方法,但使用PHP我只是将我们的Active Directory服务器作为LDAP服务器访问。

我不确定要对服务器进行哪些调整才能执行此操作。我没有设置服务器,我只是查询它。 我不是建议你使用PHP。我发现更容易处理LDAP然后尝试直接绑定到Active Directory。

答案 2 :(得分:1)

Windows集成身份验证,用户必须使用IE,并且该站点必须位于用户的可信站点中。如果这些都是真的,那么IE会将您的Windows安全令牌传递给网站,它将通过它进行身份验证。我们在内部网上使用SharePoint执行此操作,否则访问任何受限制的内容都很痛苦 - 每次单击文档时都会提示您。

答案 3 :(得分:0)

不,当然不是。你能想象导致随机网络应用程序能够获得你的AD用户名和密码的破坏吗?

现在,如果你只想要用户名 - 如果你正在使用integated windows auth,那就是REMOTE_USER。并且,Windows身份验证将自动登录用户到您的站点 - 假设您共享域(或信任)。

编辑:IWA在Intranet方案中工作,因为IE(默认情况下)包括Intranet安全区域中的Intranet站点。此外,系统管理员可以使用GPO设置其他可信站点。 Firefox也是supports NTLMOperaChrome也一样。总而言之,设置内部网并不是一种糟糕的方式。

但请注意 - 您没有获得凭据。您与客户协商令牌,这是IWA保持安全(以及我的上述观点)。