Skip to content

Commit 7c8edf5

Browse files
authored
Merge pull request #1096 from christophert/add-ldaptlsinsecure
Add option to disable LDAPS Certificate Validation
2 parents f4ea5f1 + 730cb78 commit 7c8edf5

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ LDAP_GROUP_ATTRIBUTE="memberOf"
7777
# Would you like to remove users from roles on BookStack if they do not match on LDAP
7878
# If false, the ldap groups-roles sync will only add users to roles
7979
LDAP_REMOVE_FROM_GROUPS=false
80+
# Set this option to disable LDAPS Certificate Verification
81+
LDAP_TLS_INSECURE=false
8082

8183
# Mail settings
8284
MAIL_DRIVER=smtp

app/Auth/Access/LdapService.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ protected function getConnection()
170170
}
171171
$hostName = $ldapServer[0] . ($hasProtocol?':':'') . $ldapServer[1];
172172
$defaultPort = $ldapServer[0] === 'ldaps' ? 636 : 389;
173+
174+
/*
175+
* Check if TLS_INSECURE is set. The handle is set to NULL due to the nature of
176+
* the LDAP_OPT_X_TLS_REQUIRE_CERT option. It can only be set globally and not
177+
* per handle.
178+
*/
179+
if($this->config['tls_insecure']) {
180+
$this->ldap->setOption(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
181+
}
182+
173183
$ldapConnection = $this->ldap->connect($hostName, count($ldapServer) > 2 ? intval($ldapServer[2]) : $defaultPort);
174184

175185
if ($ldapConnection === false) {

config/services.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
'user_to_groups' => env('LDAP_USER_TO_GROUPS',false),
150150
'group_attribute' => env('LDAP_GROUP_ATTRIBUTE', 'memberOf'),
151151
'remove_from_groups' => env('LDAP_REMOVE_FROM_GROUPS',false),
152+
'tls_insecure' => env('LDAP_TLS_INSECURE', false),
152153
]
153154

154155
];

0 commit comments

Comments
 (0)