internal void SetUser(AuthenticationSchemes expectedScheme, string realm, Func <IIdentity, NetworkCredential> credentialsFinder) { AuthenticationResponse authenticationResponse = AuthenticationResponse.Parse(this._request.Headers["Authorization"]); if (authenticationResponse == null) { return; } IIdentity identity = authenticationResponse.ToIdentity(); if (identity == null) { return; } NetworkCredential networkCredential = null; try { networkCredential = credentialsFinder(identity); } catch { } if (networkCredential == null) { return; } bool flag = (expectedScheme != AuthenticationSchemes.Basic) ? (expectedScheme == AuthenticationSchemes.Digest && ((HttpDigestIdentity)identity).IsValid(networkCredential.Password, realm, this._request.HttpMethod, null)) : (((HttpBasicIdentity)identity).Password == networkCredential.Password); if (flag) { this._user = new GenericPrincipal(identity, networkCredential.Roles); } }
internal static IPrincipal CreateUser(string response, AuthenticationSchemes scheme, string realm, string method, Func <IIdentity, NetworkCredential> credentialsFinder) { if ((response == null) || (response.Length == 0)) { return(null); } if (credentialsFinder == null) { return(null); } if ((scheme != AuthenticationSchemes.Basic) && (scheme != AuthenticationSchemes.Digest)) { return(null); } if (scheme == AuthenticationSchemes.Digest) { if ((realm == null) || (realm.Length == 0)) { return(null); } if ((method == null) || (method.Length == 0)) { return(null); } } if (!response.StartsWith(scheme.ToString(), StringComparison.OrdinalIgnoreCase)) { return(null); } AuthenticationResponse response2 = AuthenticationResponse.Parse(response); if (response2 == null) { return(null); } IIdentity identity = response2.ToIdentity(); if (identity == null) { return(null); } NetworkCredential credential = null; try { credential = credentialsFinder(identity); } catch { } return((credential != null) ? (((scheme != AuthenticationSchemes.Basic) || (((HttpBasicIdentity)identity).Password == credential.Password)) ? (((scheme != AuthenticationSchemes.Digest) || ((HttpDigestIdentity)identity).IsValid(credential.Password, realm, method, null)) ? new GenericPrincipal(identity, credential.Roles) : null) : null) : null); }
internal static IPrincipal CreateUser( string response, AuthenticationSchemes scheme, string realm, string method, Func <IIdentity, NetworkCredential> credentialsFinder) { if (response == null || !response.StartsWith(scheme.ToString(), StringComparison.OrdinalIgnoreCase)) { return(null); } var res = AuthenticationResponse.Parse(response); if (res == null) { return(null); } var id = res.ToIdentity(); if (id == null) { return(null); } NetworkCredential cred = null; try { cred = credentialsFinder(id); } catch { } if (cred == null) { return(null); } var valid = scheme == AuthenticationSchemes.Basic ? ((HttpBasicIdentity)id).Password == cred.Password : scheme == AuthenticationSchemes.Digest ? ((HttpDigestIdentity)id).IsValid(cred.Password, realm, method, null) : false; return(valid ? new GenericPrincipal(id, cred.Roles) : null); }
internal static IPrincipal CreateUser(string response, AuthenticationSchemes scheme, string realm, string method, Func <IIdentity, NetworkCredential> credentialsFinder) { if (response == null || !response.StartsWith(scheme.ToString(), StringComparison.OrdinalIgnoreCase)) { return(null); } AuthenticationResponse authenticationResponse = AuthenticationResponse.Parse(response); if (authenticationResponse == null) { return(null); } IIdentity identity = authenticationResponse.ToIdentity(); if (identity == null) { return(null); } NetworkCredential networkCredential = null; try { networkCredential = credentialsFinder(identity); } catch { } if (networkCredential == null) { return(null); } int num; switch (scheme) { case AuthenticationSchemes.Basic: num = ((((HttpBasicIdentity)identity).Password == networkCredential.Password) ? 1 : 0); break; case AuthenticationSchemes.Digest: num = (((HttpDigestIdentity)identity).IsValid(networkCredential.Password, realm, method, null) ? 1 : 0); break; default: num = 0; break; } return((num == 0) ? null : new GenericPrincipal(identity, networkCredential.Roles)); }
internal void SetUser( AuthenticationSchemes scheme, string realm, Func <IIdentity, NetworkCredential> credentialsFinder) { var authRes = AuthenticationResponse.Parse(_request.Headers ["Authorization"]); 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); } }
internal static IPrincipal CreateUser( string response, AuthenticationSchemes scheme, string realm, string method, Func <IIdentity, NetworkCredential> credentialsFinder) { if (response == null || response.Length == 0) { return(null); } if (credentialsFinder == null) { return(null); } if (!(scheme == AuthenticationSchemes.Basic || scheme == AuthenticationSchemes.Digest)) { return(null); } if (scheme == AuthenticationSchemes.Digest) { if (realm == null || realm.Length == 0) { return(null); } if (method == null || method.Length == 0) { return(null); } } if (!response.StartsWith(scheme.ToString(), StringComparison.OrdinalIgnoreCase)) { return(null); } var res = AuthenticationResponse.Parse(response); if (res == null) { return(null); } var id = res.ToIdentity(); if (id == null) { return(null); } NetworkCredential cred = null; try { cred = credentialsFinder(id); } catch { } if (cred == null) { return(null); } if (scheme == AuthenticationSchemes.Basic && ((HttpBasicIdentity)id).Password != cred.Password) { return(null); } if (scheme == AuthenticationSchemes.Digest && !((HttpDigestIdentity)id).IsValid(cred.Password, realm, method, null)) { return(null); } return(new GenericPrincipal(id, cred.Roles)); }
internal static IPrincipal CreateUser( string response, AuthenticationSchemes scheme, string realm, string method, Func <IIdentity, NetworkCredential> credentialsFinder ) { if (response == null || response.Length == 0) { return(null); } if (scheme == AuthenticationSchemes.Digest) { if (realm == null || realm.Length == 0) { return(null); } if (method == null || method.Length == 0) { return(null); } } else { if (scheme != AuthenticationSchemes.Basic) { return(null); } } if (credentialsFinder == null) { return(null); } var compType = StringComparison.OrdinalIgnoreCase; if (response.IndexOf(scheme.ToString(), compType) != 0) { return(null); } var res = AuthenticationResponse.Parse(response); if (res == null) { return(null); } var id = res.ToIdentity(); if (id == null) { return(null); } NetworkCredential cred = null; try { cred = credentialsFinder(id); } catch { } if (cred == null) { return(null); } if (scheme == AuthenticationSchemes.Basic) { var basicId = (HttpBasicIdentity)id; return(basicId.Password == cred.Password ? new GenericPrincipal(id, cred.Roles) : null); } var digestId = (HttpDigestIdentity)id; return(digestId.IsValid(cred.Password, realm, method, null) ? new GenericPrincipal(id, cred.Roles) : null); }