我有一个使用 Kerberos 的 Web 应用程序来使用 ASP.NET 3.5 和 IIS 访问外部资源。
当用户连接到应用程序时,Kerberos 身份验证会自动允许我使用委派作为用户连接到外部资源。这并不容易做到。这很好,但我有一个问题。有时我需要使用比用户拥有更多权限的帐户连接到外部资源。应用程序池运行的服务帐户具有我需要的附加权限。如何删除用户的 Kerberos 标识并使用运行应用程序池的服务帐户与 Kerberos 连接?
UPDATE
我不知道为什么我根本没有收到任何回复。我以前从未见过这样的情况。请发布问题,他们可能会澄清问题(对我来说也是如此)。
使用 Kerberos 并需要了解委派概述?阅读这个答案的第一部分:https://stackoverflow.com/a/19103747/215752 https://stackoverflow.com/a/19103747/215752.
我有一堂课:
public class ProcessIdentityScope : IDisposable
{
private System.Security.Principal.WindowsImpersonationContext _impersonationContext;
private bool _disposed;
public ProcessIdentityScope()
{
_impersonationContext = System.Security.Principal.WindowsIdentity.Impersonate(IntPtr.Zero);
}
#region IDisposable Members
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
_impersonationContext.Undo();
_impersonationContext.Dispose();
_disposed = true;
}
else
throw new ObjectDisposedException("ProcessIdentityScope");
}
#endregion
}
我这样使用它:
using(ProcessIdentityScope identityScope = new ProcessIdentityScope())
{
// Any code in here runs under the Process Identity.
}
该代码基于这篇 MSDN 文章:http://msdn.microsoft.com/en-us/library/ms998351.aspx http://msdn.microsoft.com/en-us/library/ms998351.aspx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)