Esempio n. 1
0
        private void InitializeToken()
        {
            error = String.Empty;
            IntPtr token = CreateUserToken(_username, _password, out error);

            _impersonateTokenRef = new ImpersonateTokenRef(token);

            if (_impersonateTokenRef.Handle == IntPtr.Zero)
            {
                if (error.Length > 0)
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Invalid_credentials_2, error),
                              ElementInformation.Properties["userName"].Source,
                              ElementInformation.Properties["userName"].LineNumber);
                }
                else
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Invalid_credentials),
                              ElementInformation.Properties["userName"].Source,
                              ElementInformation.Properties["userName"].LineNumber);
                }
            }
        }
Esempio n. 2
0
        private void InitializeToken()
        {
            this.error = string.Empty;
            IntPtr token = CreateUserToken(this._username, this._password, out this.error);

            this._impersonateTokenRef = new ImpersonateTokenRef(token);
            if (this._impersonateTokenRef.Handle == IntPtr.Zero)
            {
                if (this.error.Length > 0)
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_credentials_2", new object[] { this.error }), base.ElementInformation.Properties["userName"].Source, base.ElementInformation.Properties["userName"].LineNumber);
                }
                throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_credentials"), base.ElementInformation.Properties["userName"].Source, base.ElementInformation.Properties["userName"].LineNumber);
            }
        }
Esempio n. 3
0
        protected override void Reset(ConfigurationElement parentElement)
        {
            base.Reset(parentElement);
            IdentitySection section = parentElement as IdentitySection;

            if (section != null)
            {
                this._impersonateTokenRef = section._impersonateTokenRef;
                if (this.Impersonate)
                {
                    this.UserName             = null;
                    this.Password             = null;
                    this._impersonateTokenRef = new ImpersonateTokenRef(IntPtr.Zero);
                }
                this.impersonateCached     = false;
                this._credentialsValidated = false;
            }
        }
Esempio n. 4
0
        protected override void Reset(ConfigurationElement parentElement)
        {
            base.Reset(parentElement);
            IdentitySection parent = parentElement as IdentitySection;

            if (parent != null)
            {
                _impersonateTokenRef = parent._impersonateTokenRef;
                // No partial overrides
                if (Impersonate)
                {
                    UserName             = null;
                    Password             = null;
                    _impersonateTokenRef = new ImpersonateTokenRef(IntPtr.Zero);
                }
                impersonateCached     = false; // We don't want to cache the parent's value!
                _credentialsValidated = false;
            }
        }
        private void InitializeToken() {
            error = String.Empty;
            IntPtr token = CreateUserToken(_username, _password, out error);

            _impersonateTokenRef = new ImpersonateTokenRef(token);

            if (_impersonateTokenRef.Handle == IntPtr.Zero) {
                if (error.Length > 0) {
                    throw new ConfigurationErrorsException(
                        SR.GetString(SR.Invalid_credentials_2, error), 
                        ElementInformation.Properties["userName"].Source, 
                        ElementInformation.Properties["userName"].LineNumber);
                }
                else {
                    throw new ConfigurationErrorsException(
                        SR.GetString(SR.Invalid_credentials), 
                        ElementInformation.Properties["userName"].Source, 
                        ElementInformation.Properties["userName"].LineNumber);
                }
            }
        }
 protected override void Reset(ConfigurationElement parentElement) {
     base.Reset(parentElement);
     IdentitySection parent = parentElement as IdentitySection;
     if (parent != null) {
         _impersonateTokenRef = parent._impersonateTokenRef;
         // No partial overrides
         if (Impersonate) {
             UserName = null;
             Password = null;
             _impersonateTokenRef = new ImpersonateTokenRef(IntPtr.Zero);
         }
         impersonateCached = false; // We don't want to cache the parent's value!
         _credentialsValidated = false;
     }
 }
        internal IdentityConfig(IdentityConfig parent, bool enable, String username, String password, XmlNode section)
        {
            if (parent != null)
            {
                _enableImpersonation = parent.EnableImpersonation;
                _username            = parent.UserName;
                _password            = parent.Password;
                _impersonateTokenRef = parent._impersonateTokenRef;
            }

            // no partial overrides
            if (enable)
            {
                _username            = null;
                _password            = null;
                _impersonateTokenRef = new ImpersonateTokenRef(IntPtr.Zero);
            }

            _enableImpersonation = enable;
            _username            = username;
            _password            = password;

            if (_username != null && _enableImpersonation)
            {
                if (_password == null)
                {
                    _password = String.Empty;
                }

                StringBuilder szError = new StringBuilder(256);

                HttpContext context = HttpContext.Current;
                IntPtr      token   = IntPtr.Zero;
                if (context.WorkerRequest is System.Web.Hosting.ISAPIWorkerRequest)
                {
                    byte [] bOut = new byte[IntPtr.Size];
                    byte [] bIn1 = System.Text.Encoding.Unicode.GetBytes(_username + "\t" + _password);
                    byte [] bIn  = new byte[bIn1.Length + 2];
                    Buffer.BlockCopy(bIn1, 0, bIn, 0, bIn1.Length);
                    if (context.CallISAPI(UnsafeNativeMethods.CallISAPIFunc.GenerateToken, bIn, bOut) == 1)
                    {
                        Int64 iToken = 0;
                        for (int iter = 0; iter < IntPtr.Size; iter++)
                        {
                            iToken = iToken * 256 + bOut[iter];
                        }
                        token = (IntPtr)iToken;
                    }
                }

                if (token == IntPtr.Zero)
                {
                    token = UnsafeNativeMethods.CreateUserToken(_username, _password, 1, szError, 256);
                }

                _impersonateTokenRef = new ImpersonateTokenRef(token);

                if (_impersonateTokenRef.Handle == IntPtr.Zero)
                {
                    String strError = szError.ToString();
                    if (strError.Length > 0)
                    {
                        throw new ConfigurationException(
                                  HttpRuntime.FormatResourceString(SR.Invalid_credentials_2, strError),
                                  section);
                    }
                    else
                    {
                        throw new ConfigurationException(
                                  HttpRuntime.FormatResourceString(SR.Invalid_credentials),
                                  section);
                    }
                }
            }
            else if (_password != null && _username == null && _password.Length > 0 && _enableImpersonation)
            {
                throw new ConfigurationException(
                          HttpRuntime.FormatResourceString(SR.Invalid_credentials),
                          section);
            }
        }
 protected override void Reset(ConfigurationElement parentElement)
 {
     base.Reset(parentElement);
     IdentitySection section = parentElement as IdentitySection;
     if (section != null)
     {
         this._impersonateTokenRef = section._impersonateTokenRef;
         if (this.Impersonate)
         {
             this.UserName = null;
             this.Password = null;
             this._impersonateTokenRef = new ImpersonateTokenRef(IntPtr.Zero);
         }
         this.impersonateCached = false;
         this._credentialsValidated = false;
     }
 }
 private void InitializeToken()
 {
     this.error = string.Empty;
     IntPtr token = CreateUserToken(this._username, this._password, out this.error);
     this._impersonateTokenRef = new ImpersonateTokenRef(token);
     if (this._impersonateTokenRef.Handle == IntPtr.Zero)
     {
         if (this.error.Length > 0)
         {
             throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_credentials_2", new object[] { this.error }), base.ElementInformation.Properties["userName"].Source, base.ElementInformation.Properties["userName"].LineNumber);
         }
         throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_credentials"), base.ElementInformation.Properties["userName"].Source, base.ElementInformation.Properties["userName"].LineNumber);
     }
 }