示例#1
0
        /// <summary>
        /// Authentication Request event handler
        /// </summary>
        /// <param name="sender">
        /// The current <see cref="HttpApplication"/> instance
        /// </param>
        /// <param name="e">
        /// Not used
        /// </param>
        private void OnAuthenticateRequest(object sender, EventArgs e)
        {
            IUser user = UserFactory.Instance.CreateUser(this._realm);

            if (user == null)
            {
                throw new AuthConfigurationException(
                          string.Format(CultureInfo.CurrentCulture, Errors.ImplementationMissingAttr, "IUser"));
            }

            var application = (HttpApplication)sender;
            AuthorizationProviderFactory authorizationProviderFactory;

            if (this._userCred.ParseResponse(application, user))
            {
                // there were user credentials in the request
                authorizationProviderFactory = this._authentication.Authenticate(user); // try to authenticate user
                if (authorizationProviderFactory == null)
                {
                    // failed
                    this._userCred.RequestAuthentication(application, this._realm);
                    return;
                }
            }
            else
            {
                if (this._anonUser == null)
                {
                    // anon user not allowed so request authentication (depends on implementation)
                    this._userCred.RequestAuthentication(application, this._realm);
                    return;
                }

                // anon user exists
                authorizationProviderFactory = new AuthorizationProviderFactory(new NoAccessAuthorizationProvider());

                user = this._anonUser;
            }

            IAuthorizationProvider authorizationProvider = authorizationProviderFactory.CreateAuthorizationProvider();

            if (authorizationProvider == null)
            {
                // couldn't create an authorization provider so we fail by default
                throw new AuthConfigurationException(Errors.MissingAuthorizationImplementation);
            }

            application.Context.User =
                new DataflowPrincipal(
                    new GenericIdentity(user.UserName, this._authentication.GetType().Name), authorizationProvider, user);
        }
示例#2
0
        /// <summary>
        /// Authentication Request event handler
        /// </summary>
        /// <param name="sender">
        /// The current <see cref="HttpApplication"/> instance
        /// </param>
        /// <param name="e">
        /// Not used
        /// </param>
        private void OnAuthenticateRequest(object sender, EventArgs e)
        {
            IUser user = UserFactory.Instance.CreateUser(this._realm);
            if (user == null)
            {
                throw new AuthConfigurationException(
                    string.Format(CultureInfo.CurrentCulture, Errors.ImplementationMissingAttr, "IUser"));
            }

            var application = (HttpApplication)sender;
            AuthorizationProviderFactory authorizationProviderFactory;

            if (this._userCred.ParseResponse(application, user))
            {
                // there were user credentials in the request
                authorizationProviderFactory = this._authentication.Authenticate(user); // try to authenticate user
                if (authorizationProviderFactory == null)
                {
                    // failed
                    this._userCred.RequestAuthentication(application, this._realm);
                    return;
                }
            }
            else
            {
                if (this._anonUser == null)
                {
                    // anon user not allowed so request authentication (depends on implementation)
                    this._userCred.RequestAuthentication(application, this._realm);
                    return;
                }

                // anon user exists
                authorizationProviderFactory = new AuthorizationProviderFactory(new NoAccessAuthorizationProvider());

                user = this._anonUser;
            }

            IAuthorizationProvider authorizationProvider = authorizationProviderFactory.CreateAuthorizationProvider();
            if (authorizationProvider == null)
            {
                // couldn't create an authorization provider so we fail by default
                throw new AuthConfigurationException(Errors.MissingAuthorizationImplementation);
            }

            application.Context.User =
                new DataflowPrincipal(
                    new GenericIdentity(user.UserName, this._authentication.GetType().Name), authorizationProvider, user);
        }