这里的第一个构造器是一个基本的缺省构造器,能够在无需任何参数的情况下创建对象
www.orchn.com
第二个构造器使我们能够指定连接到给定域的AD上所需要的证书,在需要使用给定的证书连接到任意域名时,这一构造器非常方便
www.orchn.com
扮演
“扮演”这个词的意思是,我们以其他人或用户的身份执行操作
下面的代码被我称为“活动方法”,代码如下所示:
| public DSHelper.DSUser LoadUser(string username) |
| if(impersonateValidUser(this.LoginUsername, this.DomainName, this.loginPassword)) { //在这里插入在指定用户的安全环境下运行的代码 //不要忘记取消扮演 undoImpersonation(); } else { //扮演操作失败了,插入保证失败后系统安全的机制 } |
| public System.Boolean DeleteUser(DSHelper.DSUser dsUser) |
| #region setup impersonation via interop //需要保存详细资料时,为完成扮演需要通过InteropServices从COM中导入 public const int LOGON32_LOGON_INTERACTIVE = 2; public const int LOGON32_PROVIDER_DEFAULT = 0; System.Security.Principal.WindowsImpersonationContext impersonationContext; [DllImport(%26amp;quot;advapi32.dll%26amp;quot;, CharSet=CharSet.Auto)]public static extern int LogonUser(String lpszUserName, String lpszDomain,String lpszPassword,int dwLogonType,int dwLogonProvider, ref IntPtr phToken); [DllImport(%26amp;quot;advapi32.dll%26amp;quot;, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)]public extern static int DuplicateToken(IntPtr hToken, int impersonationLevel, ref IntPtr hNewToken); #endregion |
| public System.Boolean AddUserToGroup(string groupname, DSHelper.DSUser dsUser) |
| public System.Boolean Connect() |
| public System.DirectoryServices.DirectoryEntry SaveUser(DSHelper.DSUser dsUser) |
| public System.Collections.ArrayList GetGroups() |
0
顶一下0
踩一下