DirectoryTree / LdapRecord-Laravel

Multi-domain LDAP Authentication & Management for Laravel.
https://ldaprecord.com/docs/laravel/v3
MIT License
501 stars 53 forks source link

[Bug] ldap:import ldap --filter "(mail=xxx@xxx.com)" produce "unknown column '' in where clause" #207

Closed laTruffe79 closed 3 years ago

laTruffe79 commented 3 years ago

Environment (please complete the following information):

Describe the bug: When I try to import a single user using the command I cannot achieve I have this error :

SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause' (SQL: select * from `users` where `` = 0ca5445b-2916-4d11-8176-f4e95f702504 or (`email` = xxx@xxx.com) LIMIT 1)

It's pretty weird. I just want to import accounts manually I followed the documentation, added implements LdapAuthenticatable to the Laravel User model and stub methods so what do I missed ?

Thanks for your help

stevebauman commented 3 years ago

Hi @laTruffe79,

Can you post your config/auth.phpfile?

laTruffe79 commented 3 years ago

Off course

|--------------------------------------------------------------------------
    | Authentication Defaults
    */

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
            //'provider' => 'ldap',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
            'hash' => false,
        ],
    ],

'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],

        'ldap' => [
            'driver' => 'ldap',
            'model' => LdapRecord\Models\ActiveDirectory\User::class,
            'database' => [
                'model' => App\Models\User::class,
                'sync_passwords' => true,
                'sync_attributes' => [
                    'name' => 'cn',
                    'email' => 'mail',
                ],
                'sync_existing' => [
                    'email' => 'mail',
                ],
            ],
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

I do not mentionned I'm using Laravel 8 and jetstream It seems that the package does'nt know the guid column when he query the database ?

stevebauman commented 3 years ago

Ok, now can you post your App\Models\User.php file?

laTruffe79 commented 3 years ago

Sure, thanks :

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Jetstream\HasTeams;
use Laravel\Sanctum\HasApiTokens;

use LdapRecord\Laravel\Auth\LdapAuthenticatable;
use LdapRecord\Laravel\Auth\AuthenticatesWithLdap;

class User extends Authenticatable implements LdapAuthenticatable
{
    use HasApiTokens;
    use HasFactory;
    use HasProfilePhoto;
    use HasTeams;
    use Notifiable;
    use TwoFactorAuthenticatable;
    use AuthenticatesWithLdap;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token',
        'two_factor_recovery_codes',
        'two_factor_secret',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    /**
     * The accessors to append to the model's array form.
     *
     * @var array
     */
    protected $appends = [
        'profile_photo_url',
    ];

    /**
     * Get the database column name for the LDAP domain.
     *
     * @return string
     */
    public function getLdapDomainColumn()
    {
        // TODO: Implement getLdapDomainColumn() method.
    }

    /**
     * Get the models LDAP domain.
     *
     * @return string
     */
    public function getLdapDomain()
    {
        // TODO: Implement getLdapDomain() method.
    }

    /**
     * Set the models LDAP domain.
     *
     * @param string $domain
     *
     * @return void
     */
    public function setLdapDomain($domain)
    {
        // TODO: Implement setLdapDomain() method.
    }

    /**
     * Get the database column name for the LDAP guid.
     *
     * @return string
     */
    public function getLdapGuidColumn()
    {
        // TODO: Implement getLdapGuidColumn() method.
    }

    /**
     * Get the models LDAP GUID.
     *
     * @return string
     */
    public function getLdapGuid()
    {
        // TODO: Implement getLdapGuid() method.
    }

    /**
     * Set the models LDAP GUID.
     *
     * @param string $guid
     *
     * @return void
     */
    public function setLdapGuid($guid)
    {
        // TODO: Implement setLdapGuid() method.
    }
}

Humm ok I must override the getters ?

stevebauman commented 3 years ago

You've overridden every method supplied by the AuthenticatesWithLdap trait.

Remove all of the overridden methods and you're all set. 👍

laTruffe79 commented 3 years ago

You've overridden every method supplied by the AuthenticatesWithLdap trait.

Remove all of the overridden methods and you're all set. 👍

Thanks for your help I followed phpstorm too quickly when he said "hey inject stub methods!" 😂