C# 如何在没有用户密码的情况下,使用具有用户主体名称(UPN)的模拟用户获取Alfresco登录票证
我正在编写一个DLL,该DLL具有获取Alfresco登录票证的功能,无需使用用户密码,只需使用用户主体名称(UPN)。我正在调用AlfrescoRESTAPI服务/wcservice。我在露天使用NTLM 我正在使用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
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 或者不管你提议什么
祝你好运。
帕科我已经解决了这个问题 我相信我们有一个共同的目标 为了解决这个问题,必须这样做:
- Active Directory的检查表
- 客户申请检查表
- 中层员工检查表
- 后端检查表
- 常见问题的配置示例 情景
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]