3

我正在编写一个 DLL,该 DLL 具有在不使用用户密码的情况下仅使用用户主体名称 (UPN) 获取 Alfresco 登录票的功能。我正在调用 alfresco REST API 服务/wcservice。我在露天使用 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]
4

2 回答 2

4

我已经解决了这个问题!

我相信我们遇到了双跳问题

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

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

这一切(以及更多)都在 Microsoft 文档Troubleshooting Kerberos delegate中进行了解释。它包含:

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

  • 常见场景的配置示例。

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

您可以阅读更多关于ASP.NET 2.0 中的 Windows 身份验证的信息。

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

于 2011-01-20T15:25:04.747 回答
1

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

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

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

还有 URI,像这样:

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

祝你好运。帕科

于 2011-01-12T11:15:39.227 回答