コード例 #1
0
ファイル: LdapManager.cs プロジェクト: DamilolaAdegunwa/abp-2
        public void AddUserToOrganization(string userName, string password, LdapOrganization parentOrganization)
        {
            var dn   = $"CN={userName},{parentOrganization.DistinguishedName}";
            var mail = $"{userName}@{_ldapOptions.DomainName}";

            sbyte[] encodedBytes = SupportClass.ToSByteArray(Encoding.Unicode.GetBytes($"\"{password}\""));

            var attributeSet = new LdapAttributeSet
            {
                new LdapAttribute("instanceType", "4"),
                new LdapAttribute("objectCategory", $"CN=Person,CN=Schema,CN=Configuration,{_ldapOptions.DomainDistinguishedName}"),
                new LdapAttribute("objectClass", new[] { "top", "person", "organizationalPerson", "user" }),
                new LdapAttribute("name", userName),
                new LdapAttribute("cn", userName),
                new LdapAttribute("sAMAccountName", userName),
                new LdapAttribute("userPrincipalName", userName),
                new LdapAttribute("sn", userName),
                new LdapAttribute("displayName", userName),
                new LdapAttribute("unicodePwd", encodedBytes),
                new LdapAttribute("userAccountControl", "512"),
                new LdapAttribute("mail", mail),
            };
            var newEntry = new LdapEntry(dn, attributeSet);

            using (var ldapConnection = GetConnection())
            {
                ldapConnection.Add(newEntry);
            }
        }
コード例 #2
0
        public void AddSubOrganization(string organizationName, LdapOrganization parentOrganization)
        {
            organizationName = Check.NotNullOrWhiteSpace(organizationName, nameof(organizationName));
            var dn = $"OU={organizationName},{parentOrganization.DistinguishedName}";

            var attributeSet = new LdapAttributeSet {
                new LdapAttribute("objectCategory", $"CN=Organizational-Unit,CN=Schema,CN=Configuration,{_ldapOptions.DomainDistinguishedName}"),
                new LdapAttribute("objectClass", new [] { "top", "organizationalUnit" }),
                new LdapAttribute("name", organizationName),
            };

            var newEntry = new LdapEntry(dn, attributeSet);

            using (var ldapConnection = GetConnection()) {
                ldapConnection.Add(newEntry);
            }
        }