|
3 | 3 | namespace Adldap\Laravel\Commands\Console;
|
4 | 4 |
|
5 | 5 | use Exception;
|
| 6 | +use UnexpectedValueException; |
6 | 7 | use Adldap\Models\User;
|
7 | 8 | use Adldap\Laravel\Events\Imported;
|
8 | 9 | use Adldap\Laravel\Facades\Resolver;
|
9 | 10 | use Adldap\Laravel\Commands\SyncPassword;
|
10 | 11 | use Adldap\Laravel\Commands\Import as ImportUser;
|
11 | 12 | use Illuminate\Console\Command;
|
12 | 13 | use Illuminate\Support\Facades\Bus;
|
13 |
| -use Illuminate\Support\Facades\Auth; |
14 | 14 | use Illuminate\Support\Facades\Event;
|
| 15 | +use Illuminate\Support\Facades\Config; |
15 | 16 | use Illuminate\Database\Eloquent\Model;
|
16 | 17 |
|
17 | 18 | class Import extends Command
|
@@ -329,7 +330,34 @@ protected function delete(User $user, Model $model)
|
329 | 330 | */
|
330 | 331 | protected function model() : Model
|
331 | 332 | {
|
332 |
| - return Auth::getProvider()->createModel(); |
| 333 | + $model = Config::get('ldap_auth.model') ?? $this->determineModel(); |
| 334 | + |
| 335 | + return new $model; |
| 336 | + } |
| 337 | + |
| 338 | + /** |
| 339 | + * Retrieves the model by checking the configured LDAP authentication providers. |
| 340 | + * |
| 341 | + * @return string |
| 342 | + * |
| 343 | + * @throws UnexpectedValueException |
| 344 | + */ |
| 345 | + protected function determineModel() |
| 346 | + { |
| 347 | + // Retrieve all of the configured authentication providers that |
| 348 | + // use the LDAP driver and have a configured model. |
| 349 | + $providers = array_where(Config::get('auth.providers'), function ($value, $key) { |
| 350 | + return $value['driver'] == 'ldap' && array_key_exists('model', $value); |
| 351 | + }); |
| 352 | + |
| 353 | + // Pull the first driver and return a new model instance. |
| 354 | + if ($ldap = reset($providers)) { |
| 355 | + return $ldap['model']; |
| 356 | + } |
| 357 | + |
| 358 | + throw new UnexpectedValueException( |
| 359 | + 'Unable to retrieve LDAP authentication driver. Did you forget to configure it?' |
| 360 | + ); |
333 | 361 | }
|
334 | 362 |
|
335 | 363 | /**
|
|
0 commit comments