From bc48dbf68b8c342eaa05c7b28062c3e030d735a5 Mon Sep 17 00:00:00 2001 From: sta Date: Wed, 20 Apr 2016 14:16:26 +0900 Subject: [PATCH] [Modify] Move it --- websocket-sharp/Net/HttpListener.cs | 32 +------------------- websocket-sharp/Net/HttpListenerContext.cs | 34 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/websocket-sharp/Net/HttpListener.cs b/websocket-sharp/Net/HttpListener.cs index cdcb476c..1966c57f 100644 --- a/websocket-sharp/Net/HttpListener.cs +++ b/websocket-sharp/Net/HttpListener.cs @@ -530,36 +530,6 @@ namespace WebSocketSharp.Net } } - internal bool Authenticate (HttpListenerContext context) - { - var schm = SelectAuthenticationScheme (context); - if (schm == AuthenticationSchemes.Anonymous) - return true; - - if (schm != AuthenticationSchemes.Basic && schm != AuthenticationSchemes.Digest) { - context.Response.Close (HttpStatusCode.Forbidden); - return false; - } - - var realm = Realm; - var req = context.Request; - var user = - HttpUtility.CreateUser ( - req.Headers["Authorization"], schm, realm, req.HttpMethod, UserCredentialsFinder - ); - - if (user == null || !user.Identity.IsAuthenticated) { - context.Response.CloseWithAuthChallenge ( - new AuthenticationChallenge (schm, realm).ToString () - ); - - return false; - } - - context.User = user; - return true; - } - internal HttpListenerAsyncResult BeginGetContext (HttpListenerAsyncResult asyncResult) { lock (_ctxRegistrySync) { @@ -587,7 +557,7 @@ namespace WebSocketSharp.Net if (!_listening) return false; - if (!Authenticate (context)) + if (!context.Authenticate ()) return false; lock (_ctxRegistrySync) { diff --git a/websocket-sharp/Net/HttpListenerContext.cs b/websocket-sharp/Net/HttpListenerContext.cs index b5b86b61..397c2db0 100644 --- a/websocket-sharp/Net/HttpListenerContext.cs +++ b/websocket-sharp/Net/HttpListenerContext.cs @@ -166,6 +166,40 @@ namespace WebSocketSharp.Net #endregion + #region Internal Methods + + internal bool Authenticate () + { + var schm = _listener.SelectAuthenticationScheme (this); + if (schm == AuthenticationSchemes.Anonymous) + return true; + + if (schm != AuthenticationSchemes.Basic && schm != AuthenticationSchemes.Digest) { + _response.Close (HttpStatusCode.Forbidden); + return false; + } + + var realm = _listener.Realm; + var user = + HttpUtility.CreateUser ( + _request.Headers["Authorization"], + schm, + realm, + _request.HttpMethod, + _listener.UserCredentialsFinder + ); + + if (user == null || !user.Identity.IsAuthenticated) { + _response.CloseWithAuthChallenge (new AuthenticationChallenge (schm, realm).ToString ()); + return false; + } + + _user = user; + return true; + } + + #endregion + #region Public Methods ///