Skip to content

Commit c159497

Browse files
authored
Merge pull request #1 from SynapseProject/develop
Merge develop Branch with Master
2 parents 4474878 + cda8013 commit c159497

8 files changed

Lines changed: 344 additions & 66 deletions

File tree

Zephyr.Directory.Aws/Ldap.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ public static LdapResponse ProcessRequest(LdapRequest request, ILambdaContext ct
4242
{
4343
LdapUtils.ApplyDefaulsAndValidate(request);
4444
string searchFilter = LdapUtils.GetSearchString(request);
45-
if (request.ObjectType != null && request.Union != null)
46-
throw new FormatException("Warning: Myriad currently does not support this type of call: Union with objectType");
45+
// if (request.ObjectType != null && request.Union != null)
46+
// throw new FormatException("Warning: Myriad currently does not support this type of call: Union with objectType");
4747
LdapServer ldap = new LdapServer(request.Config);
4848
ldap.Bind(request.Config);
49-
response = ldap.Search(request.SearchBase, searchFilter, request.Attributes, request.SearchScope, request.MaxResults, request.NextToken, request.Union);
49+
if(request.Config.TokenType == "Server" || request.Config.TokenType == "Client"){
50+
response = ldap.Search(request, request.SearchBase, searchFilter, request.Attributes, request.SearchScope, request.MaxResults, request.NextToken, request.Union);
51+
}
52+
else{
53+
throw new FormatException("Warning: TokenType must be set to Server or Client");
54+
}
5055
ldap.Disconnect();
5156
}
5257
catch (Exception e)

Zephyr.Directory.Aws/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
1818
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
1919

20-
[assembly: AssemblyVersion("1.1.23346.0")]
21-
[assembly: AssemblyFileVersion("1.1.23346.0")]
20+
[assembly: AssemblyVersion("1.1.24059.0")]
21+
[assembly: AssemblyFileVersion("1.1.24059.0")]
2222

2323
// The following attributes are used to specify the signing key for the assembly,
2424
// if desired. See the Mono documentation for more information about signing.

Zephyr.Directory.Ldap/Classes/LdapConfig.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public class LdapConfig
2929
{
3030
[JsonProperty(PropertyName = "server", NullValueHandling = NullValueHandling.Ignore)]
3131
public string Server { get; set; }
32+
33+
[JsonProperty(PropertyName = "TokenType", NullValueHandling = NullValueHandling.Ignore)]
34+
public string TokenType { get; set; }
3235

3336
[JsonProperty(PropertyName = "port", NullValueHandling = NullValueHandling.Ignore)]
3437
public int? Port { get; set; }

Zephyr.Directory.Ldap/Classes/LdapRequest.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public enum SearchScopeType
4040
Base = LdapConnection.ScopeBase // Search only the base object
4141
}
4242

43+
public class UnionType
44+
{
45+
[JsonProperty(PropertyName = "searchValue", NullValueHandling = NullValueHandling.Ignore)]
46+
public string SearchValue { get; set; }
47+
48+
[JsonProperty(PropertyName = "searchBase", NullValueHandling = NullValueHandling.Ignore)]
49+
public string SearchBase { get; set; }
50+
}
4351
public class LdapRequest
4452
{
4553
[JsonConverter(typeof(StringEnumConverter))]
@@ -68,8 +76,8 @@ public class LdapRequest
6876
[JsonProperty(PropertyName = "wildcardSearch", NullValueHandling = NullValueHandling.Ignore)]
6977
public bool? WildcardSearch { get; set; }
7078

71-
[JsonProperty(PropertyName = "Union", NullValueHandling = NullValueHandling.Ignore)]
72-
public List<Dictionary<string, string>> Union { get; set; }
79+
[JsonProperty(PropertyName = "union", NullValueHandling = NullValueHandling.Ignore)]
80+
public List<UnionType> Union { get; set; }
7381

7482
[JsonProperty(PropertyName = "attributes", NullValueHandling = NullValueHandling.Ignore)]
7583
public List<string> Attributes { get; set; } // null = ALL, empty list = NONE

Zephyr.Directory.Ldap/LdapServer.cs

Lines changed: 279 additions & 34 deletions
Large diffs are not rendered by default.

Zephyr.Directory.Ldap/Utilities/LdapUtils.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ private static LdapConfig SetConfigValues(LdapConfig target, LdapConfig source)
218218

219219
if (target.IgnoreWarnings == null)
220220
target.IgnoreWarnings = source.IgnoreWarnings;
221+
222+
if (target.TokenType == null)
223+
target.TokenType = source.TokenType;
221224

222225
if (target.AttributeTypes == null)
223226
target.AttributeTypes = new Dictionary<string, LdapAttributeTypes>(StringComparer.OrdinalIgnoreCase);
@@ -275,15 +278,17 @@ public static LdapCrypto ApplyDefaulsAndValidate(LdapCrypto crypto)
275278
return crypto;
276279
}
277280

278-
public static string GetSearchString(LdapRequest request)
281+
public static string GetSearchString(LdapRequest request, string searchValue = null, string SearchBase = null, bool flag = false)
279282
{
280283
string searchFilter = null;
281284

282285
if (request.ObjectType == null)
283286
searchFilter = request.SearchValue;
287+
else if (request.ObjectType == null && flag == true)
288+
searchFilter = searchValue;
284289
else
285290
{
286-
string id = GetIdentitySearchString(request);
291+
string id = GetIdentitySearchString(request, searchValue, SearchBase, flag);
287292

288293
if (request.ObjectType == ObjectType.Ou)
289294
searchFilter = $"(&(objectCategory=OrganizationalUnit){id})";
@@ -302,10 +307,12 @@ public static string GetSearchString(LdapRequest request)
302307
return searchFilter;
303308
}
304309

305-
public static string GetIdentitySearchString(LdapRequest request)
310+
public static string GetIdentitySearchString(LdapRequest request, string searchVal = null, string SearchBase = null, bool flag = false)
306311
{
307312
string identity = null;
308313
string searchValue = request.SearchValue;
314+
if(flag == true)
315+
searchValue = searchVal;
309316
Guid g = Guid.Empty;
310317
string dnRegexString = @"^\s*?(cn\s*=|ou\s*=|dc\s*=)";
311318

@@ -372,15 +379,11 @@ public static bool ContainsKnownDomain(string value)
372379
return rc;
373380
}
374381

375-
// public static void CheckforError(LdapRequest request){
376-
// Regex test = new(@"\([^)]*\)");
377-
// for (int i = 0; i < request.Union.Count; i++){
378-
// var index = request.Union.ElementAt(i);
379-
// bool result = test.IsMatch(index["searchValue"]);
380-
// if(!result){
381-
// throw new Exception(String.Format("Error: Search Value in index: {0} is not properly formatted", i));
382-
// }
383-
// }
384-
// }
382+
public static string CheckforError(LdapRequest request, string searchValue, string SearchBase){
383+
if(Regex.IsMatch(searchValue, @"\([^)]*\)") == false){
384+
searchValue = LdapUtils.GetSearchString(request, searchValue, SearchBase, true);
385+
}
386+
return searchValue;
387+
}
385388
}
386389
}

Zephyr.Directory.Test/Program.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,25 @@ static void Main(string[] args)
4242
LdapUtils.ApplyDefaulsAndValidate(request);
4343
string searchFilter = LdapUtils.GetSearchString(request);
4444
// LdapUtils.CheckforError(request);
45-
if (request.ObjectType != null && request.Union != null)
46-
throw new FormatException("Warning: Myriad currently does not support this type of call: Union with objectType");
45+
// if (request.ObjectType != null && request.Union != null)
46+
// throw new FormatException("Warning: Myriad currently does not support this type of call: Union with objectType");
4747

4848
LdapServer ldap = new LdapServer(request.Config);
4949
ldap.Bind(request.Config);
50-
51-
response = ldap.Search(request.SearchBase, searchFilter, request.Attributes, request.SearchScope, request.MaxResults, request.NextToken, request.Union);
50+
if(request.Config.TokenType == "Server" || request.Config.TokenType == "Client"){
51+
response = ldap.Search(request, request.SearchBase, searchFilter, request.Attributes, request.SearchScope, request.MaxResults, request.NextToken, request.Union);
52+
53+
}
54+
else{
55+
throw new FormatException("Warning: TokenType must be set to Server or Client");
56+
}
5257
ldap.Disconnect();
5358
}
5459
catch (Exception e)
5560
{
5661
response = LdapServer.ReturnError(e, request.Config);
5762
}
5863
}
59-
6064
Console.WriteLine(JsonTools.Serialize(response, true));
6165

6266
}
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
{
2-
"objectType": "Group",
3-
"searchValue": "TooManyGroup_0019",
4-
"attributes": [
5-
"cn",
6-
"displayName"
7-
]
8-
}
2+
"objectType": "Group",
3+
"searchValue": "leegroup_*",
4+
"searchBase": "OU=Myriad,OU=TooManyGroups2,DC=ad,DC=cavazosactivedirectory,DC=com",
5+
"attributes": [],
6+
"maxResults": 30,
7+
"nextToken": "MTAtMDI=",
8+
"union": [
9+
{
10+
"searchValue": "leegroup_*",
11+
"searchBase": "OU=Myriad,OU=TooManyGroups2,DC=ad,DC=cavazosactivedirectory,DC=com"
12+
},
13+
{
14+
"searchValue": "leegroup_*",
15+
"searchBase": "OU=Myriad,OU=TooManyGroups2,DC=ad,DC=cavazosactivedirectory,DC=com"
16+
}
17+
]
18+
}

0 commit comments

Comments
 (0)