{"record":{"id":"8345982f8135ac42","repo":"BookStackApp/BookStack","slug":"exception-getmessage","errorCode":null,"errorMessage":"$exception->getMessage()","messagePattern":"\\$exception->getMessage\\(\\)","errorType":"exception","errorClass":"LoginAttemptException","httpStatus":null,"severity":"error","filePath":"app/Access/Guards/LdapSessionGuard.php","lineNumber":82,"sourceCode":"        $username = $credentials['username'];\n        $userDetails = $this->ldapService->getUserDetails($username);\n\n        $user = null;\n        if (isset($userDetails['uid'])) {\n            $this->lastAttempted = $user = $this->provider->retrieveByCredentials([\n                'external_auth_id' => $userDetails['uid'],\n            ]);\n        }\n\n        if (!$this->ldapService->validateUserCredentials($userDetails, $credentials['password'])) {\n            return false;\n        }\n\n        if (is_null($user)) {\n            try {\n                $user = $this->createNewFromLdapAndCreds($userDetails, $credentials);\n            } catch (UserRegistrationException $exception) {\n                throw new LoginAttemptException($exception->getMessage());\n            }\n        }\n\n        if (!($user instanceof User)) {\n            throw new LoginAttemptException('Could not find or create a user for LDAP login.');\n        }\n\n        // Sync LDAP groups if required\n        if ($this->ldapService->shouldSyncGroups()) {\n            $this->ldapService->syncGroups($user, $username);\n        }\n\n        // Attach avatar if non-existent\n        if (!$user->avatar()->exists()) {\n            $this->ldapService->saveAndAttachAvatar($user, $userDetails);\n        }\n\n        $this->login($user, $remember);","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/BookStackApp/BookStack/blob/18f8469a1c72f8cc8497e9372635e6dea5028071/app/Access/Guards/LdapSessionGuard.php#L64-L100","documentation":"LoginAttemptException rethrown in LdapSessionGuard::attempt wrapping a UserRegistrationException that occurred while creating a new local user from LDAP details. The original registration message (e.g. missing email, invalid details) is surfaced as a login failure. This library throws it because the LDAP user could not be provisioned locally.","triggerScenarios":"First-time LDAP login for a user with no local User record where createNewFromLdapAndCreds (or the underlying registration service) throws UserRegistrationException — commonly because the LDAP record lacks an email and no fallback email was provided, or the email collides with an existing account.","commonSituations":"LDAP users without a mail attribute; multiple LDAP users mapping to the same email violating uniqueness; auto-registration disabled or restricted by email domain; user data sanitization rejecting characters from the LDAP record.","solutions":["Read the wrapped message: it states the exact registration failure (e.g. missing email)","Ensure LDAP users have a mail attribute, or configure a fallback email (e.g. 'email' => attribute/default) in the LDAP config","Check for email collisions with existing local users and resolve duplicates","Verify registration settings (auto-register on, allowed email domains) permit LDAP user creation"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (empty($ldapUserDetails['email']) && empty($credentials['email'] ?? null)) {\n    throw new \\InvalidArgumentException('LDAP user has no email; cannot provision.');\n}","typeGuard":"function isProvisionable(array $ldapDetails, array $creds): bool {\n    return !empty(trim($ldapDetails['email'] ?? '')) || !empty($creds['email'] ?? null);\n}","tryCatchPattern":"try {\n    auth()->attempt($credentials);\n} catch (\\BookStack\\Access\\Exceptions\\LoginAttemptException $e) {\n    return back()->with('error', $e->getMessage());\n}","preventionTips":["Ensure the mail attribute is populated for all LDAP accounts that may log in","Configure a sensible email attribute mapping or fallback","Watch for email collisions between LDAP users and existing local accounts"],"tags":["ldap","provisioning","login"],"backgroundTag":"ldap-user-provisioning-failed","analyzedSha":"18f8469a1c72f8cc8497e9372635e6dea5028071","analyzedAt":"2026-09-02T19:49:33.068Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}