Closed arfiqbal closed 4 years ago
Sounds like your application is doing something funky.
How are you running the ldap:import
command?
This is definitely not the case, and is easily tested here in the test cases:
@stevebauman i am just running php artisan ldap:import ldap
Do you need any file or output ?
even i am not able to figure it out, Kinda stuck here
Have you modified your users
database table migration?
I would check your logs after running the ldap:import
command and post them here.
The import command will synchronize all existing LDAP users, as well as import any new users. Unless of course you have added scopes to your LdapRecord model that is restricting the LDAP import query.
Also, post your LoginController.php
code -- as I'm not sure how you're "logging in two users at the same time"?
user migration ======= use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateUsersTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('users', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('name'); $table->string('username')->unique(); $table->string('password'); $table->rememberToken(); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('users'); } } ============= middleware('guest')->except('logout'); $this->listenForLdapBindFailure(); } public function username(){ return 'username'; } protected function credentials(Request $request) { return [ 'uid' => $request->get('username'), 'password' => $request->get('password'), ]; } }
when i say two user that means two different user...
In your configured sync_attributes
you have email
specified:
'sync_attributes' => [
'name' => 'cn',
'username' => 'uid',
'email' => 'mail', // <-- Here
],
But your users
database table does not have an email:
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('username')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
I'm assuming the import is failing -- due to this missing column.
Please run the ldap:import
command with logging
enabled in your ldap.php
configuration file, and post the results here that are output in your storage/logs
directory.
use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class AddEmailToUsers extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::table('users', function (Blueprint $table) { $table->string('email')->nullable(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::table('users', function (Blueprint $table) { // }); } }
forget to add my both migration file
Okay, please run the ldap:import
command with logging enabled in your ldap.php
configuration file, and post the results here that are output in your storage/logs directory.
Also, please post your App\Ldap\User.php
file.
App\Ldap\User.php
namespace App\Ldap; use LdapRecord\Models\Model; class User extends Model { /** * The object classes of the LDAP model. * * @var array */ public static $objectClasses = [ 'top', 'person', 'organizationalperson', 'inetorgperson', 'inetuser', 'posixaccount' ]; }
output of import command
[2020-04-22 22:39:28] local.INFO: User [gitlab] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [gitlab] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [vijay] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [vijay] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [arif] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [arif] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [vishalp] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [vishalp] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [mpatel] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [mpatel] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [rsainimsaini] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [rsainimsaini] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [pkumar] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [pkumar] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [sparida] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [sparida] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [ldixit] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [ldixit] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [odeshpande] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [odeshpande] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [smaralay] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [smaralay] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [dnagar] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [dnagar] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [pkajale] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [pkajale] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [aasif] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [aasif] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [ppandey] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [ppandey] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [sbehera] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [sbehera] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [psrivastava] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [psrivastava] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [msabnish] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [msabnish] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [pmdeshpande] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [pmdeshpande] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [aakhouri] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [aakhouri] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [spal] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [spal] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [vpawar] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [vpawar] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [pnaik] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [pnaik] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [krrathi] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [krrathi] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [rsaini] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [rsaini] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [stalkatkar] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [stalkatkar] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [sbaranwal] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [sbaranwal] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [gshinde] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [gshinde] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [lnair] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [lnair] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [sktukaram] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [sktukaram] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [ashelke] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [ashelke] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [sagarwal] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [sagarwal] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [drathi] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [drathi] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [ldapbind] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [ldapbind] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [test] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [test] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [test2] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [test2] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [test3] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [test3] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [johnsonn] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [johnsonn] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [psharma] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [psharma] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [santoshn] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [santoshn] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [ihasan] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [ihasan] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [skarpe] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [skarpe] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [rahulc] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [rahulc] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [rahuls] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [rahuls] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [araut] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [araut] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [pankaj] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [pankaj] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [santosh] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [santosh] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [anshu] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [anshu] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [kamlesh] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [kamlesh] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [kinjalv] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [kinjalv] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [mpawar] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [mpawar] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [jijop] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [jijop] has been successfully synchronized. [2020-04-22 22:39:28] local.INFO: User [gauravp] is being synchronized. [2020-04-22 22:39:28] local.INFO: User [gauravp] has been successfully synchronized.
but when i check my user table it show only the user i.e gauravp is added to the table. I dontn't why
Ok, I have some more questions:
LdapRecord\Models\OpenLDAP\Entry
model, as it is needed to retrieve the entryUUID
from the LDAP record for synchronizationguid
and domain
database columns to your users
table?No its a FreeIPA
use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class AddLdapColumnsToUsersTable extends Migration { /** * Run the migrations. */ public function up() { Schema::table('users', function (Blueprint $table) { $table->string('guid')->unique()->nullable(); $table->string('domain')->nullable(); }); } /** * Reverse the migrations. */ public function down() { Schema::table('users', function (Blueprint $table) { $table->dropColumn(['guid', 'domain']); }); } }
Okay, unfortunately I don't have any FreeIPA servers to test on. You will have to dive into this head first yourself. I would however try changing the $guidKey
property inside of your Ldap\User.php
model to entryUUID
(which I believe is the proper GUID key for FreeIPA):
namespace App\Ldap;
use LdapRecord\Models\Model;
class User extends Model
{
protected $guidKey = 'entryuuid';
Then try running the import again. This would be my first guess as to why it's not importing all users properly.
mysql> select * from users; +----+---------------+----------+--------------------------------------------------------------+----------------+---------------------+---------------------+------+---------+------------------------+ | id | name | username | password | remember_token | created_at | updated_at | guid | domain | email | +----+---------------+----------+--------------------------------------------------------------+----------------+---------------------+---------------------+------+---------+------------------------+ | 1 | Gaurav Pathak | gauravp | $2y$10$mi.GJQK9zhV6KueLuwGkqOxFmv2mBIxQwanyxCqKzp8m9Dc0RH34O | NULL | 2020-04-22 21:36:05 | 2020-04-22 22:59:07 | NULL | default | gauravp@xxx.com | +----+---------------+----------+--------------------------------------------------------------+----------------+---------------------+---------------------+------+---------+------------------------+ 1 row in set (0.00 sec)
Nope... it still the same
You need to find out what attribute contains your users guid
key. You can do this by dumping and dying in your routes/web.php
file like so:
// routes/web.php
use App\Ldap\User;
dd(User::first()->getAttributes());
Post your users attributes (with any sensitive ones removed), and I can help you locate it.
It should be something like this: 2c5ea4c0-4067-11e9-8b2d-1b9d6bcdbbfd
To prevent this, a new release will be out shortly to prevent imports being ran on objects where the GUID cannot be retrieved. This is to prevent any destructive potential using the importer.
Thanks!
Hi @stevebauman
issue resolved
App\Ldap\User.php
namespace App\Ldap;
use LdapRecord\Models\Model;
class User extends Model
{
protected $guidKey = 'ipauniqueid';
/**
* The object classes of the LDAP model.
*
* @var array
*/
public static $objectClasses = [
'top',
'person',
'organizationalperson',
'inetorgperson',
'inetuser',
'posixaccount'
];
}
For IPA we should add
protected $guidKey = 'ipauniqueid';
Thanks man for your help... appreciated :)
when i importing the user it will only updating the table instead of adding to the table so i end up with only one column and its shows 53 user synchronized. Only the last user added to the user table and when two user login at a same time it will only add latest user to the table
auth.php
'ldap' => [ 'driver' => 'ldap', 'model' => App\Ldap\User::class, 'database' => [
'model' => App\User::class, 'sync_passwords' => false,
'sync_attributes' => [ 'name' => 'cn', 'username' => 'uid', 'email' => 'mail', ], ], ],
user.php <?php
namespace App;
use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; use LdapRecord\Laravel\Auth\AuthenticatesWithLdap; use LdapRecord\Laravel\Auth\LdapAuthenticatable;
class User extends Authenticatable implements LdapAuthenticatable { use Notifiable, AuthenticatesWithLdap;
}
Environment (please complete the following information):