private WindowsIdentity Authenticate(ref Stream netStream, TcpServerSocketHandler streamManager)
 { 
     // Use the identity for impersonation etc. 
     NegotiateStream negoServer = null;
     try 
     {
         negoServer = new NegotiateStream(netStream);
         // Block for authentication request
         TokenImpersonationLevel impLevel = TokenImpersonationLevel.Identification; 
         if (_impersonate)
             impLevel = TokenImpersonationLevel.Impersonation; 
         negoServer.AuthenticateAsServer((NetworkCredential)CredentialCache.DefaultCredentials, _protectionLevel, impLevel); 
         netStream = negoServer;
         return (WindowsIdentity)negoServer.RemoteIdentity; 
     }
     catch
     {
         streamManager.SendErrorResponse( 
             String.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_ServerAuthenticationFailed")), false);
         if (negoServer != null) 
             negoServer.Close(); 
         throw;
     } 
 }
 private WindowsIdentity Authenticate(ref Stream netStream, TcpServerSocketHandler streamManager)
 {
     NegotiateStream stream = null;
     WindowsIdentity remoteIdentity;
     try
     {
         stream = new NegotiateStream(netStream);
         TokenImpersonationLevel identification = TokenImpersonationLevel.Identification;
         if (this._impersonate)
         {
             identification = TokenImpersonationLevel.Impersonation;
         }
         stream.AuthenticateAsServer((NetworkCredential) CredentialCache.DefaultCredentials, this._protectionLevel, identification);
         netStream = stream;
         remoteIdentity = (WindowsIdentity) stream.RemoteIdentity;
     }
     catch
     {
         streamManager.SendErrorResponse(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_ServerAuthenticationFailed"), new object[0]), false);
         if (stream != null)
         {
             stream.Close();
         }
         throw;
     }
     return remoteIdentity;
 }