Exemple #1
0
        public async Task BindAsync(Native.Native.LdapAuthType authType, LdapCredential ldapCredential)
        {
            ThrowIfNotInitialized();
            IntPtr result;

            if (authType == Native.Native.LdapAuthType.Simple)
            {
                result = await _native.BindSimpleAsync(_ld, ldapCredential.UserName, ldapCredential.Password);
            }
            else if (authType != Native.Native.LdapAuthType.Unknown)
            {
                result = await _native.BindSaslAsync(_ld, authType, ldapCredential);
            }
            else
            {
                throw new LdapException(
                          $"Not implemented mechanism: {authType.ToString()}. Available: {Native.Native.LdapAuthType.Simple.ToString()} | {Native.Native.LdapAuthType.GssApi}. ");
            }

            if (result != IntPtr.Zero)
            {
                ThrowIfParseResultError(result);
            }

            _bound = true;
        }
Exemple #2
0
        public void Bind(Native.Native.LdapAuthType authType, LdapCredential credential)
        {
            ThrowIfNotInitialized();
            if (authType == Native.Native.LdapAuthType.Simple)
            {
                _native.ThrowIfError(_ld, _native.BindSimple(_ld, credential.UserName, credential.Password),
                                     nameof(_native.BindSimple));
            }
            else if (authType == Native.Native.LdapAuthType.Anonymous)
            {
                _native.BindSimple(_ld, null, null);
            }
            else if (authType == Native.Native.LdapAuthType.ExternalAd)
            {
                _native.LdapConnect(_ld);
            }
            else if (authType != Native.Native.LdapAuthType.Unknown)
            {
                _native.ThrowIfError(_ld, _native.BindSasl(_ld, authType, credential), nameof(_native.BindSasl));
            }
            else
            {
                throw new LdapException(
                          $"Not implemented mechanism: {authType.ToString()}. Available: {Native.Native.LdapAuthType.Simple.ToString()} | {Native.Native.LdapAuthType.GssApi}. ");
            }

            _bound = true;
        }