private static IPrincipal CopyPrincipal(IPrincipal user)
        {
            // Copy IPrincipal to the new WebSocket object. m_User gets disposed when
            // HttpListenerContext is closed.
            IPrincipal retVal = null;

            if (user != null)
            {
                if (user as WindowsPrincipal == null)
                {
                    // authtype Basic
                    HttpListenerBasicIdentity basicIdentity = user.Identity as HttpListenerBasicIdentity;
                    if (basicIdentity != null)
                    {
                        retVal = new GenericPrincipal((new HttpListenerBasicIdentity(basicIdentity.Name,
                                                                                     basicIdentity.Password)), null);
                    }
                }
                else
                {
                    // Digest, Negotiate, NTLM
                    WindowsIdentity windowsIdentity = (WindowsIdentity)user.Identity;
                    retVal = new WindowsPrincipal(HttpListener.CreateWindowsIdentity(windowsIdentity.Token,
                                                                                     windowsIdentity.AuthenticationType, WindowsAccountType.Normal, true));
                }
            }

            return(retVal);
        }