Skip to content

Commit

Permalink
Improve AD login speed
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Jacobsen Work committed May 17, 2023
1 parent 2e13beb commit 53ca882
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion BLAZAM/BLAZAM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<ServerGarbageCollection>false</ServerGarbageCollection>
<AssemblyVersion>0.8.2</AssemblyVersion>
<Version>2023.05.17.0002</Version>
<Version>2023.05.17.1900</Version>
<RootNamespace>BLAZAM</RootNamespace>
<GenerateDocumentationFile>False</GenerateDocumentationFile>

Expand Down
37 changes: 29 additions & 8 deletions BLAZAMActiveDirectory/ActiveDirectoryContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ public void Dispose()
{
try
{

var findUser = Users.FindUserByUsername(loginReq.Username.ToLower(), false);
if (findUser != null)
{
Expand All @@ -482,18 +483,38 @@ public void Dispose()
{
loginReq.Username += "@" + ConnectionSettings.FQDN;
}
using (var connection = new LdapConnection(new LdapDirectoryIdentifier(ConnectionSettings.ServerAddress, ConnectionSettings.ServerPort)))

WindowsImpersonationUser logonUser = new WindowsImpersonationUser
{
FQDN = ConnectionSettings.FQDN,
Username=loginReq.Username,
Password= loginReq.SecurePassword
};
WindowsImpersonation impersonation = new WindowsImpersonation(logonUser);
try
{
impersonation.Run(() => {
return true;
});
return findUser;
}
catch(Exception ex)
{
connection.AuthType = AuthType.Basic;
connection.SessionOptions.ProtocolVersion = 3;
connection.SessionOptions.SecureSocketLayer = ConnectionSettings.UseTLS;
return null;
}

connection.Credential = new NetworkCredential(loginReq.Username, loginReq.SecurePassword);
connection.Bind();
//using (var connection = new LdapConnection(new LdapDirectoryIdentifier(ConnectionSettings.ServerAddress, ConnectionSettings.ServerPort)))
//{
// connection.AuthType = AuthType.Basic;
// connection.SessionOptions.ProtocolVersion = 3;
// connection.SessionOptions.SecureSocketLayer = ConnectionSettings.UseTLS;

return findUser;
// connection.Credential = new NetworkCredential(loginReq.Username, loginReq.SecurePassword);
// connection.Bind();

}
// return findUser;

//}

}
}
Expand Down

0 comments on commit 53ca882

Please sign in to comment.