Catching successful and unsuccessful LDAP searches #587
-
With LDAP logging turned on I can see a
... and added corresponding methods into What am I doing wrong? I also notice that the search event log is rather cryptic:
Why all these hex values (which for amaccountname translates to 't654321')? Something I can configure to get it in plain text instead of hex? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @acharseth, Those events you're attempting to watch on are from the native core LdapRecord framework, which requires you to register your listeners from it's event dispatcher and not Laravel's event dispatcher. This is because the core LdapRecord framework doesn't require the use of Laravel (or any framework for that matter). Here are docs on how to register listeners for core LdapRecord events: https://ldaprecord.com/docs/core/v3/events/#registering-listeners use LdapRecord\Container;
use \LdapRecord\Query\Events\Search;
$dispatcher = Container::getDispatcher();
$dispatcher->listen(Search::class, function (Search $event) {
// ...
}); To tell which events can be listened for in Laravel, the events will reside underneath the Also, the use LdapRecord\Container;
$dispatcher = Container::getDispatcher();
// Listen for all query events.
$dispatcher->listen('LdapRecord\Query\Events\*', function ($eventName, array $data) {
// Returns 'LdapRecord\Models\Events\Search'
echo $eventName;
// Returns [0] => (object) LdapRecord\Query\Events\Search;
var_dump($data);
}); |
Beta Was this translation helpful? Give feedback.
-
For more elaborate information on how I implemented listen and log LdapRecord Core events:
App\Providers\LdapCoreServiceProvider::class,
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Services\LogType;
use app\Services\MyLog;
use LdapRecord\Models\ActiveDirectory\User as LdapUser;
use LdapRecord\Auth\Events\Attempting;
use LdapRecord\Auth\Events\Binding;
use LdapRecord\Auth\Events\Passed;
use LdapRecord\Auth\Events\Failed;
use LdapRecord\Auth\Events\Bound;
class LdapCoreServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
$dispatcher = \LdapRecord\Container::getDispatcher();
$dispatcher->listen(Attempting::class, function ($event) {
$userid=LdapUser::find($event->getUsername())->samaccountname[0];
MyLog::uaUidLog(LogType::Info, get_class($event), $userid, "Ldap autentiseringsforsøk");
});
$dispatcher->listen(Binding::class, function ($event) {
$userid=LdapUser::find($event->getUsername())->samaccountname[0];
MyLog::uaUidLog(LogType::Info, get_class($event), $userid, "Ldap binding");
});
$dispatcher->listen(Passed::class, function ($event) {
$userid=LdapUser::find($event->getUsername())->samaccountname[0];
MyLog::uaUidLog(LogType::Info, get_class($event), $userid, "Ldap autentisert");
});
$dispatcher->listen(Failed::class, function ($event) {
$userid=LdapUser::find($event->getUsername())->samaccountname[0];
MyLog::uaUidLog(LogType::Alert, get_class($event), $userid, "Ldap autentisering feilet!");
});
$dispatcher->listen(Bound::class, function ($event) {
$userid=LdapUser::find($event->getUsername())->samaccountname[0];
MyLog::uaUidLog(LogType::Info, get_class($event), $userid, "Ldap bound");
});
}
/**
* Bootstrap services.
*/
public function boot(): void
{
//
}
} |
Beta Was this translation helpful? Give feedback.
Hi @acharseth,
Those events you're attempting to watch on are from the native core LdapRecord framework, which requires you to register your listeners from it's event dispatcher and not Laravel's event dispatcher. This is because the core LdapRecord framework doesn't require the use of Laravel (or any framework for that matter).
Here are docs on how to register listeners for core LdapRecord events:
https://ldaprecord.com/docs/core/v3/events/#registering-listeners
To tell which events can be listened for in L…