如何在Kerberos中"取消模仿"(un-delegate?)

Hog*_*gan 4 asp.net iis kerberos

我有一个使用Kerberos访问使用ASP.NET 3.5和IIS的外部资源的Web应用程序.

当用户与应用程序连接时,Kerberos身份验证会自动允许我使用委派连接到充当用户的外部资源.这不容易做到.这很好,但我有一个问题.有时我需要使用权限多于用户的帐户连接到外部资源.app-pool运行的服务帐户具有我需要的附加权限.如何使用运行应用程序池的服务帐户删除用户的Kerberos标识并使用Kerberos连接?

UPDATE

我不知道为什么我没有得到任何答复.我以前从未见过这个.请发布问题,他们可能会澄清问题(对我而言).


在Kerberos中学习并需要概述授权?阅读本答案的第一部分:https://stackoverflow.com/a/19103747/215752.

Rya*_*yan 7

我有一节课:

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
}
Run Code Online (Sandbox Code Playgroud)

我这样使用它:

using(ProcessIdentityScope identityScope = new ProcessIdentityScope())
{
    // Any code in here runs under the Process Identity.
}
Run Code Online (Sandbox Code Playgroud)

此代码基于此MSDN文章:http://msdn.microsoft.com/en-us/library/ms998351.aspx