コード例 #1
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;
        }
コード例 #2
0
        public void Bind(string mechanism = Native.Native.LdapAuthMechanism.Kerberos, string userDn = null,
                         string password  = null)
        {
            ThrowIfNotInitialized();
            if (Native.Native.LdapAuthMechanism.SIMPLE.Equals(mechanism, StringComparison.OrdinalIgnoreCase))
            {
                _native.ThrowIfError(_ld, _native.BindSimple(_ld, userDn, password), nameof(_native.BindSimple));
            }
            else if (Native.Native.LdapAuthMechanism.Kerberos.Equals(mechanism, StringComparison.OrdinalIgnoreCase))
            {
                _native.ThrowIfError(_ld, _native.BindKerberos(_ld), nameof(_native.BindKerberos));
            }
            else
            {
                throw new LdapException(
                          $"Not implemented mechanism: {mechanism}. Available: {Native.Native.LdapAuthMechanism.Kerberos} | {Native.Native.LdapAuthMechanism.SIMPLE}. ");
            }

            _bound = true;
        }