如何在没有用户密码的情况下获取Alfresco登录票证,但使用用户主体名称(UPN)模拟用户

我正在编写一个DLL,它具有在不使用用户密码的情况下获取Alfresco登录票证的function,仅使用用户主体名称(UPN)。 我正在调用alfresco REST API服务/ wcservice 。 我在Alfresco使用NTLM。

我正在冒充使用WindowsIdentity构造函数的用户,如http://msdn.microsoft.com/en-us/library/ms998351.aspx#paght000023_impersonatingbyusingwindowsidentity所述 。 我检查并且用户被正确模拟(我检查了WindowsIdentity.GetCurrent().Name属性)。

在模仿用户之后,我尝试使用CredentialsCache.DefaultNetworkCredentials制作HttpWebRequest并设置其凭据。 我收到错误:

 The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() 

当我使用new NetworkCredential("username", "P@ssw0rd")来设置请求凭据时,我获得了Alfresco登录票证( HttpStatusCode.OK ,200)。

有没有办法可以在没有用户密码的情况下获得Alfresco登录票?

这是我正在使用的代码:

 private string GetTicket(string UPN) { WindowsIdentity identity = new WindowsIdentity(UPN); WindowsImpersonationContext context = null; try { context = identity.Impersonate(); MakeWebRequest(); } catch (Exception e) { return e.Message + Environment.NewLine + e.StackTrace; } finally { if (context != null) { context.Undo(); } } } private string MakeWebRequest() { string URI = "http://alfrescoserver/alfresco/wcservice/mg/util/login"; HttpWebRequest request = WebRequest.Create(URI) as HttpWebRequest; request.CookieContainer = new CookieContainer(1); //request.Credentials = new NetworkCredential("username", "p@ssw0rd"); // It works with this request.Credentials = CredentialCache.DefaultNetworkCredentials; // It doesn't work with this //request.Credentials = CredentialCache.DefaultCredentials; // It doesn't work with this either try { using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { StreamReader sr = new StreamReader(response.GetResponseStream()); return sr.ReadToEnd(); } } catch (Exception e) { return (e.Message + Environment.NewLine + e.StackTrace); } } 

以下是来自Alfresco stdout.log的记录(如果它有任何帮助):

 17:18:04,550 DEBUG [app.servlet.NTLMAuthenticationFilter] Processing request: /alfresco/wcservice/mg/util/login SID:7453F7BD4FD2E6A61AD40A31A37733A5 17:18:04,550 DEBUG [web.scripts.DeclarativeRegistry] Web Script index lookup for uri /mg/util/login took 0.526239ms 17:18:04,550 DEBUG [app.servlet.NTLMAuthenticationFilter] New NTLM auth request from 10.**.**.** (10.**.**.**:1229) 17:18:04,566 DEBUG [app.servlet.NTLMAuthenticationFilter] Processing request: /alfresco/wcservice/mg/util/login SID:7453F7BD4FD2E6A61AD40A31A37733A5 17:18:04,566 DEBUG [web.scripts.DeclarativeRegistry] Web Script index lookup for uri /mg/util/login took 0.400909ms 17:18:04,566 DEBUG [app.servlet.NTLMAuthenticationFilter] Received type1 [Type1:0xe20882b7,Domain:,Wks:] 17:18:04,566 DEBUG [app.servlet.NTLMAuthenticationFilter] Client domain null 17:18:04,675 DEBUG [app.servlet.NTLMAuthenticationFilter] Sending NTLM type2 to client - [Type2:0x80000283,Target:AlfrescoServerA,Ch:197e2631cc3f9e0a] 

我已经解决了这个问题!

我相信我们有一个双跳问题 。

这是解决这个问题所必须做的事情:

  1. 运行我的DLL的用户必须是Windows Server 2003域用户
  2. 使用我的DLL的服务必须在域控制器中注册服务主体名称与运行它的用户(运行我的DLL的用户)
  3. 运行我的DLL的用户必须没有帐户敏感,并且无法在域控制器中选择委派选项
  4. 运行我的DLL的用户必须信任此用户以便委派任何服务(仅限Kerberos)信任此用户以获取在域控制器中选择的仅指定服务选项(如果用户位于Windows Server 2003function域中此选项仅可用)当您向此用户注册服务主体名称时)
  5. 运行我的DLL的用户必须将TrustedToAuthForDelegation用户帐户控制(UAC)设置为true
  6. 运行使用我的DLL的服务的计算机必须具有用于委派任何服务的 Trust计算机 (仅限Kerberos)用于委派给域控制器中的指定服务的Trust计算机选项

在Microsoft文档疑难解答Kerberos委派中解释了这一切(以及更多)。 它包含:

  • Active Directory清单,
  • 客户申请清单,
  • 中层清单,
  • 后端核对清单

  • 常见方案的配置示例。

设置TrustedToAuthForDelegation用户帐户控制(UAC)是在PowerShell中通过此处说明的Active Directory cmdlet完成的。

您可以在ASP.NET 2.0中阅读有关Windows身份validation的更多信息。

当然,Alfresco必须启用Kerberos登录。

我认为Alfresco不可能。 只有当您使用特殊身份validation子系统时,才会存在此“非个人”用户。

试试这个,因为’guest’用户对所有子系统身份validation都是横向的。

request.Credentials = new NetworkCredential(“guest”,“guest”);

和URI,像这样:

string URI =“http:// alfrescoserver / alfresco / s / api / login或者你提出的任何建议。

祝好运。 帕科

Interesting Posts