Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit a8bdb4e

Browse files
committed
Added ability turn off password synchronization.
- Closes #99.
1 parent 71d4f67 commit a8bdb4e

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

src/Config/auth.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,29 @@
8484

8585
'password_key' => env('ADLDAP_PASSWORD_KEY', 'password'),
8686

87+
/*
88+
|--------------------------------------------------------------------------
89+
| Password Sync
90+
|--------------------------------------------------------------------------
91+
|
92+
| The password sync option allows you to automatically synchronize
93+
| users AD passwords to your local database. These passwords are
94+
| hashed natively by laravel.
95+
|
96+
| Enabling this option would also allow users to login to their
97+
| accounts using the password last used when an AD connection
98+
| was present.
99+
|
100+
| If this option is disabled, the local user account is applied
101+
| a random 16 character hashed password, and will lose access
102+
| to this account upon loss of AD connectivity.
103+
|
104+
| This option must be true or false.
105+
|
106+
*/
107+
108+
'password_sync' => env('ADLDAP_PASSWORD_SYNC', true),
109+
87110
/*
88111
|--------------------------------------------------------------------------
89112
| Login Attribute

src/Traits/ImportsUsers.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,15 @@ protected function syncModelFromAdldap(User $user, Authenticatable $model)
120120
*/
121121
protected function syncModelPassword(Authenticatable $model, $password)
122122
{
123-
if ($model instanceof Model && $model->hasSetMutator('password')) {
124-
// If the model has a set mutator for the password then
125-
// we'll assume that the dev is using their
126-
// own encryption method for passwords.
127-
$model->password = $password;
123+
// If the developer doesn't want to synchronize AD passwords,
124+
// we'll set the password to a random 16 character string.
125+
$password = ($this->getPasswordSync() ? $password : str_random());
128126

129-
return $model;
130-
}
131-
132-
// Always encrypt the model password by default.
133-
$model->password = bcrypt($password);
127+
// If the model has a set mutator for the password then
128+
// we'll assume that the dev is using their own
129+
// encryption method for passwords. Otherwise
130+
// we'll bcrypt it normally.
131+
$model->password = ($model->hasSetMutator('password') ? $password : bcrypt($password));
134132

135133
return $model;
136134
}
@@ -246,7 +244,7 @@ protected function getAdldap($provider = null)
246244
}
247245

248246
/**
249-
* Retrieves the Aldldap select attributes when performing
247+
* Returns the configured select attributes when performing
250248
* queries for authentication and binding for users.
251249
*
252250
* @return array
@@ -257,7 +255,7 @@ protected function getSelectAttributes()
257255
}
258256

259257
/**
260-
* Returns the username attribute for discovering LDAP users.
258+
* Returns the configured username attribute for discovering LDAP users.
261259
*
262260
* @return array
263261
*/
@@ -267,7 +265,7 @@ protected function getUsernameAttribute()
267265
}
268266

269267
/**
270-
* Retrieves the Adldap bind user to model config option for binding
268+
* Returns the configured bind user to model option for binding
271269
* the Adldap user model instance to the laravel model.
272270
*
273271
* @return bool
@@ -278,7 +276,7 @@ protected function getBindUserToModel()
278276
}
279277

280278
/**
281-
* Retrieves the Adldap login attribute for authenticating users.
279+
* Returns the configured login attribute for authenticating users.
282280
*
283281
* @return string
284282
*/
@@ -288,7 +286,7 @@ protected function getLoginAttribute()
288286
}
289287

290288
/**
291-
* Retrieves the Adldap sync attributes for filling the
289+
* Returns the configured sync attributes for filling the
292290
* Laravel user model with active directory fields.
293291
*
294292
* @return array
@@ -298,6 +296,16 @@ protected function getSyncAttributes()
298296
return Config::get('adldap_auth.sync_attributes', ['name' => $this->getSchema()->commonName()]);
299297
}
300298

299+
/**
300+
* Returns the configured password sync configuration option.
301+
*
302+
* @return bool
303+
*/
304+
protected function getPasswordSync()
305+
{
306+
return Config::get('adldap_auth.password_sync', true);
307+
}
308+
301309
/**
302310
* Returns the configured login limitation filter.
303311
*
@@ -309,7 +317,7 @@ protected function getLimitationFilter()
309317
}
310318

311319
/**
312-
* Retrieves the default connection name from the configuration.
320+
* Returns the configured default connection name.
313321
*
314322
* @return mixed
315323
*/

0 commit comments

Comments
 (0)