Skip to content

Commit 85dfb6f

Browse files
authored
Make ldap optional (#4208)
1 parent 7bdac9f commit 85dfb6f

5 files changed

Lines changed: 15 additions & 14 deletions

File tree

app/DTO/LdapConfiguration.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ final class LdapConfiguration
3535
public readonly int $connection_timeout;
3636

3737
/**
38-
* @throws LdapConfigurationException if required LDAP config missing
38+
* @throws LdapConfigurationException if required LDAP config missing or ext-ldap absent
3939
*/
4040
public function __construct()
4141
{
42+
if (!extension_loaded('ldap')) {
43+
throw new LdapConfigurationException('LDAP configuration error: the PHP ldap extension is not installed');
44+
}
45+
4246
// Validate required connection settings
4347
$this->host = $this->requireString(config('ldap.connections.default.hosts')[0], 'LDAP_HOST', 'ldap.example.com');
4448
$this->port = $this->requireInt(config('ldap.connections.default.port'), 'LDAP_PORT');

app/Http/Controllers/AuthController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ public function getConfig(): AuthConfig
122122
*/
123123
protected function isLdapEnabled(Request $request): bool
124124
{
125-
return $request->verify()->is_supporter() && config('ldap.auth.enabled', false) === true;
125+
return $request->verify()->is_supporter() &&
126+
config('ldap.auth.enabled', false) === true &&
127+
extension_loaded('ldap') &&
128+
class_exists(\LdapRecord\Connection::class);
126129
}
127130

128131
/**

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@
167167
"php-http/discovery": false
168168
}
169169
},
170+
"suggest": {
171+
"ext-ldap": "Required to enable LDAP authentication (LDAP_ENABLED=true)"
172+
},
170173
"minimum-stability": "dev",
171174
"prefer-stable": true
172175
}

config/ldap.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
'use_ssl' => env('LDAP_PORT', 389) === 636, // Auto-detect LDAPS from port
2929

3030
// Additional connection options
31-
'options' => [
32-
// TLS certificate verification
31+
// LDAP constants require ext-ldap; skip when the extension is absent
32+
'options' => extension_loaded('ldap') ? [
3333
LDAP_OPT_X_TLS_REQUIRE_CERT => ((bool) env('LDAP_TLS_VERIFY_PEER', true))
3434
? LDAP_OPT_X_TLS_DEMAND
3535
: LDAP_OPT_X_TLS_ALLOW,
36-
],
36+
] : [],
3737
],
3838
],
3939

public/index.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@
1818
*/
1919
require_once __DIR__ . '/../bootstrap/PanicAttack.php';
2020

21-
/**
22-
* Check if the required extensions are loaded and if not, display a nice error page.
23-
* This is a sanity check to prevent the user from seeing a blank page with an error in the top left corner.
24-
*/
25-
if (!extension_loaded('ldap')) {
26-
$panic_attack = new PanicAttack();
27-
$panic_attack->ldap();
28-
}
29-
3021
/*
3122
|--------------------------------------------------------------------------
3223
| Initialize before loading composer

0 commit comments

Comments
 (0)