private static IDirectoryAttributes AddContainerIfNecessary(Type type) { var mapping = LdapConfiguration.Configuration.Mapper.GetMapping(type); var containerCn = DnParser.ParseName(mapping.NamingContext); var containerPrefix = DnParser.ParseRDN(mapping.NamingContext); return(AddContainerIfNecessary(containerPrefix, containerCn)); }
private static void PopulateDirectoryForTests() { var user2Container = DnParser.ParseName(TestUserDirectoryContainer); var user2Prefix = DnParser.ParseRDN(TestUserDirectoryContainer); AddContainerIfNecessary(user2Prefix, user2Container); using (var context = new DirectoryContext()) { AddEntryIfNecessary("CN=PasswordUser," + TestUserDirectoryContainer, "user", context); AddEntryIfNecessary("CN=persontest," + TestUserDirectoryContainer, "user", context); AddEntryIfNecessary("CN=TestUser," + TestUserDirectoryContainer, "user", context); AddEntryIfNecessary("CN=TestUser2," + TestUserDirectoryContainer, "user", context); } var roleContainer = DnParser.ParseName(RolesDirectoryContainer); var rolePrefix = DnParser.ParseRDN(RolesDirectoryContainer); AddContainerIfNecessary(rolePrefix, roleContainer); using (var context = new DirectoryContext()) { IDirectoryAttributes rangeTest = AddEntryIfNecessary("CN=RangeTest," + RolesDirectoryContainer, "group", context); foreach (var kvp in rangeTest.Where(kvp => kvp.Key.StartsWith("member", StringComparison.OrdinalIgnoreCase))) { if (kvp.Value is IEnumerable <string> && ((IEnumerable <string>)kvp.Value).Any()) { Console.WriteLine("RangeTest members already populated"); return; } } var newMembers = new List <string>(); newMembers.AddRange(context.Query <LdsUser>().Take(10000).Select(u => u.DistinguishedName)); rangeTest.Set("member", newMembers); context.Update(rangeTest); } }
private static void EnablePasswordChangesOn389() { using (var context = new DirectoryContext()) { var attributes = context.ListServerAttributes("namingcontexts"); var namingContexts = attributes.GetStrings("namingcontexts"); var configurationDN = namingContexts != null ? namingContexts .FirstOrDefault(s => DnParser.ParseName(s) .Equals("Configuration", StringComparison.OrdinalIgnoreCase)) : null; bool success = false; if (configurationDN != null) { var directoryService = context.Query(configurationDN) .Where(_ => Filter.Equal(_, "cn", "Directory Service", true)) .Select("distinguishedName") .FirstOrDefault(); if (directoryService != null) { directoryService.Set("dSHeuristics", "0000000001001"); context.Update(directoryService); success = true; } } if (!success) { Console.WriteLine("Could not set a password policy"); } } }
public void ParseName_SingleCharacter_ReturnsCN() { DnParser.ParseName("n=test,Dd=domain,Dd=com").Should().Be.EqualTo("test"); }
public void ParseRDN_NoEqualsIndex_ThrowsException() { Executing.This(() => DnParser.ParseName("Test")) .Should().Throw <ArgumentException>(); }
public void ParseRDN_BadEqualsIndex_ThrowsException() { Executing.This(() => DnParser.ParseName("=test,Cn=test2,Dc=domain,Dc=com")) .Should().Throw <ArgumentException>(); }
public void ParseName_NullDn_ThrowsException() { Executing.This(() => DnParser.ParseName(null)) .Should().Throw <ArgumentException>(); }
public void ParseName_OU_ReturnsOU() { DnParser.ParseName("OU=test,Cn=test2,Dc=domain,Dc=com").Should().Be.EqualTo("test"); }
public void ParseName_CN_ReturnsCN() { DnParser.ParseName("Cn=test,Dc=domain,Dc=com").Should().Be.EqualTo("test"); }
public void ParseName_OneRDN_ReturnsOU() { DnParser.ParseName("OU=DoeJohn").Should().Be.EqualTo("DoeJohn"); }