AD 用户组类库中增加几个功能

修改/增加的地方:
1、权限机制:摒弃在配置文件中配置域管理员帐号密码的方式,而采用重新用COM+安全身份来执行整个AD操作。
2、用户:修正Lock/UnLock和Enabled/Disabled,Mail-Enabled/Mailbox-Enabled的用法。
3、组:修正创建组时无法指定Group Scope/Group Type的问题,增加对各类型组的创建支持。同时支持更改组Owner,和设置管理Membership list的属性。
其中更新Membership list属性的更改比较有意思。因为在AD中并没有一个属性与之对应,只能通过修改访问规则来设置:
ActiveDirectorySecurity ads = myGroup.ObjectSecurity;
ActiveDirectoryAccessRule accessRule = new ActiveDirectoryAccessRule(
          new NTAccount(Domain, samAccountName),
          ActiveDirectoryRights.WriteProperty,
          AccessControlType.Allow,
          new Guid("bf9679c0-0de6-11d0-a285-00aa003049e2"));
ads.AddAccessRule(accessRule);
myGroup.ObjectSecurity = ads;
myGroup.CommitChanges();

4、Mail相关:增加了对Exchange Server/StoreGroup/MailStore/Mailbox的各类操作(相关见《枚举Exchange Server, StoreGroups, MailStore》)。同时支持对proxyAddresses等属性的修改设置。

 

其中更新proxyAddresseses并设置 Primary proxyAddress也比较有意思,摘出供参考:
       private void UpdateProxyAddresses(DirectoryEntry userEntry, ArrayList emailAddresses)
        {
            PropertyCollection properties = userEntry.Properties;
            PropertyValueCollection proxyAddresses = userEntry.Properties["proxyAddresses"];
            if (proxyAddresses != null)
            {
                for (int i = 0; i < emailAddresses.Count; i++)
                {
                    string emailType = emailTypes[i];
                    string emailAddress = emailAddresses[i].ToString();
                    int schemaIndex = Array.IndexOf(emailTypes, emailType);
                    if (schemaIndex > -1)
                    {
                        // Is it the primary address
                        if (schemaIndex == 0)
                            userEntry.Properties["mail"].Value = emailAddress.ToString();
                        string emailPrefix = emailPrefixes[schemaIndex];
                        bool found = false;
                        for (int j = 0; j < proxyAddresses.Count; j++)
                        {
                            string proxyAddress = proxyAddresses[j].ToString();
                            if (proxyAddress.StartsWith(emailPrefix + ":"))
                            {
                                proxyAddresses[j] = emailPrefix + ":" + emailAddress;
                                found = true;
                            }
                        }
                        if (!found)
                            proxyAddresses.Add(emailPrefix + ":" + emailAddress);
                    }
                    userEntry.Properties["proxyAddresses"].Value = proxyAddresses.Value;
                }
            }
        }
        public void MakePrimaryProxyAddress(DirectoryEntry userEntry, string newMailAddress)
        {
            System.DirectoryServices.PropertyCollection properties = userEntry.Properties;
            PropertyValueCollection proxyAddresses = userEntry.Properties["proxyAddresses"];
            if (proxyAddresses != null)
            {
                bool found = false;
                for (int j = 0; j < proxyAddresses.Count; j++)
                {
                    string proxyadd = proxyAddresses[j].ToString();
                    if (proxyadd.StartsWith("SMTP:"))
                    {
                        found = true;
                        string[] proxyparts = proxyadd.Split(':');
                        proxyAddresses[j] = "smtp:" + proxyparts[1];
                    }
                }
                if (!found)
                {
                    proxyAddresses.Insert(0, "SMTP:" + newMailAddress);
                    userEntry.Properties["proxyAddresses"].Value = proxyAddresses.Value;
                }
            }
        }
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值