-
Notifications
You must be signed in to change notification settings - Fork 193
Auth broken after upgrade to v6 (with DatabaseUserProvider) #693
Comments
Hi @ThomHurks, The query will return a user with either the given object guid or the given email. The exception is showing a duplicate |
@stevebauman Thanks for your reply. What is happening here is that even though the user binds correctly, the object guid is null. However all objectguid fields in the database are null since we just migrated, so simply the first row gets selected because To me it definitely seems like this behaviour is wrong. What it should do in my opinion is check if the object guid exists and is not null, and then try to query it in the database. In case the object guid does not exist or is null, just query on the Now the second issue is; why is the object guid always null for me? Well, according to the OpenLDAP schema, the object guid is the Regarding my third paragraph, I think the code should be something like: $query->where(
Resolver::getDatabaseUsernameColumn(),
'=',
$this->user->getFirstAttribute(Resolver::getLdapDiscoveryAttribute())
);
$guid = $this->user->getConvertedGuid();
if ($guid !== null) { // Or maybe use !empty($guid)?
$query->orWhere(
Resolver::getDatabaseIdColumn(),
'=',
$guid
);
}
$userCount = $query->count();
if ($userCount === 0) {
return null;
} elseif ($userCount === 1) {
return $query->first();
} else {
throw new ModelNotFoundException('Multiple matching users were found in the database.');
} Also note that I changed the use of only |
Hi @ThomHurks, I completely understand, thanks for spending the time to thoroughly go through this with me! I really appreciate it. I'll try to knock out all of your issues / questions here:
The query that is supposed to be executed is supposed to contain your LDAP users GUID and not Adldap2-Laravel/src/Commands/Import.php Lines 83 to 94 in c52c007
Otherwise you're right, the query is wrong if it returns
In the code pasted above from the // app/Schemas/OpenLDAP.php
namespace App\Schemas;
use Adldap\Schemas\OpenLDAP as BaseSchema;
class OpenLDAP extends BaseSchema
{
/**
* {@inheritdoc}
*/
public function objectGuid()
{
return 'uid'; // The LDAP attribute name that contains your users object GUID
}
} // config/ldap.php
'schema' => \App\Schemas\OpenLDAP::class, Once you put the above in place, the This is definitely where the issue lies - and once you put the above in place you won't have issues with the query generated that locates the user in your database. In the meantime I'm going to patch the Import job to throw an exception when an object GUID can't be located to prevent this from occurring. Are you able to try the above and see if it resolves your issue? |
- Make sure we can retrieve the LDAP users GUID and configured username by throwing an exception if one does not exist - #693
@stevebauman Thanks! I override the OpenLDAP schema now as you suggest, and now I can log in fine. Great! What do you think about my suggestion to also throw when more than one matching user is located in the database? That case shouldn't happen if the user has unique constraints on both the |
Awesome @ThomHurks! Glad you were able to resolve the issue.
I think you're right, there should be some protection in place to prevent this from happening just in case. I'll close out this issue once that protection is in place. Thanks again 😄 |
Very nice, thanks @stevebauman! |
Ok I added exceptions when the users Object GUID or username cannot be retrieved (9fe1443) - this covers the scenario if one of them returns New release will be out shortly! |
Thanks @stevebauman! |
Description:
I followed the upgrade guide to upgrade v6. After testing I found out that authentication is now broken. Upon examining the logs I found the following:
The reason is of course that the first query returns the first row in the users table (id=1) because all
objectguid
fields arenull
after just upgrading an existing users database. The following part of the query seems wrong:as that part will always cause the wrong user to be returned.
The text was updated successfully, but these errors were encountered: