Scenario:
An ASP.NET 2.0 app that uses Windows Integrated Authentication needs to be able interact with a web service which accepts Kerberos tokens for authentication. The user context of the web service call must match the end user of the ASP.NET app, and their password is not known. Both the ASP.NET app and web service reside on Win 2008 servers within the same domain on the company intranet. Here is what I am trying to do:
WindowsIdentity winid = (WindowsIdentity)HttpContext.Current.User.Identity
WindowsImpersonationContext ctx = null;
try
{
// Start impersonating
ctx = winId.Impersonate();
// Now impersonating
// Access resources using the identity of the authenticated user
KerberosToken kt = new KerberosToken(
targetPrincipal,
ImpersonationLevel.Identification );
// Access web service using generated token
....
}
finally
{
// Revert impersonation
if( ctx != null )
ctx.U ...
Go to the complete details ...