简体   繁体   English

WCF,Active Directory身份验证|授权和sql组合中的用户配置文件

[英]WCF, active directory authentication|authorization and user profiles in sql combination

I'm developing a WCF service that will host business logic of the application. 我正在开发一个WCF服务,它将托管应用程序的业务逻辑。 The application is mostly for intranet, but can be accessed from internet. 该应用程序主要用于Intranet,但可以从Internet访问。 We have an active directory domain up and running, so I plan to authenticate and authorize users according to their username and groups they are in. This service will be used mostly be an ASP.NET MVC site 我们已经启动并运行了一个活动目录域,因此我计划根据用户所在的用户名和组对用户进行身份验证和授权。该服务将主要用于ASP.NET MVC网站

So, first question is how to authenticate and authorize users based on their AD profile? 因此,第一个问题是如何根据用户的AD配置文件对用户进行身份验证和授权?

Secondly, I need to store additional info about each user. 其次,我需要存储有关每个用户的其他信息。 The problem is that I can't modify AD scheme. 问题是我无法修改AD方案。 The number of added fields is about 10 or so. 添加字段的数量约为10个左右。

Can I somehow use SQL server for profile storage? 我可以以某种方式使用SQL Server进行配置文件存储吗? Of course I can, but how to tie this with AD auth? 我当然可以,但是如何将此与AD auth绑定在一起?

You can use WIF for this. 您可以为此使用WIF。

You would configure your WCF service for WIF in the normal way and then use a custom ClaimsAuthenticationManager class deriving from the base ClaimsAuthenticationManager and overriding its Authenticate method. 您将以常规方式为WIF配置WCF服务,然后使用从基本ClaimsAuthenticationManager并覆盖其Authenticate方法的自定义ClaimsAuthenticationManager类。 This is a normal extensibility point of WIF. 这是WIF的正常扩展点。 WIF will get hold of the security token from the incoming request and add claims for each of the relevant AD properties. WIF将从传入请求中获取安全令牌,并为每个相关AD属性添加声明。 In your override of the Authenticate method, you will add new claims to represent your extra properties. 在对Authenticate方法的覆盖中,您将添加新的声明来表示您的额外属性。

The basic use of WIF for WCF services is described here: WIF用于WCF服务的基本用法描述如下:

http://msdn.microsoft.com/en-us/library/ee748476.aspx http://msdn.microsoft.com/en-us/library/ee748476.aspx

To see how to use ClaimsAuthenticationManager, start here: 要查看如何使用ClaimsAuthenticationManager,请从此处开始:

http://msdn.microsoft.com/en-us/library/ee748211.aspx http://msdn.microsoft.com/en-us/library/ee748211.aspx

Well, I think you have a couple of choices here, but you will have to carefully consider the implementation. 好吧,我认为您在这里有两个选择,但是您将必须仔细考虑实现。

The primary issue with using active directory authentication is that by default a user's credentials can only be passed successfully between two machines. 使用活动目录身份验证的主要问题是,默认情况下,用户凭据只能在两台计算机之间成功传递。 In the case of a web application, this means that the user's credentials can travel between the end user's machine and the web server, but no further. 对于Web应用程序,这意味着用户的凭据可以在最终用户的计算机和Web服务器之间传播,但不能再传播。

However, this behavior can be changed through the use of Kerberos authentication, which essentially allows an authentication ticket to be passed among all of the trusted machines in the chain (ie from the web server to the application server to the database, for example). 但是,可以通过使用Kerberos身份验证来更改此行为,它实质上允许在链中所有受信任的机器之间传递身份验证票证(例如,从Web服务器到应用程序服务器再到数据库)。 Successfully configuring Kerberos can be extremely challenging, especially if you have had no prior experience with it. 成功配置Kerberos可能会极具挑战性,特别是如果您以前没有使用它的经验。

I think your best bet is to configure your web site to accept only Windows Authentication. 我认为最好的选择是将您的网站配置为仅接受Windows身份验证。 This means that IIS will perform the validation of the user against active directory. 这意味着IIS将针对活动目录执行用户验证。 In your ASP.Net application you can pickup the domain name of the authorized user from Request.ServerVariables("logon_user"). 在ASP.Net应用程序中,您可以从Request.ServerVariables(“ logon_user”)中提取授权用户的域名。

At this point, you can log the user on with FormsAuthentication, for example, without requiring them to login again. 此时,例如,您可以使用FormsAuthentication登录用户,而无需他们再次登录。

You could then either implement the SQL Server Membership Provider or create your own interface to your database for further user validation and extra information storage. 然后,您可以实现SQL Server成员资格提供程序,也可以创建自己的数据库接口,以进行进一步的用户验证和其他信息存储。 We have used both mechanisms, but I prefer the self-built one due to the additional control it provides and, in this case, you won't need a lot of the functionality (password reset, recovery, etc) that the membership provider offers. 我们已经使用了这两种机制,但是由于它提供了额外的控制,因此我更喜欢自行构建的机制,在这种情况下,您将不需要成员资格提供程序提供的很多功能(密码重置,恢复等) 。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM