Beispiel #1
0
        public PrincipalContext(
            ContextType contextType, string name, string container, ContextOptions options, string userName, string password)
        {
            GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalContext", "Entering ctor");

            if ((userName == null && password != null) ||
                (userName != null && password == null))
                throw new ArgumentException(SR.ContextBadUserPwdCombo);

            if ((options & ~(ContextOptions.Signing | ContextOptions.Negotiate | ContextOptions.Sealing | ContextOptions.SecureSocketLayer | ContextOptions.SimpleBind | ContextOptions.ServerBind)) != 0)
                throw new InvalidEnumArgumentException(nameof(options), (int)options, typeof(ContextOptions));

            if (contextType == ContextType.Machine && ((options & ~ContextOptions.Negotiate) != 0))
            {
                throw new ArgumentException(SR.InvalidContextOptionsForMachine);
            }

            if ((contextType == ContextType.Domain || contextType == ContextType.ApplicationDirectory) &&
                (((options & (ContextOptions.Negotiate | ContextOptions.SimpleBind)) == 0) ||
                (((options & (ContextOptions.Negotiate | ContextOptions.SimpleBind)) == ((ContextOptions.Negotiate | ContextOptions.SimpleBind))))))
            {
                throw new ArgumentException(SR.InvalidContextOptionsForAD);
            }

            if ((contextType != ContextType.Machine) &&
                (contextType != ContextType.Domain) &&
                (contextType != ContextType.ApplicationDirectory)
            #if TESTHOOK
                && (contextType != ContextType.Test)
            #endif
                )
            {
                throw new InvalidEnumArgumentException(nameof(contextType), (int)contextType, typeof(ContextType));
            }

            if ((contextType == ContextType.Machine) && (container != null))
                throw new ArgumentException(SR.ContextNoContainerForMachineCtx);

            if ((contextType == ContextType.ApplicationDirectory) && ((string.IsNullOrEmpty(container)) || (string.IsNullOrEmpty(name))))
                throw new ArgumentException(SR.ContextNoContainerForApplicationDirectoryCtx);

            _contextType = contextType;
            _name = name;
            _container = container;
            _options = options;

            _username = userName;
            _password = password;

            DoServerVerifyAndPropRetrieval();

            _credValidate = new CredentialValidator(contextType, name, _serverProperties);
        }
Beispiel #2
0
        public PrincipalContext(
                    ContextType contextType, string name, string container, ContextOptions options, string userName, string password)
        {
            GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalContext", "Entering ctor");

            if ((userName == null && password != null) ||
                (userName != null && password == null))
                throw new ArgumentException(StringResources.ContextBadUserPwdCombo);

            if ((options & ~(ContextOptions.Signing | ContextOptions.Negotiate | ContextOptions.Sealing | ContextOptions.SecureSocketLayer | ContextOptions.SimpleBind | ContextOptions.ServerBind)) != 0)
                throw new InvalidEnumArgumentException("options", (int)options, typeof(ContextOptions));

            if (contextType == ContextType.Machine && ((options & ~ContextOptions.Negotiate) != 0))
            {
                throw new ArgumentException(StringResources.InvalidContextOptionsForMachine);
            }

            if ((contextType == ContextType.Domain || contextType == ContextType.ApplicationDirectory) &&
                (((options & (ContextOptions.Negotiate | ContextOptions.SimpleBind)) == 0) ||
                (((options & (ContextOptions.Negotiate | ContextOptions.SimpleBind)) == ((ContextOptions.Negotiate | ContextOptions.SimpleBind))))))
            {
                throw new ArgumentException(StringResources.InvalidContextOptionsForAD);
            }

            if ((contextType != ContextType.Machine) &&
                (contextType != ContextType.Domain) &&
                (contextType != ContextType.ApplicationDirectory)
#if TESTHOOK                
                && (contextType != ContextType.Test)
#endif
                )
            {
                throw new InvalidEnumArgumentException("contextType", (int)contextType, typeof(ContextType));
            }

            if ((contextType == ContextType.Machine) && (container != null))
                throw new ArgumentException(StringResources.ContextNoContainerForMachineCtx);

            if ((contextType == ContextType.ApplicationDirectory) && ((String.IsNullOrEmpty(container)) || (String.IsNullOrEmpty(name))))
                throw new ArgumentException(StringResources.ContextNoContainerForApplicationDirectoryCtx);

            _contextType = contextType;
            _name = name;
            _container = container;
            _options = options;

            _username = userName;
            _password = password;

            DoServerVerifyAndPropRetrieval();

            _credValidate = new CredentialValidator(contextType, name, _serverProperties);
        }
Beispiel #3
0
		public PrincipalContext(ContextType contextType, string name, string container, ContextOptions options, string userName, string password)
		{
			this.initializationLock = new object();
			if ((userName != null || password == null) && (userName == null || password != null))
			{
				if ((options & -64) == 0)
				{
					if (contextType != ContextType.Machine || (options & (ContextOptions.SimpleBind | ContextOptions.SecureSocketLayer | ContextOptions.Signing | ContextOptions.Sealing | ContextOptions.ServerBind)) == 0)
					{
						if ((contextType == ContextType.Domain || contextType == ContextType.ApplicationDirectory) && ((options & (ContextOptions.Negotiate | ContextOptions.SimpleBind)) == 0 || (options & (ContextOptions.Negotiate | ContextOptions.SimpleBind)) == (ContextOptions.Negotiate | ContextOptions.SimpleBind)))
						{
							throw new ArgumentException(StringResources.InvalidContextOptionsForAD);
						}
						else
						{
							if (contextType == ContextType.Machine || contextType == ContextType.Domain || contextType == ContextType.ApplicationDirectory)
							{
								if (contextType != ContextType.Machine || container == null)
								{
									if (contextType != ContextType.ApplicationDirectory || !string.IsNullOrEmpty(container) && !string.IsNullOrEmpty(name))
									{
										this.contextType = contextType;
										this.name = name;
										this.container = container;
										this.options = options;
										this.username = userName;
										this.password = password;
										this.DoServerVerifyAndPropRetrieval();
										this.credValidate = new CredentialValidator(contextType, name, this.serverProperties);
										return;
									}
									else
									{
										throw new ArgumentException(StringResources.ContextNoContainerForApplicationDirectoryCtx);
									}
								}
								else
								{
									throw new ArgumentException(StringResources.ContextNoContainerForMachineCtx);
								}
							}
							else
							{
								throw new InvalidEnumArgumentException("contextType", contextType, typeof(ContextType));
							}
						}
					}
					else
					{
						throw new ArgumentException(StringResources.InvalidContextOptionsForMachine);
					}
				}
				else
				{
					throw new InvalidEnumArgumentException("options", options, typeof(ContextOptions));
				}
			}
			else
			{
				throw new ArgumentException(StringResources.ContextBadUserPwdCombo);
			}
		}
Beispiel #4
0
 public PrincipalContext(ContextType contextType, string name, string container, ContextOptions options, string userName, string password)
 {
     this.initializationLock = new object();
     if ((userName != null || password == null) && (userName == null || password != null))
     {
         if ((options & -64) == 0)
         {
             if (contextType != ContextType.Machine || (options & (ContextOptions.SimpleBind | ContextOptions.SecureSocketLayer | ContextOptions.Signing | ContextOptions.Sealing | ContextOptions.ServerBind)) == 0)
             {
                 if ((contextType == ContextType.Domain || contextType == ContextType.ApplicationDirectory) && ((options & (ContextOptions.Negotiate | ContextOptions.SimpleBind)) == 0 || (options & (ContextOptions.Negotiate | ContextOptions.SimpleBind)) == (ContextOptions.Negotiate | ContextOptions.SimpleBind)))
                 {
                     throw new ArgumentException(StringResources.InvalidContextOptionsForAD);
                 }
                 else
                 {
                     if (contextType == ContextType.Machine || contextType == ContextType.Domain || contextType == ContextType.ApplicationDirectory)
                     {
                         if (contextType != ContextType.Machine || container == null)
                         {
                             if (contextType != ContextType.ApplicationDirectory || !string.IsNullOrEmpty(container) && !string.IsNullOrEmpty(name))
                             {
                                 this.contextType = contextType;
                                 this.name        = name;
                                 this.container   = container;
                                 this.options     = options;
                                 this.username    = userName;
                                 this.password    = password;
                                 this.DoServerVerifyAndPropRetrieval();
                                 this.credValidate = new CredentialValidator(contextType, name, this.serverProperties);
                                 return;
                             }
                             else
                             {
                                 throw new ArgumentException(StringResources.ContextNoContainerForApplicationDirectoryCtx);
                             }
                         }
                         else
                         {
                             throw new ArgumentException(StringResources.ContextNoContainerForMachineCtx);
                         }
                     }
                     else
                     {
                         throw new InvalidEnumArgumentException("contextType", contextType, typeof(ContextType));
                     }
                 }
             }
             else
             {
                 throw new ArgumentException(StringResources.InvalidContextOptionsForMachine);
             }
         }
         else
         {
             throw new InvalidEnumArgumentException("options", options, typeof(ContextOptions));
         }
     }
     else
     {
         throw new ArgumentException(StringResources.ContextBadUserPwdCombo);
     }
 }
        private bool BindLdap(NetworkCredential creds, ContextOptions contextOptions)
        {
            LdapConnection item;
            int            lDAPSSLPORT;
            bool           flag;
            int            num;
            bool           flag1 = (ContextOptions.SecureSocketLayer & contextOptions) > 0;

            if (this.contextType != ContextType.ApplicationDirectory)
            {
                CredentialValidator ldapDirectoryIdentifier = this;
                string str = this.serverName;
                if (flag1)
                {
                    lDAPSSLPORT = LdapConstants.LDAP_SSL_PORT;
                }
                else
                {
                    lDAPSSLPORT = LdapConstants.LDAP_PORT;
                }
                ldapDirectoryIdentifier.directoryIdent = new LdapDirectoryIdentifier(str, lDAPSSLPORT);
            }
            else
            {
                CredentialValidator credentialValidator = this;
                string str1 = this.serverProperties.dnsHostName;
                if (flag1)
                {
                    num = this.serverProperties.portSSL;
                }
                else
                {
                    num = this.serverProperties.portLDAP;
                }
                credentialValidator.directoryIdent = new LdapDirectoryIdentifier(str1, num);
            }
            if (!flag1)
            {
                flag = false;
            }
            else
            {
                flag = this.fastConcurrentSupported;
            }
            bool flag2 = flag;
            int  num1  = Convert.ToInt32(flag2) * 2 + Convert.ToInt32(flag1);

            if (this.connCache.Contains(num1))
            {
                item = (LdapConnection)this.connCache[(object)num1];
            }
            else
            {
                lock (this.cacheLock)
                {
                    if (this.connCache.Contains(num1))
                    {
                        item = (LdapConnection)this.connCache[(object)num1];
                    }
                    else
                    {
                        item = new LdapConnection(this.directoryIdent);
                        item.SessionOptions.SecureSocketLayer = flag1;
                        if (flag2)
                        {
                            try
                            {
                                item.SessionOptions.FastConcurrentBind();
                            }
                            catch (PlatformNotSupportedException platformNotSupportedException)
                            {
                                item.Dispose();
                                item = null;
                                this.fastConcurrentSupported = false;
                                num1 = Convert.ToInt32(flag1);
                                item = new LdapConnection(this.directoryIdent);
                                item.SessionOptions.SecureSocketLayer = flag1;
                            }
                        }
                        this.connCache.Add(num1, item);
                    }
                }
            }
            if (!flag2 || !this.fastConcurrentSupported)
            {
                lock (this.cacheLock)
                {
                    this.lockedLdapBind(item, creds, contextOptions);
                }
            }
            else
            {
                this.lockedLdapBind(item, creds, contextOptions);
            }
            return(true);
        }