首先,Domino的LDAP服務配置為不能匿名訪問,不然就沒意義了。
安全性中,internet認證設置為:較多名稱變換,較低安全性。
這樣的話用戶名可以使用Domino個人文檔中的:名+空格+姓、簡稱、Email地址
如果不需要的話也可以不這樣設置。
密碼為:Internet密碼
默認情況下Domino的LDAP屬性沒有uid(簡稱),需要自己添加下。
原理:使用輸入的用戶名密碼執行一個LDAP查詢,如果沒有拋出異常,說明用戶名密碼正確。
1using System.DirectoryServices;
2using System.Configuration;
3using System.Text;
4
5 public class LDAPHelper
6 {
7
8 private string dominoServer;
9 /**//// <summary>
10 /// domino服務器地址
11 /// </summary>
12 public string DominoServer
13 {
14 get { return dominoServer; }
15 set { dominoServer = value; }
16 }
17 private string ldapServer;
18 /**//// <summary>
19 /// ldap服務器地址
20 /// </summary>
21 public string LdapServer
22 {
23 get { return ldapServer; }
24 set { ldapServer = value; }
25 }
26
27 private string userName;
28 /**//// <summary>
29 /// 用戶名
30 /// </summary>
31 public string UserName
32 {
33 get { return userName; }
34 set { userName = value; }
35 }
36
37 private string passWord;
38 /**//// <summary>
39 /// 密碼
40 /// </summary>
41 public string PassWord
42 {
43 get { return passWord; }
44 set { passWord = value; }
45 }
46 /**//// <summary>
47 /// 實例化
48 /// </summary>
49 /// <param name="userName">用戶名</param>
50 /// <param name="passWord">密碼</param>
51 public LDAPHelper(string userName, string passWord)
52 {
53 try
54 {
55 //this.LdapServer = ConfigurationManager.APPSettings["LDAPServer"].ToString();
56
57 //this.DominoServer = ConfigurationManager.APPSettings["DominoServer"].ToString();
58
59 this.LdapServer = "192.176.0.46";
60
61 this.DominoServer= "192.176.0.46"
62
63 this.UserName = userName;
64 this.Password = passWord;
65 }
66 catch
67 {
68 throw;
69 }
70 }
71
72 /**//// <summary>
73 /// 通過domino LDAP服務驗證用戶名密碼是否正確
74 /// </summary>
75 /// <param name="userName">用戶名</param>
76 /// <param name="passWord">密碼</param>
77 /// <returns></returns>
78 public bool VerifyUser()
79 {
80 try
81 {
82 DirectorySearcher searcher = prepareSearcher();
83
84 //執行以下方法時沒拋出異常說明用戶名密碼正確
85 SearchResult rs = searcher.FindOne();
86
87 return true;
88 }
89 catch
90 {
91 return false;
92 }
93 }
94
95 /**//// <summary>
96 /// Prepare DirectorySearcher
97 /// </summary>
98 /// <returns>DirectorySearcher</returns>
99 private DirectorySearcher prepareSearcher()
100 {
101
102 DirectoryEntry root = new DirectoryEntry(this.LdapServer, this.UserName, this.PassWord, AuthenticationTypes.None);
103 DirectorySearcher searcher = new DirectorySearcher(root);
104
105 //LDAP搜索的過濾條件,cn為用戶名,uid為用戶簡稱
106
107 searcher.Filter = "(&(objectClass=dominoPerson)(|(cn=" + this.UserName +
108
109")(uid=" + this.UserName + ")(mail=" + this.UserName + ")))";
110
111
112 //searcher.Filter = "(&(objectClass=dominoPerson)(cn=" + this.UserName +"))";
113 return searcher;
114
115 }
116 }