Exemplo n.º 1
0
        public LdapConnection(ILdapConnectionSettings settings)
        {
            this._ldap = new LdapUserLookup();

            this._ldap.Hostname = settings.LdapServer;
            this._ldap.Port     = settings.LdapPort;

            this._ldap.LookupDN       = settings.LookupDN;
            this._ldap.LookupPassword = settings.LookupPassword;

            this._ldap.UserSearchBase = settings.UserBaseDN;
            this._ldap.UserFilter     = settings.UserFilter;
            this._ldap.UserNameField  = settings.UserNameField;

            this._ldap.StripGroupBaseDN = true;

            this._ldap.GroupSearchBase  = settings.GroupBaseDN;
            this._ldap.GroupFilter      = settings.GroupFilter;
            this._ldap.GroupNameField   = settings.GroupNameField;
            this._ldap.GroupMemberField = settings.GroupMemberField;

            if (!string.IsNullOrEmpty(settings.LdapCertificate))
            {
                this._ldap.SslOptions.Enabled             = true;
                this._ldap.SslOptions.CertificateFileName = settings.LdapCertificate;
            }

            this._userGroupName = settings.UserGroup;
            this._rootGroupName = settings.RootGroup;
        }
        public Directory(ILdapConnectionFactory ldapConnectionFactory, ILdapConnectionSettings ldapConnectionSettings, IDirectorySettings directorySettings, IDistinguishedNameParser distinguishedNameParser)
        {
            if (ldapConnectionFactory == null)
            {
                throw new ArgumentNullException("ldapConnectionFactory");
            }

            if (ldapConnectionSettings == null)
            {
                throw new ArgumentNullException("ldapConnectionSettings");
            }

            if (directorySettings == null)
            {
                throw new ArgumentNullException("directorySettings");
            }

            if (distinguishedNameParser == null)
            {
                throw new ArgumentNullException("distinguishedNameParser");
            }

            this._directorySettings       = directorySettings;
            this._distinguishedNameParser = distinguishedNameParser;
            this._ldapConnectionFactory   = ldapConnectionFactory;
            this._ldapConnectionSettings  = ldapConnectionSettings;
        }
        public virtual bool TryParse(string connectionString, out ILdapConnectionSettings ldapConnectionSettings)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException("connectionString");
            }

            try
            {
                ldapConnectionSettings = this.Parse(connectionString);
                return(true);
            }
            catch
            {
                ldapConnectionSettings = null;
                return(false);
            }
        }
        public virtual LdapConnection Create(ILdapConnectionSettings ldapConnectionSettings)
        {
            if (ldapConnectionSettings == null)
            {
                throw new ArgumentNullException("ldapConnectionSettings");
            }

            if (string.IsNullOrEmpty(ldapConnectionSettings.Host))
            {
                throw new ArgumentException("The host can not be null or empty.", "ldapConnectionSettings");
            }

            var ldapConnection = new LdapConnection(this.CreateLdapDirectoryIdentifier(ldapConnectionSettings.Host, ldapConnectionSettings.Port));

            if (ldapConnectionSettings.AuthenticationType != null)
            {
                ldapConnection.AuthType = ldapConnectionSettings.AuthenticationType.Value;
            }

            if (ldapConnectionSettings.UserName != null)
            {
                ldapConnection.Credential = new NetworkCredential(ldapConnectionSettings.UserName, ldapConnectionSettings.Password);
            }

            if (ldapConnectionSettings.SecureSocketLayer != null)
            {
                ldapConnection.SessionOptions.SecureSocketLayer = ldapConnectionSettings.SecureSocketLayer.Value;
            }

            if (ldapConnectionSettings.Timeout != null)
            {
                ldapConnection.Timeout = ldapConnectionSettings.Timeout.Value;
            }

            ldapConnection.SessionOptions.ProtocolVersion = _defaultProtocolVersion;

            return(ldapConnection);
        }
 public Directory(ILdapConnectionFactory ldapConnectionFactory, ILdapConnectionSettings ldapConnectionSettings, IDirectorySettings directorySettings, IDistinguishedNameParser distinguishedNameParser) : base(ldapConnectionFactory, ldapConnectionSettings, directorySettings, distinguishedNameParser)
 {
 }