Skip to content

Commit

Permalink
Fixes an issue where the Active Directory trigger UI screen had overl…
Browse files Browse the repository at this point in the history
…apping elements

Fixes an issue where credentials in the form of domain\username could not be used on the Active Directory trigger
  • Loading branch information
ryannewington committed Apr 28, 2018
1 parent 56c0f32 commit b5cac85
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Lithnet.Miiserver.AutoSync/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static bool HasUnconfirmedExports(this StepDetails s)
{
return s?.ExportCounters?.HasChanges ?? false;
}

public static TResult InvokeThenClose<TChannel, TResult>(this TChannel client, Func<TChannel, TResult> function) where TChannel : ICommunicationObject
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public NetworkCredential GetCredentialPackage()
return null;
}

return new NetworkCredential(this.Username, this.Password?.Value);
return new NetworkCredential(ActiveDirectoryChangeTrigger.GetUserNameFromFullyQualifiedName(this.Username), this.Password?.Value, ActiveDirectoryChangeTrigger.GetDomainOrNullFromFullyQualifiedName(this.Username));
}

[DataMember(Name = "username")]
Expand Down Expand Up @@ -107,16 +107,19 @@ private void SetupListener()
{
this.stopped = false;
LdapDirectoryIdentifier directory = new LdapDirectoryIdentifier(this.HostName);
NetworkCredential creds = this.GetCredentialPackage();

if (this.HasCredentials)
if (creds != null)
{
this.connection = new LdapConnection(directory, this.GetCredentialPackage());
this.Log($"Connecting to {this.HostName} as {this.Username}");
this.connection = new LdapConnection(directory, creds);
}
else
{
this.Log($"Connecting to {this.HostName} as {Thread.CurrentPrincipal.Identity.Name}");
this.connection = new LdapConnection(directory);
}

List<string> attributesToGet = new List<string>() { ActiveDirectoryChangeTrigger.ObjectClassAttribute };
attributesToGet.AddRange(ActiveDirectoryChangeTrigger.TimeStampAttributesToIgnore);

Expand All @@ -135,6 +138,8 @@ private void SetupListener()
PartialResultProcessing.ReturnPartialResultsAndNotifyCallback,
this.Notify,
r);

this.Log($"Listening for changes from {this.HostName}");
}
catch (Exception ex)
{
Expand Down Expand Up @@ -377,5 +382,53 @@ private void OnDeserializing(StreamingContext context)
{
this.Initialize();
}

private static string GetDomainOrNullFromFullyQualifiedName(string fqname)
{
if (string.IsNullOrWhiteSpace(fqname))
{
return null;
}

int sindex = fqname.IndexOf('\\');

if (sindex > -1)
{
return fqname.Substring(0, sindex);
}

sindex = fqname.IndexOf('@');

if (sindex > -1)
{
return fqname.Substring(sindex + 1, fqname.Length - sindex - 1);
}

return null;
}

private static string GetUserNameFromFullyQualifiedName(string fqname)
{
if (string.IsNullOrWhiteSpace(fqname))
{
return fqname;
}

int sindex = fqname.IndexOf('\\');

if (sindex > -1)
{
return fqname.Substring(sindex + 1, fqname.Length - sindex - 1);
}

sindex = fqname.IndexOf('@');

if (sindex > -1)
{
return fqname.Substring(0, sindex);
}

return fqname;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition Height="5"/>
<RowDefinition/>
<RowDefinition Height="5"/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
Expand All @@ -45,10 +45,10 @@
Margin="10 0 0 5"
Text="{Binding BaseDN}" />

<TextBlock Grid.Row="3"
<TextBlock Grid.Row="4"
Grid.Column="0"
Text="Object classes"/>
<TextBox Grid.Row="3"
<TextBox Grid.Row="4"
Grid.Column="1"
Margin="10 0 0 5"
Text="{Binding ObjectClasses}" />
Expand Down

0 comments on commit b5cac85

Please sign in to comment.