예제 #1
0
        public async Task BindAsync(Native.Native.LdapAuthType authType, LdapCredential ldapCredential)
        {
            ThrowIfNotInitialized();
            var result = IntPtr.Zero;

            if (authType == Native.Native.LdapAuthType.Simple)
            {
                result = await _native.BindSimpleAsync(_ld, ldapCredential.UserName, ldapCredential.Password);
            }
            else if (authType == Native.Native.LdapAuthType.Anonymous)
            {
                result = await _native.BindSimpleAsync(_ld, null, null);
            }
            else if (authType == Native.Native.LdapAuthType.ExternalAd)
            {
                _native.LdapConnect(_ld);
            }
            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;
        }
예제 #2
0
        public async Task BindAsync(string mechanism = Native.Native.LdapAuthMechanism.Kerberos, string userDn = null,
                                    string password  = null)
        {
            ThrowIfNotInitialized();
            IntPtr result;

            if (Native.Native.LdapAuthMechanism.SIMPLE.Equals(mechanism, StringComparison.OrdinalIgnoreCase))
            {
                result = await _native.BindSimpleAsync(_ld, userDn, password);
            }
            else if (Native.Native.LdapAuthMechanism.Kerberos.Equals(mechanism, StringComparison.OrdinalIgnoreCase))
            {
                result = await _native.BindKerberosAsync(_ld);
            }
            else
            {
                throw new LdapException(
                          $"Not implemented mechanism: {mechanism}. Available: {Native.Native.LdapAuthMechanism.Kerberos} | {Native.Native.LdapAuthMechanism.SIMPLE}. ");
            }

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

            _bound = true;
        }