Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在没有用户密码的情况下,使用具有用户主体名称(UPN)的模拟用户获取Alfresco登录票证_C#_Authentication_Alfresco_Impersonation_Defaultnetworkcredentials - Fatal编程技术网

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

C# 如何在没有用户密码的情况下,使用具有用户主体名称(UPN)的模拟用户获取Alfresco登录票证,c#,authentication,alfresco,impersonation,defaultnetworkcredentials,C#,Authentication,Alfresco,Impersonation,Defaultnetworkcredentials,我正在编写一个DLL,该DLL具有获取Alfresco登录票证的功能,无需使用用户密码,只需使用用户主体名称(UPN)。我正在调用AlfrescoRESTAPI服务/wcservice。我在露天使用NTLM 我正在使用WindowsIdentity构造函数模拟用户,如下所述。我选中了,并且用户被正确模拟(我选中了WindowsIdentity.GetCurrent().Nameproperty) 在模拟用户之后,我尝试进行HttpWebRequest,并使用CredentialsCache.De

我正在编写一个DLL,该DLL具有获取Alfresco登录票证的功能,无需使用用户密码,只需使用用户主体名称(UPN)。我正在调用AlfrescoRESTAPI服务/wcservice。我在露天使用NTLM

我正在使用
WindowsIdentity
构造函数模拟用户,如下所述。我选中了,并且用户被正确模拟(我选中了
WindowsIdentity.GetCurrent().Name
property)

在模拟用户之后,我尝试进行
HttpWebRequest
,并使用
CredentialsCache.DefaultNetworkCredentials
设置其凭据。我得到一个错误:

The remote server returned an error: (401) Unauthorized.
   at System.Net.HttpWebRequest.GetResponse()
当我使用
新网络凭据(“用户名”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:04550调试[app.servlet.NTLMAuthenticationFilter]处理请求:/alfresco/wcservice/mg/util/login SID:7453F7BD4FD2E6A61AD40A31A37733A5
17:18:04550调试[web.scripts.DeclarativeRegistry]uri/mg/util/login的web脚本索引查找耗时0.526239ms
17:18:04550调试[app.servlet.NTLMAuthenticationFilter]来自10.*.*.*(10.*.*.*:1229)的新NTLM身份验证请求
17:18:04566调试[app.servlet.NTLMAuthenticationFilter]处理请求:/alfresco/wcservice/mg/util/login SID:7453F7BD4FD2E6A61AD40A31A37733A5
17:18:04566调试[web.scripts.DeclarativeRegistry]uri/mg/util/login的web脚本索引查找耗时0.400909ms
17:18:04566调试[app.servlet.NTLMAuthenticationFilter]收到类型1[type1:0xe20882b7,域:,Wks:]
17:18:04566调试[app.servlet.NTLMAuthenticationFilter]客户端域空
17:18:04675调试[app.servlet.NTLMAuthenticationFilter]将NTLM type2发送到客户端-[type2:0x8000283,目标:AlfrescoServer,Ch:197E2631C3C3F9E0A]

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

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

request.Credentials=新网络凭据(“来宾”、“来宾”)

还有URI,类似这样:

字符串URI=”http://alfrescoserver/alfresco/s/api/login 或者不管你提议什么

祝你好运。
帕科

我已经解决了这个问题

我相信我们有一个共同的目标

为了解决这个问题,必须这样做:

  • 运行我的DLL的用户必须是Windows Server 2003域 用户
  • 使用我的DLL的服务必须具有 在中注册的服务主体名称 具有以下用户的域控制器: 运行它(运行我的DLL的用户)
  • 运行我的DLL的用户必须没有 帐户敏感,无法删除 已在域中选择委派的选项 控制器
  • 运行我的DLL的用户必须具有 信任此用户以将其委派给 任何服务(仅限Kerberos)信任 此用户需要授权给 仅限指定服务选项 在域控制器中选择(如果 用户位于Windows Server 2003中 功能域此选项为 仅当您注册时可用 具有此名称的服务主体名称 (用户)
  • 运行my DLL的用户必须将TrustedTouthForElegation用户帐户控制(UAC)设置为true
  • 运行服务的计算机,该服务使用 我的DLL必须具有信任计算机的 对任何服务的委托(Kerberos) 仅适用于)信任计算机 指定服务的委托 仅在域中选择了选项 控制器
  • Microsoft文档中解释了这一切(以及更多)。它包含:

    • Active Directory的检查表
    • 客户申请检查表
    • 中层员工检查表
    • 后端检查表
    加上

    • 常见问题的配置示例 情景
    通过Active Directory cmdlet在PowerShell中完成删除用户帐户控制(UAC)的设置

    你可以阅读更多关于

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

    如果我使用,我需要提供用户密码作为我试图避免的参数。我相信我尝试做的应该是可能的。我需要做的就是为HTTP请求获取正确的凭据。可能我有双跳问题(),我正在阅读Microsoft关于Kerberos委派()疑难解答的文档,试图解决此问题。我仍然需要帮助。
    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]