Skip to content

Commit e108ac5

Browse files
committed
Added some extra logging, along with using reconnect/disconnect for the LDAP connections (not needed as much for this repository, but I think the changes were necessary for the sftpgo-ldap-http-server repository due to it having a long-lived process with the HTTP server.
1 parent 6bf7e8b commit e108ac5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

functions.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function authenticateUser() {
3434

3535
// Strip specific organization email domains if provided:
3636
if (isset($domains_to_strip_automatically)) {
37+
logMessage('Username before domain stripping: ' . $data['username']);
3738
foreach($domains_to_strip_automatically as $domain) {
3839
$domain = '@'.str_replace('@', '', $domain);
3940
logMessage('Attempting to strip ' . $domain . ' from provided username.');
@@ -44,7 +45,7 @@ function authenticateUser() {
4445
foreach($connections as $connectionName => $connection) {
4546

4647
logMessage('Before connection attempt to ' . $connectionName);
47-
$connection->connect();
48+
$connection->reconnect();
4849
logMessage('After connection attempt to ' . $connectionName);
4950

5051
$configuration = $connection->getConfiguration();
@@ -68,12 +69,21 @@ function authenticateUser() {
6869
// User has been successfully authenticated.
6970
logMessage('After authentication attempt for: ' . $data['username'] . ' (success!)');
7071
$output = createResponseObject($connectionName, $data['username']);
72+
73+
logMessage('Disconnecting from ' . $connectionName);
74+
$connection->disconnect();
7175
createResponse($output);
7276
} else {
7377
// Username or password is incorrect.
7478
logMessage('After authentication attempt for: ' . $data['username'] . ' (failed!)');
79+
80+
logMessage('Disconnecting from ' . $connectionName);
81+
$connection->disconnect();
7582
denyRequest();
7683
}
84+
} else {
85+
logMessage('Disconnecting from ' . $connectionName);
86+
$connection->disconnect();
7787
}
7888

7989
logMessage('User lookup failed for: ' . $data['username']);
@@ -82,6 +92,7 @@ function authenticateUser() {
8292
} catch (\LdapRecord\Auth\BindException $e) {
8393
$error = $e->getDetailedError();
8494

95+
logMessage($error->getErrorMessage());
8596
//echo $error->getErrorCode();
8697
//echo $error->getErrorMessage();
8798
//echo $error->getDiagnosticMessage();

0 commit comments

Comments
 (0)