コード例 #1
0
 public async Task CanBind()
 {
     using (var client = new LdapClient(Hostname))
     {
         await client.SimpleBindAsync("cn=read-only-admin,dc=example,dc=com", "password",
                                      CancellationToken.None);
     }
 }
コード例 #2
0
        public async Task CanReadEntry()
        {
            using (var client = new LdapClient(Hostname))
            {
                var result = await client.SearchAsync("uid=tesla,dc=example,dc=com", SearchScope.BaseObject, null, CancellationToken.None);

                var entry = Assert.Single(result.Entries);
                Assert.Equal("uid=tesla,dc=example,dc=com", entry.ObjectName.ToString());
                Assert.Empty(result.References);
            }
        }
コード例 #3
0
        public void TryConnect()
        {
            using (var client = new LdapClient())
            {
                client.SslOptions  = this._ldap.SslOptions;
                client.UseStartTLS = this._ldap.UseStartTLS;
                client.HostName    = this._ldap.Hostname;
                client.Port        = this._ldap.Port;

                client.Open();
                client.Close();
            }
        }
コード例 #4
0
        public async Task CanSearch(string filter, string dn)
        {
            using (var client = new LdapClient(Hostname))
            {
                var result = await client.SearchAsync("dc=example,dc=com", SearchScope.SingleLevel, filter, CancellationToken.None);

                var entry = Assert.Single(result.Entries);
                Assert.Equal(dn, entry.ObjectName.ToString());
                Assert.Empty(result.References);
                result = await client.SearchAsync("dc=example,dc=com", SearchScope.BaseObject, filter, CancellationToken.None);

                Assert.Empty(result.Entries);
                Assert.Empty(result.References);
            }
        }
コード例 #5
0
        public async Task CanCompare()
        {
            using (var client = new LdapClient(Hostname))
            {
                var result = await client.CompareAsync("ou=chemists,dc=example,dc=com", "cn", "Chemists", CancellationToken.None);

                Assert.True(result);
                result = await client.CompareAsync("ou=chemists,dc=example,dc=com", "cn", "ChemistS", CancellationToken.None);

                Assert.True(result);
                result = await client.CompareAsync("ou=chemists,dc=example,dc=com", "cn", "Foo", CancellationToken.None);

                Assert.False(result);
                var ex = await Assert.ThrowsAsync <LdapException>(() => client.CompareAsync("ou=chemists,dc=example,dc=com", "ad", "void", CancellationToken.None));

                Assert.Equal(ResultCode.UndefinedAttributeType, ex.ResultCode);
            }
        }
コード例 #6
0
        public async Task CanSearchWithAttributes(string filter, string dn, string attributeName, string attribute, string expectedAttributeName = null)
        {
            using (var client = new LdapClient(Hostname))
            {
                var result = await client.SearchAsync("dc=example,dc=com", SearchScope.SingleLevel, filter, new [] { attributeName }, CancellationToken.None);

                var entry = Assert.Single(result.Entries);
                Assert.Equal(dn, entry.ObjectName.ToString());
                Assert.Empty(result.References);
                if (!String.IsNullOrEmpty(attribute))
                {
                    var attr = Assert.Single(entry.Attributes);
                    Assert.Equal(expectedAttributeName ?? attributeName, attr.Type.ToString());
                    var attrValue = Assert.Single(attr.Values);
                    Assert.Equal(attribute, Encoding.UTF8.GetString(attrValue.Span));
                }
                else
                {
                    Assert.Empty(entry.Attributes);
                }
            }
        }
コード例 #7
0
ファイル: StudentLib.cs プロジェクト: debuglevel/StudentsList
        /// <summary>
        /// Initializing the LDAP client and internal stuff
        /// </summary>
        /// <param name="username">user within the AD</param>
        /// <param name="password">the user's password</param>
        /// <param name="ldapServer">the AD</param>
        public Studierende(string username, SecureString password, string ldapServer)
        {
            this.ldapClient = new LdapClient(ldapServer, username, password);

            this.Programs = new List <string>();
        }
コード例 #8
0
 public LdapEventListener(LdapClient ldapClient)
 {
     _ldapClient = ldapClient;
 }