diff --git a/websocket-sharp/Net/HttpListenerAsyncResult.cs b/websocket-sharp/Net/HttpListenerAsyncResult.cs index 17b283a5..909f15bf 100644 --- a/websocket-sharp/Net/HttpListenerAsyncResult.cs +++ b/websocket-sharp/Net/HttpListenerAsyncResult.cs @@ -108,34 +108,30 @@ namespace WebSocketSharp.Net #region Private Methods - private static bool authenticate (HttpListenerContext context) + private static bool authenticate ( + HttpListenerContext context, + AuthenticationSchemes scheme, + string realm, + Func credentialsFinder) { - var listener = context.Listener; - var schm = listener.SelectAuthenticationScheme (context); - if (schm == AuthenticationSchemes.Anonymous) - return true; - - if (schm == AuthenticationSchemes.None) { + if (scheme == AuthenticationSchemes.None) { context.Response.Close (HttpStatusCode.Forbidden); return false; } var req = context.Request; - var realm = listener.Realm; var user = HttpUtility.CreateUser ( - req.Headers["Authorization"], schm, realm, req.HttpMethod, listener.UserCredentialsFinder); + req.Headers["Authorization"], scheme, realm, req.HttpMethod, credentialsFinder); if (user != null && user.Identity.IsAuthenticated) { context.User = user; - req.IsAuthenticated = true; - return true; } - if (schm == AuthenticationSchemes.Basic) + if (scheme == AuthenticationSchemes.Basic) context.Response.CloseWithAuthChallenge ( AuthenticationChallenge.CreateBasicChallenge (realm).ToBasicString ()); - else if (schm == AuthenticationSchemes.Digest) + else if (scheme == AuthenticationSchemes.Digest) context.Response.CloseWithAuthChallenge ( AuthenticationChallenge.CreateDigestChallenge (realm).ToDigestString ()); else @@ -186,8 +182,11 @@ namespace WebSocketSharp.Net internal void Complete (HttpListenerContext context, bool syncCompleted) { - if (!authenticate (context)) { - context.Listener.BeginGetContext (this); + var listener = context.Listener; + var schm = listener.SelectAuthenticationScheme (context); + if (schm != AuthenticationSchemes.Anonymous && + !authenticate (context, schm, listener.Realm, listener.UserCredentialsFinder)) { + listener.BeginGetContext (this); return; } diff --git a/websocket-sharp/Net/HttpListenerRequest.cs b/websocket-sharp/Net/HttpListenerRequest.cs index 12d1ad88..383a1151 100644 --- a/websocket-sharp/Net/HttpListenerRequest.cs +++ b/websocket-sharp/Net/HttpListenerRequest.cs @@ -59,7 +59,6 @@ namespace WebSocketSharp.Net private static readonly byte[] _100continue; private string[] _acceptTypes; - private bool _authenticated; private bool _chunked; private Encoding _contentEncoding; private long _contentLength; @@ -242,11 +241,7 @@ namespace WebSocketSharp.Net /// public bool IsAuthenticated { get { - return _authenticated; - } - - internal set { - _authenticated = value; + return _context.User != null; } } diff --git a/websocket-sharp/Net/WebSockets/HttpListenerWebSocketContext.cs b/websocket-sharp/Net/WebSockets/HttpListenerWebSocketContext.cs index 23bff44a..f39c3b55 100644 --- a/websocket-sharp/Net/WebSockets/HttpListenerWebSocketContext.cs +++ b/websocket-sharp/Net/WebSockets/HttpListenerWebSocketContext.cs @@ -114,7 +114,7 @@ namespace WebSocketSharp.Net.WebSockets /// public override bool IsAuthenticated { get { - return _context.Request.IsAuthenticated; + return _context.User != null; } } @@ -257,7 +257,7 @@ namespace WebSocketSharp.Net.WebSockets /// Gets the client information (identity, authentication, and security roles). /// /// - /// A that represents the client information. + /// A instance that represents the client information. /// public override IPrincipal User { get { diff --git a/websocket-sharp/Net/WebSockets/WebSocketContext.cs b/websocket-sharp/Net/WebSockets/WebSocketContext.cs index c6424d8b..5f88e709 100644 --- a/websocket-sharp/Net/WebSockets/WebSocketContext.cs +++ b/websocket-sharp/Net/WebSockets/WebSocketContext.cs @@ -182,7 +182,7 @@ namespace WebSocketSharp.Net.WebSockets /// Gets the client information (identity, authentication, and security roles). /// /// - /// A that represents the client information. + /// A instance that represents the client information. /// public abstract IPrincipal User { get; }