我正在编写一个 DLL,它具有无需使用用户密码、仅使用用户主体名称 (UPN) 即可获取 Alfresco 登录票证的功能。我正在调用露天 REST API 服务 /wc服务. 。我在 Alfresco 中使用 NTLM。

我冒充用户使用 WindowsIdentity 构造函数如此处解释 http://msdn.microsoft.com/en-us/library/ms998351.aspx#paght000023_impersonatingbyusingwindowsidentity. 。我检查过并且用户被正确模拟(我检查过 WindowsIdentity.GetCurrent().Name 财产)。

冒充用户后,我尝试制作 HttpWebRequest 并设置其凭据 CredentialsCache.DefaultNetworkCredentials. 。我收到错误:

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:<NotSet>,Wks:<NotSet>]
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 2003功能域中,此选项仅在您在此用户中注册principal名称时才可用)
  5. 运行我的DLL的用户必须有 TrustedtoAuthfordElegation 用户帐户控制(UAC)设置为true
  6. 运行使用我dll的服务的计算机一定有 将计算机信任委托给任何服务(仅Kerberos) 或者 将计算机信任委托仅指定服务 在域控制器中选择的选项

Microsoft文档中解释了这一切(以及更多) 故障排除Kerberos代表团. 。它包含:

  • Active Directory的清单,
  • 客户端应用程序清单,
  • 中间层的清单,
  • 后端清单

  • 常见方案的配置示例。

环境 TrustedtoAuthfordElegation 用户帐户控制(UAC)是通过Active Directory CMDLET在PowerShell中进行的 这里.

您可以阅读更多有关 Windows身份验证在ASP.NET 2.0中.

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

其他提示

我认为对于 Alfresco 来说这是不可能的。仅当您使用存在此“非个人”用户的特殊身份验证子系统时。

尝试这个,因为“来宾”用户对于所有子系统身份验证都是横向的。

request.Credentials = new NetworkCredential("guest", "guest");

还有 URI,类似这样:

string URI = "http://alfrescoserver/alfresco/s/api/login 或您建议的任何内容。

祝你好运。帕科

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top