mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Changed debug level on bad LDAP connection (#9314)
* Changed debug level on bad LDAP connection TODO: Unfuck all of this. It’s a mess and it really doesn’t work the way we think it does. AdLdap library strikes again. :( Signed-off-by: snipe <snipe@snipe.net> * Improved phrasing Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
72f7baf5ee
commit
8fd8e716ac
|
@ -36,13 +36,17 @@ class SettingsController extends Controller
|
||||||
public function ldapAdSettingsTest(LdapAd $ldap): JsonResponse
|
public function ldapAdSettingsTest(LdapAd $ldap): JsonResponse
|
||||||
{
|
{
|
||||||
if(!$ldap->init()) {
|
if(!$ldap->init()) {
|
||||||
Log::info('LDAP is not enabled cannot test.');
|
Log::info('LDAP is not enabled so we cannot test.');
|
||||||
return response()->json(['message' => 'LDAP is not enabled, cannot test.'], 400);
|
return response()->json(['message' => 'LDAP is not enabled, cannot test.'], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The connect, bind and resulting users message
|
// The connect, bind and resulting users message
|
||||||
$message = [];
|
$message = [];
|
||||||
|
|
||||||
|
|
||||||
|
// This is all kinda fucked right now. The connection test doesn't actually do what you think,
|
||||||
|
// // and the way we parse the errors
|
||||||
|
// on the JS side is horrible.
|
||||||
Log::info('Preparing to test LDAP user login');
|
Log::info('Preparing to test LDAP user login');
|
||||||
// Test user can connect to the LDAP server
|
// Test user can connect to the LDAP server
|
||||||
try {
|
try {
|
||||||
|
@ -51,13 +55,11 @@ class SettingsController extends Controller
|
||||||
'message' => 'Successfully connected to LDAP server.'
|
'message' => 'Successfully connected to LDAP server.'
|
||||||
];
|
];
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
\Log::debug('LDAP connected but Bind failed. Please check your LDAP settings and try again.');
|
\Log::debug('Connection to LDAP server '.Setting::getSettings()->ldap_server.' failed. Please check your LDAP settings and try again. Server Responded with error: ' . $ex->getMessage());
|
||||||
return response()->json([
|
return response()->json(
|
||||||
'message' => 'Error logging into LDAP server, error: ' . $ex->getMessage() . ' - Verify your that your username and password are correct']);
|
['message' => 'Connection to LDAP server '.Setting::getSettings()->ldap_server." failed. Verify that the LDAP hostname is entered correctly and that it can be reached from this web server. \n\nServer Responded with error: " . $ex->getMessage()
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
], 400);
|
||||||
\Log::info('LDAP connection failed but we cannot debug it any further on our end.');
|
|
||||||
return response()->json(['message' => 'The LDAP connection failed but we cannot debug it any further on our end. The error from the server is: '.$e->getMessage()], 500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::info('Preparing to test LDAP bind connection');
|
Log::info('Preparing to test LDAP bind connection');
|
||||||
|
@ -66,12 +68,11 @@ class SettingsController extends Controller
|
||||||
Log::info('Testing Bind');
|
Log::info('Testing Bind');
|
||||||
$ldap->testLdapAdBindConnection();
|
$ldap->testLdapAdBindConnection();
|
||||||
$message['bind'] = [
|
$message['bind'] = [
|
||||||
'message' => 'Successfully binded to LDAP server.'
|
'message' => 'Successfully bound to LDAP server.'
|
||||||
];
|
];
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
Log::info('LDAP Bind failed');
|
Log::info('LDAP Bind failed');
|
||||||
return response()->json([
|
return response()->json(['message' => 'Connection to LDAP successful, but we were unable to Bind the LDAP user '.Setting::getSettings()->ldap_uname.". Verify your that your LDAP Bind username and password are correct. \n\nServer Responded with error: " . $ex->getMessage()
|
||||||
'message' => 'Error binding to LDAP server, error: ' . $ex->getMessage()
|
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,9 +95,17 @@ class SettingsController extends Controller
|
||||||
'email' => $item[$settings['ldap_email']][0] ?? null,
|
'email' => $item[$settings['ldap_email']][0] ?? null,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
$message['user_sync'] = [
|
if ($users->count() > 0) {
|
||||||
'users' => $users
|
$message['user_sync'] = [
|
||||||
];
|
'users' => $users
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$message['user_sync'] = [
|
||||||
|
'message' => 'Connection to LDAP was successful, however there were no users returned from your query. You should confirm the Base Bind DN above.'
|
||||||
|
];
|
||||||
|
return response()->json($message, 400);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
Log::info('LDAP sync failed');
|
Log::info('LDAP sync failed');
|
||||||
$message['user_sync'] = [
|
$message['user_sync'] = [
|
||||||
|
|
|
@ -504,9 +504,9 @@ class LdapAd extends LdapAdConfiguration
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->ldap->connect();
|
$this->ldap->connect();
|
||||||
} catch (\Adldap\Auth\BindException $e) {
|
} catch (\Exception $e) {
|
||||||
Log::error($e);
|
Log::debug('LDAP ERROR: '.$e->getMessage());
|
||||||
throw new Exception('Unable to connect to LDAP directory!');
|
throw new Exception($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue