首先,Domino的LDAP服务配置为不能匿名访问,不然就没意义了。
安全性中,internet认证设置为:较多名称变换,较低安全性。
这样的话用户名可以使用Domino个人文档中的:名+空格+姓、简称、Email地址
如果不需要的话也可以不这样设置。
密码为:Internet密码
默认情况下Domino的LDAP属性没有uid(简称),需要自己添加下。
原理:使用输入的用户名密码执行一个LDAP查询,如果没有抛出异常,说明用户名密码正确。
1
using System.DirectoryServices;
2
using System.Configuration;
3
using 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
}

2

3

4

5

6



7

8

9


10

11

12

13



14



15



16

17

18


19

20

21

22



23



24



25

26

27

28


29

30

31

32



33



34



35

36

37

38


39

40

41

42



43



44



45

46


47

48

49

50

51

52



53

54



55

56

57

58

59

60

61

62

63

64

65

66

67



68

69

70

71

72


73

74

75

76

77

78

79



80

81



82

83

84

85

86

87

88

89

90



91

92

93

94

95


96

97

98

99

100



101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116
