Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

Commit 7c5283f

Browse files
committed
extra field SourceControlFieldToLdapMapper on EmailLDAPConverter for custom mapping of the username returned by the source control system
1 parent 77410bf commit 7c5283f

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

project/core/publishers/EmailLDAPConverter.cs

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,36 @@ namespace ThoughtWorks.CruiseControl.Core.Publishers
2828
/// </converters>
2929
/// </code>
3030
/// </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+
/// mail : [email protected]
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>
3154
[ReflectorType("ldapConverter")]
3255
public class EmailLDAPConverter : IEmailConverter
3356
{
3457
private string domainName = string.Empty;
3558
private string ldap_Mail = "mail";
3659
private string ldap_QueryField = "MailNickName";
60+
private string sourceControlFieldToLdapMapper = "SAMAccountName";
3761
private string ldap_LogOnUser = string.Empty;
3862
private PrivateString ldap_LogOnPassword = string.Empty;
3963

@@ -62,6 +86,22 @@ public string LdapQueryField
6286
set { ldap_QueryField = value; }
6387
}
6488

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+
65105
/// <summary>
66106
/// Username for logging into the LDAP service.
67107
/// </summary>
@@ -102,28 +142,28 @@ public EmailLDAPConverter()
102142
/// <param name="username">The username.</param>
103143
/// <returns>The email address.</returns>
104144
public string Convert(string username)
105-
{
145+
{
106146
string ldapPath = @"LDAP://" + domainName;
107-
string ldapFilter = @"(&(objectClass=user)(SAMAccountName=" + username + "))";
147+
string ldapFilter = @"(&(objectClass=user)(" + sourceControlFieldToLdapMapper + "=" + username + "))";
108148
string[] ldapProperties = { ldap_Mail, ldap_QueryField };
109149

110150
System.DirectoryServices.DirectoryEntry domain;
111-
if (ldap_LogOnUser.Length > 0 )
151+
if (ldap_LogOnUser.Length > 0)
112152
{
113-
domain = new System.DirectoryServices.DirectoryEntry(ldapPath,ldap_LogOnUser,ldap_LogOnPassword.PrivateValue);
153+
domain = new System.DirectoryServices.DirectoryEntry(ldapPath, ldap_LogOnUser, ldap_LogOnPassword.PrivateValue);
114154
}
115155
else
116156
{
117157
domain = new System.DirectoryServices.DirectoryEntry(ldapPath);
118158
}
119-
159+
120160

121161
System.DirectoryServices.DirectorySearcher searcher = new System.DirectoryServices.DirectorySearcher(domain);
122162
System.DirectoryServices.SearchResult result;
123163

124164
searcher.Filter = ldapFilter;
125165
searcher.PropertiesToLoad.AddRange(ldapProperties);
126-
166+
127167
result = searcher.FindOne();
128168

129169
searcher.Dispose();
@@ -135,7 +175,7 @@ public string Convert(string username)
135175
}
136176
else
137177
{
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));
139179
return null;
140180
}
141181
}

0 commit comments

Comments
 (0)