Я пытаюсь реализовать аутентификацию LDAP в приложении для моей компании. Я использую Laravel 5.8 и пакет LdapRecord (https://github.com/DirectoryTree/LdapRecord-Laravel).
Мне удалось подключить приложение к серверу LDAP, но аутентификация по-прежнему не работает, и неизвестно почему ...: (
Вот мой код:
Контроллер входа в систему
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use LdapRecord\Container;
use Illuminate\Http\Request;
use App\User;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* LDAP Connection
*/
private $connection;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->connection = Container::getConnection('default');
$this->middleware('guest')->except('logout');
}
public function username() {
return 'username';
}
protected function credentials(Request $request)
{
return [
'comptent' => $request->username,
'password' => $request->password,
];
}
}
Вот конфигурация - auth. php:
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'ldap',
],
// some code
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Ldap\User::class,
],
'ldap' => [
'driver' => 'ldap',
'model' => LdapRecord\Models\ActiveDirectory\User::class,
'rules' => [],
'database' => [
'model' => App\Ldap\User::class,
'sync_passwords' => false,
'sync_attributes' => [
'LASTNAME' => 'sn',
'FIRSTNAME' => 'givenname',
'ACTIVE_DIRECTORY_USER' => 'comptent'
Модель пользователя - Пользователь. php:
<?php
namespace App\Ldap;
//use Illuminate\Database\Eloquent\Model;
use LdapRecord\Laravel\Auth\HasLdapUser;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use LdapRecord\Laravel\Auth\AuthenticatesWithLdap;
use LdapRecord\Laravel\Auth\LdapAuthenticatable;
use LdapRecord\Models\Model;
/**
* Class User
*
* @property int $ID_USER
* @property string $LASTNAME
* @property string $FIRSTNAME
* @property string $ACTIVE_DIRECTORY_USER
* @property int $ID_ROLE
*
* @property Role $role
*
* @package App\Models
*/
class User extends Model
{
use Notifiable, AuthenticatesWithLdap;
/**
* The object classes of the LDAP model.
*
* @var array
*/
public static $objectClasses = [];
protected $table = 'user';
protected $primaryKey = 'ID_USER';
public $incrementing = false;
public $timestamps = false;
protected $casts = [
'ID_USER' => 'int',
'ID_ROLE' => 'int'
];
protected $fillable = [
'LASTNAME',
'FIRSTNAME',
'ACTIVE_DIRECTORY_USER',
'ID_ROLE'
];
public function role()
{
return $this->belongsTo(Role::class, 'ID_ROLE');
}
}
Вот некоторые журналы, которые у меня появляются, когда я пытаюсь для входа в систему:
[2020-02-19 15:49:12] local.INFO: LDAP (ldap://srv-gldap1:389) - Operation: Listing - Base DN: ou=utilisateurs,dc=rms,dc=fr - Filter: (objectclass=*) - Selected: (*) - Time Elapsed: 922.65
[2020-02-19 15:49:12] local.INFO: LDAP (ldap://srvil-gdldap1:389) - Operation: Search - Base DN: ou=utilisateurs,dc=rms,dc=fr - Filter: (comptentdomaine=hippolyte.massicot@rms.local) - Selected: (*) - Time Elapsed: 101.91
Есть ли кто-нибудь, кто уже использовал этот пакет и может помочь мне с моим кодом? заранее спасибо :)