@@ -28,12 +28,36 @@ namespace ThoughtWorks.CruiseControl.Core.Publishers
28
28
/// </converters>
29
29
/// </code>
30
30
/// </example>
31
+ /// <para>
32
+ /// Take the following ldap setup :
33
+ /// <code>
34
+ /// domain name : FortKnox
35
+ /// sAMAccountName : JB
36
+ /// givenName : James
37
+ /// sn : Bond
38
+ /// displayName : James Bond
39
+
40
+ /// </code>
41
+ /// Suppose the source control displays the modifying user as 'jb', you need the following in the ldapConverter
42
+ /// <code>
43
+ /// DomainName = FortKnox
44
+ /// LdapQueryField = mail
45
+ /// SourceControlFieldToLdapMapper = SAMAccountName
46
+ /// </code>
47
+ /// Suppose the source control displays the modifying user as 'james bond', you need the following in the ldapConverter
48
+ /// <code>
49
+ /// DomainName = FortKnox
50
+ /// LdapQueryField = mail
51
+ /// SourceControlFieldToLdapMapper = displayName
52
+ /// </code>
53
+ /// </para>
31
54
[ ReflectorType ( "ldapConverter" ) ]
32
55
public class EmailLDAPConverter : IEmailConverter
33
56
{
34
57
private string domainName = string . Empty ;
35
58
private string ldap_Mail = "mail" ;
36
59
private string ldap_QueryField = "MailNickName" ;
60
+ private string sourceControlFieldToLdapMapper = "SAMAccountName" ;
37
61
private string ldap_LogOnUser = string . Empty ;
38
62
private PrivateString ldap_LogOnPassword = string . Empty ;
39
63
@@ -62,6 +86,22 @@ public string LdapQueryField
62
86
set { ldap_QueryField = value ; }
63
87
}
64
88
89
+
90
+
91
+ /// <summary>
92
+ /// The field in LDAP to use as lookup reference for the user name of the source control.
93
+ /// </summary>
94
+ /// <version>1.9</version>
95
+ /// <default>SAMAccountName</default>
96
+ [ ReflectorProperty ( "SourceControlFieldToLdapMapper" , Required = false ) ]
97
+ public string SourceControlFieldToLdapMapper
98
+ {
99
+ get { return sourceControlFieldToLdapMapper ; }
100
+ set { sourceControlFieldToLdapMapper = value ; }
101
+
102
+ }
103
+
104
+
65
105
/// <summary>
66
106
/// Username for logging into the LDAP service.
67
107
/// </summary>
@@ -102,28 +142,28 @@ public EmailLDAPConverter()
102
142
/// <param name="username">The username.</param>
103
143
/// <returns>The email address.</returns>
104
144
public string Convert ( string username )
105
- {
145
+ {
106
146
string ldapPath = @"LDAP://" + domainName ;
107
- string ldapFilter = @"(&(objectClass=user)(SAMAccountName =" + username + "))" ;
147
+ string ldapFilter = @"(&(objectClass=user)(" + sourceControlFieldToLdapMapper + " =" + username + "))" ;
108
148
string [ ] ldapProperties = { ldap_Mail , ldap_QueryField } ;
109
149
110
150
System . DirectoryServices . DirectoryEntry domain ;
111
- if ( ldap_LogOnUser . Length > 0 )
151
+ if ( ldap_LogOnUser . Length > 0 )
112
152
{
113
- domain = new System . DirectoryServices . DirectoryEntry ( ldapPath , ldap_LogOnUser , ldap_LogOnPassword . PrivateValue ) ;
153
+ domain = new System . DirectoryServices . DirectoryEntry ( ldapPath , ldap_LogOnUser , ldap_LogOnPassword . PrivateValue ) ;
114
154
}
115
155
else
116
156
{
117
157
domain = new System . DirectoryServices . DirectoryEntry ( ldapPath ) ;
118
158
}
119
-
159
+
120
160
121
161
System . DirectoryServices . DirectorySearcher searcher = new System . DirectoryServices . DirectorySearcher ( domain ) ;
122
162
System . DirectoryServices . SearchResult result ;
123
163
124
164
searcher . Filter = ldapFilter ;
125
165
searcher . PropertiesToLoad . AddRange ( ldapProperties ) ;
126
-
166
+
127
167
result = searcher . FindOne ( ) ;
128
168
129
169
searcher . Dispose ( ) ;
@@ -135,7 +175,7 @@ public string Convert(string username)
135
175
}
136
176
else
137
177
{
138
- Core . Util . Log . Debug ( string . Format ( System . Globalization . CultureInfo . CurrentCulture , "No email adress found for user {0} in domain {1}" , username , domainName ) ) ;
178
+ Core . Util . Log . Debug ( string . Format ( System . Globalization . CultureInfo . CurrentCulture , "No email adress found for user {0} in domain {1}" , username , domainName ) ) ;
139
179
return null ;
140
180
}
141
181
}
0 commit comments