代码之家  ›  专栏  ›  技术社区  ›  Hogan

如何“取消模仿”(取消代表?)在Kerberos中

  •  4
  • Hogan  · 技术社区  · 15 年前

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

    当用户与应用程序连接时,Kerberos身份验证自动神奇地允许我使用委托连接到充当用户的外部资源。这不容易做到。很好,但我有个问题。有时我需要使用一个比用户拥有更多权限的帐户连接到外部资源。运行应用程序池所使用的服务帐户具有我所需的添加权限。如何删除用户的kerberos标识并使用运行应用程序池的服务帐户与kerberos连接?

    更新

    我不知道为什么我没有得到任何回应。我以前从没见过。请张贴问题,他们可能会澄清问题(我也)。


    在kerberos中工作,需要对委派进行概述吗?阅读此答案的第一部分: https://stackoverflow.com/a/19103747/215752 .

    1 回复  |  直到 6 年前
        1
  •  7
  •   Ryan    15 年前

    我有一门课:

    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