ASP kerberos 委派场景中的双跳请求
ASP double hop request in kerberos delegation scenario
请帮忙!
我需要我的 asp 应用程序来请求具有模拟用户凭据的远程系统。但是总是得到 401 Unauthorized 错误。
我从这里进行了所有配置:
Kerberos 已配置并在我的应用程序和我的测试远程应用程序中工作(我在 fiddler 中看到了 kerberos 票证)。委派、spns 和一切都已配置。
那是我的代码usnig System.Net.Http.httpclient:
HttpClientHandler handler = new HttpClientHandler()
{
UseDefaultCredentials = true,
PreAuthenticate = true
};
using (HttpClient client = new HttpClient(handler))
{
client.DefaultRequestHeaders.Accept.Clear();
var method = new HttpMethod("GET");
var request = new HttpRequestMessage(method, "http://testdelegationapp.avp.ru/");
var response = client.SendAsync(request).Result;
}
事实上 http 请求是由 Apppool 帐户发出的(在远程应用程序 IIS 中限制访问 Apppool 帐户时出现 401 错误)
此处:
声称 HttpClient 无法将安全令牌传递给另一个线程,最好使用 System.Net.WebClient
的同步方法
使用网络客户端的代码:
var wi = (WindowsIdentity)HttpContext.User.Identity;
var wic = wi.Impersonate();
try
{
string URI = "http://testdelegationapp.avp.ru/";
using (WebClient wc = new WebClient())
{
wc.UseDefaultCredentials = true;
string response = wc.DownloadString(URI);
}
}
finally
{
wic.Undo();
}
结果更糟,同样的 401 错误,但在 fiddler 中我可以看到网络客户端使用 NTLM 票证访问远程应用程序!
流动令牌的配置从这里抛出线程:
也没有帮助。 SecurityContext.IsWindowsIdentityFlowSuppressed() 为假。
WindowsIdentity.GetCurrent().Name 和 Thread.CurrentPrincipal.Identity.Name 显示了应有的模拟用户。
所有时间问题都在 chrome 浏览器中,默认情况下它禁止 kerberos 委派。您应该将以下内容添加到注册表中:
Path: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome ;
string: AuthNegotiateDelegateWhitelist ;
value: *.avp.ru
所以,现在我的工作配置是
用于 Web 请求的 HttpClient。
ASP 如果您想在 IIS 下执行所有应用程序,则在 IIS 中启用模拟
委托凭证。如果你想要方法特定的委托,那么使用:
var wi = (WindowsIdentity)HttpContext.User.Identity;
var wic = wi.Impersonate();
wic.Undo();
HttpClient 在另一个线程中执行请求,因此在 aspnet_config.config 中我们需要进行以下更改:
<legacyImpersonationPolicy enabled="false"/>
<alwaysFlowImpersonationPolicy enabled="true"/>
您可以在以下位置找到 aspnet_config.config:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet.config
C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet.config
请帮忙! 我需要我的 asp 应用程序来请求具有模拟用户凭据的远程系统。但是总是得到 401 Unauthorized 错误。 我从这里进行了所有配置: Kerberos 已配置并在我的应用程序和我的测试远程应用程序中工作(我在 fiddler 中看到了 kerberos 票证)。委派、spns 和一切都已配置。
那是我的代码usnig System.Net.Http.httpclient:
HttpClientHandler handler = new HttpClientHandler()
{
UseDefaultCredentials = true,
PreAuthenticate = true
};
using (HttpClient client = new HttpClient(handler))
{
client.DefaultRequestHeaders.Accept.Clear();
var method = new HttpMethod("GET");
var request = new HttpRequestMessage(method, "http://testdelegationapp.avp.ru/");
var response = client.SendAsync(request).Result;
}
事实上 http 请求是由 Apppool 帐户发出的(在远程应用程序 IIS 中限制访问 Apppool 帐户时出现 401 错误)
此处: 声称 HttpClient 无法将安全令牌传递给另一个线程,最好使用 System.Net.WebClient
的同步方法使用网络客户端的代码:
var wi = (WindowsIdentity)HttpContext.User.Identity;
var wic = wi.Impersonate();
try
{
string URI = "http://testdelegationapp.avp.ru/";
using (WebClient wc = new WebClient())
{
wc.UseDefaultCredentials = true;
string response = wc.DownloadString(URI);
}
}
finally
{
wic.Undo();
}
结果更糟,同样的 401 错误,但在 fiddler 中我可以看到网络客户端使用 NTLM 票证访问远程应用程序!
流动令牌的配置从这里抛出线程: 也没有帮助。 SecurityContext.IsWindowsIdentityFlowSuppressed() 为假。
WindowsIdentity.GetCurrent().Name 和 Thread.CurrentPrincipal.Identity.Name 显示了应有的模拟用户。
所有时间问题都在 chrome 浏览器中,默认情况下它禁止 kerberos 委派。您应该将以下内容添加到注册表中:
Path: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome ;
string: AuthNegotiateDelegateWhitelist ;
value: *.avp.ru
所以,现在我的工作配置是
用于 Web 请求的 HttpClient。
ASP 如果您想在 IIS 下执行所有应用程序,则在 IIS 中启用模拟 委托凭证。如果你想要方法特定的委托,那么使用:
var wi = (WindowsIdentity)HttpContext.User.Identity;
var wic = wi.Impersonate();
wic.Undo();
HttpClient 在另一个线程中执行请求,因此在 aspnet_config.config 中我们需要进行以下更改:
<legacyImpersonationPolicy enabled="false"/>
<alwaysFlowImpersonationPolicy enabled="true"/>
您可以在以下位置找到 aspnet_config.config:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet.config
C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet.config