简体   繁体   English

ASP.NET中的Windows身份验证模式使用Active Directory组名称(Windows 2000之前的版本)?

[英]Windows authentication mode in ASP.NET uses the Active Directory group name (pre-Windows 2000)?

Here is the background. 这是背景。 I had an .NET MVC v1.0 project that I was trying to secure it by using Windows authentication mode. 我有一个.NET MVC v1.0项目,我试图通过使用Windows身份验证模式来保护它。 So I set the web.config to: 所以我将web.config设置为:

<authentication mode="Windows" />

And then went into my controller and did the following: 然后进入我的控制器并执行以下操作:

[Authorize(Roles="IT")]
public class LicenseController : Controller

In AD we have a group called "IT" and I am many others are apart of this group. 在AD中,我们有一个名为“IT”的小组,而我和其他许多小组都是这个小组的一部分。 Once I had this in place I started a debug session and tried going to any of the actions in that controller and I was met with a 401. I search high and low looking for somewhere that I had screwed the pooch and couldn't find anything wrong. 一旦我有了这个,我开始一个调试会话,并试图去控制器中的任何一个动作,我遇到了一个401.我搜索高低寻找某个地方,我搞砸了小狗,找不到任何东西错误。 After a while of struggling I decided to try changing the "Authorize" to a specific user an see if that worked. 经过一段时间的努力,我决定尝试将“授权”更改为特定用户,看看是否有效。 So I changed it to the following: 所以我把它改成了以下内容:

[Authorize(Users="domain\\tnederveld")]

And low and behold that worked. 而且看起来很有效。 So I went and added a different group that I was a member of and took out the users authorize statement and that worked. 所以我去了一个不同的小组,我是其中的一员,并取出了用户授权声明,并且有效。 I started looking into the differences between the two AD groups and the only thing that was different was on the second group I tried the "Group name (pre-Windows 2000):" were the same. 我开始研究两个AD组之间的差异,唯一不同的是第二组我尝试了“组名(pre-Windows 2000):”是相同的。 The "IT" groups "Group name (pre-Windows 2000):" was "IT Associates". “IT”组“组名(pre-Windows 2000):”是“IT Associates”。 So I tried changing the authorize statement to: 所以我尝试将authorize语句更改为:

[Authorize(Roles="IT Associates")]

And it started working. 它开始工作了。 I thought for sure this was an MVC issue, so to make sure I tried it on a regular Web Forms project and was meet with the same issue. 我确信这是一个MVC问题,所以为了确保我在常规的Web Forms项目上尝试它并遇到了同样的问题。

The real kicker is that when you use the UserPrincipal that is part of the System.DirectoryServices.AccountManagement it returns the group "IT" when using the .GetGroups() method. 真正的问题是,当您使用属于System.DirectoryServices.AccountManagement的UserPrincipal时,它会在使用.GetGroups()方法时返回组“IT”。

Why is this is happening? 为什么会这样?

You need to keep apart the various names an entry in AD can have: 您需要将AD中的条目的各种名称分开:

  • the name per se is typically the CN attribute - the Common Name. 名称本身通常是CN属性 - 公共名称。 This is the "CN=xxx" part in your LDAP string. 这是LDAP字符串中的“CN = xxx”部分。 Here it's IT - and that's what System.DirectoryServices.AccountManagement will return - it's the "Active Directory"'s most common name 这就是IT - 这就是System.DirectoryServices.AccountManagement将返回的内容 - 它是“Active Directory”最常见的名称

  • the "IT Associates" name is the pre-Windows 2000 or sAMAccountName - the thing Windows NT used to use before there was AD - a local user and/or group name (SAM = Security Account Management or something like that). “IT Associates”名称是Windows 2000之前或sAMAccountName - Windows NT在AD之前使用的东西 - 本地用户和/或组名(SAM =安全帐户管理或类似的东西)。 The SAM Account Name needs to be unique per domain - even in a huge AD forest these days. SAM帐户名称每个域都必须是唯一的 - 即使在如今的巨大AD林中也是如此。

Unfortunately, lots of the Windows API calls are still based on that name - since they are (and need to be) backwards compatible with earlier Windows versions. 不幸的是,许多Windows API调用仍然基于该名称 - 因为它们(并且需要)向后兼容早期的Windows版本。 The ASP.NET membership system uses those calls and thus will use your domain/tnederveld user name and IT Associates group - those are the SAM account names of your objects ASP.NET成员资格系统使用这些调用,因此将使用您的domain/tnederveld用户名和IT Associates组 - 这些是您的对象的SAM帐户名

Not sure if there's much you can do about it - just be aware that in a AD environment, any of your user or groups has a plethora of "names" - always be very clear about which one you're talking about! 不确定你能做多少事情 - 只要知道在AD环境中,你的任何用户或群体都有很多“名字” - 总是非常清楚你在谈论哪一个!

For a detailed list of all AD attributes, see Richard Mueller's excellent web site with Active Directory reference material . 有关所有AD属性的详细列表,请参阅Richard Mueller使用Active Directory参考资料优秀网站

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有Asp.net Windows身份验证的活动目录 - Active directory with Asp.net windows authentication 对另一个Active Directory域的ASP.NET Windows身份验证 - ASP.NET Windows authentication to another Active Directory domain ASP.NET MVC 5:应用程序池,Windows身份验证和Active Directory - ASP.NET MVC 5: App Pool, Windows Authentication and Active Directory 具有Windows身份验证aganst Active Directory的Asp.net WebPage - Asp.net WebPage with Windows Authentication aganst Active Directory ASP.NET应用程序通过Windows身份验证或表单身份验证对Active Directory或SQL进行身份验证 - ASP.NET Application to authenticate to Active Directory or SQL via Windows Authentication or Forms Authentication ASP.NET身份+ Windows身份验证(混合模式 - 表单+ Windows) - ASP.NET Identity + Windows Authentication (Mix mode - Forms + Windows) Asp.Net Windows身份验证:是否可以不询问登录用户是否已经登录到活动目录? - Asp.Net windows authentication: is it possible not to ask login if user is already logged in active directory? 具有活动目录和Windows身份验证的asp.net c#Web应用程序 - asp.net c# web app with active directory and windows authentication Windows 2000上的ASP.NET 3.5 - ASP.NET 3.5 on Windows 2000 根据ASP.NET Windows身份验证的用户名与Active Directory中的登录名不匹配 - Username according to ASP.NET Windows auth doesn't match logon name in Active Directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM