[Modify] Move it

This commit is contained in:
sta 2016-04-20 14:16:26 +09:00
parent ff5c62eedb
commit bc48dbf68b
2 changed files with 35 additions and 31 deletions

View File

@ -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) {

View File

@ -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
/// <summary>