Modified HTTP auth for WebSocketServer class
This commit is contained in:
@@ -105,6 +105,12 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
|
||||
#region Internal Properties
|
||||
|
||||
internal string HttpMethod {
|
||||
get {
|
||||
return _request.HttpMethod;
|
||||
}
|
||||
}
|
||||
|
||||
internal Stream Stream {
|
||||
get {
|
||||
return _stream;
|
||||
@@ -159,7 +165,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// </value>
|
||||
public override bool IsAuthenticated {
|
||||
get {
|
||||
return _user != null && _user.Identity.IsAuthenticated;
|
||||
return _user != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,7 +310,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets the client information (identity, authentication, and security roles).
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="IPrincipal"/> that represents the client information.
|
||||
/// A <see cref="IPrincipal"/> instance that represents the client information.
|
||||
/// </value>
|
||||
public override IPrincipal User {
|
||||
get {
|
||||
@@ -359,38 +365,9 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
_request = HttpRequest.Read (_stream, 15000);
|
||||
}
|
||||
|
||||
internal void SetUser (
|
||||
AuthenticationSchemes scheme,
|
||||
string realm,
|
||||
Func<IIdentity, NetworkCredential> credentialsFinder)
|
||||
internal void SetUser (IPrincipal value)
|
||||
{
|
||||
var authRes = _request.AuthenticationResponse;
|
||||
if (authRes == null)
|
||||
return;
|
||||
|
||||
var id = authRes.ToIdentity ();
|
||||
if (id == null)
|
||||
return;
|
||||
|
||||
NetworkCredential cred = null;
|
||||
try {
|
||||
cred = credentialsFinder (id);
|
||||
}
|
||||
catch {
|
||||
}
|
||||
|
||||
if (cred == null)
|
||||
return;
|
||||
|
||||
var valid = scheme == AuthenticationSchemes.Basic
|
||||
? ((HttpBasicIdentity) id).Password == cred.Password
|
||||
: scheme == AuthenticationSchemes.Digest
|
||||
? ((HttpDigestIdentity) id).IsValid (
|
||||
cred.Password, realm, _request.HttpMethod, null)
|
||||
: false;
|
||||
|
||||
if (valid)
|
||||
_user = new GenericPrincipal (id, cred.Roles);
|
||||
_user = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
Reference in New Issue
Block a user