コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }