Skip to content

Commit

Permalink
Implement LDAP attribute fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
grezniczek committed Feb 5, 2024
1 parent c0de118 commit 4274407
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ REDCap 12.0.7 Standard / REDCap 12.0.8 LTS or newer.

- **LDAP Attribute mappings:** When LDAP is enabled, custom attribute mappings for email, first, last, and full name can be set. These will be used when attempting to get email and full name of an authenticated user.

- **Fall back to retrieving user information from REDCap's user table when no values are obtained from LDAP attributes:** When enabled and full name or Fall back to retrieving user information from REDCap's user table when no values are obtained from LDAP attributes

- **Custom:** When selected, custom credentials can be entered into a text box. Type one username-password pair per line, separated by a colon (e.g. `UserXY:secret123`). Usernames are not case-sensitive (passwords are).

- **Use Allowlist:** When checked, a list of usernames (one username per line) can be entered. Only users in this list will be able to authenticate successfully.
Expand All @@ -118,6 +120,7 @@ The **@SURVEY-AUTH** action tag can be used inside **@IF** action tags. Note tha

Release | Description
------- | ---------------------
v1.5.0 | LDAP attributes: Support fallback to REDCap's user table for email and full name.
v1.4.5 | Fix a potential LDAP error when using PHP8.1+
v1.4.4 | Critical bug fix: Surveys would be marked as completed before actually getting displayed. This was an unintended side effect of the v1.4.3 "fix". The log leak, for now, cannot be prevent, but the module now immediately sanitizes the `redcap_log_view` table by deleting any such log entries (the delete query is limited to the specific project and instrument).
v1.4.3 | Critical security bug fix: REDCap logged the POST request, including the clear-text password, in `redcap_log_view`. Run `DELETE FROM redcap_log_view WHERE miscellaneous LIKE "// POST%[redcap_survey_auth-password]%"` against your database to sanitize the table!
Expand Down
9 changes: 9 additions & 0 deletions SurveyAuthExternalModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,15 @@ private function doLDAPauth($username, $password, $config, &$result) {
}
}
@ldap_unbind($ldap);
// Optional fallback mapping of username and email from REDCap's user table
if ($this->settings->fallbackToTableUserInfo && (empty($result["fullname"]) || empty($result["email"]))) {
$sql = "SELECT `user_email`, `user_firstname`, `user_lastname` FROM redcap_user_information WHERE `username` = ? LIMIT 1";
$q = $this->query($sql, [$result["username"]]);
if ($row = $q->fetch_assoc()) {
if (empty($result["fullname"])) $result["fullname"] = trim("{$row["user_firstname"]} {$row["user_lastname"]}");
if (empty($result["email"])) $result["email"] = $row["user_email"];
}
}
}
catch (\Exception $e) {
$result["log_error"][] = "LDAP error: " . $e->getMessage();
Expand Down
2 changes: 2 additions & 0 deletions classes/SurveyAuthSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SurveyAuthSettings {
public $useCustom;
public $customCredentials;
public $otherLDAPConfigs;
public $fallbackToTableUserInfo;
public $ldapMappings = array(
"email" => array(),
"fullname" => array(),
Expand Down Expand Up @@ -73,6 +74,7 @@ function __construct($module)
$this->useOtherLDAP = $this->getValue("surveyauth_useotherldap", false);
$this->useCustom = $this->getValue("surveyauth_usecustom", false);
$this->otherLDAPConfigs = json_decode($this->getValue("surveyauth_otherldap", "[]"), true);
$this->fallbackToTableUserInfo = $this->getValue("surveyauth_ldap_uifallback", false);
if (!is_array($this->otherLDAPConfigs)) $this->otherLDAPConfigs = array();
$defaults = array(
"email" => "email,mail",
Expand Down
12 changes: 12 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@
]
}
},
{
"key":"surveyauth_ldap_uifallback",
"name":"Fall back to retrieving user information from REDCap's user table when no values are obtained from LDAP attributes",
"type": "checkbox",
"branchingLogic": {
"type": "or",
"conditions": [
{ "field": "surveyauth_useldap", "value": true },
{ "field": "surveyauth_useotherldap", "value": true }
]
}
},
{
"key": "surveyauth_usecustom",
"name": "Custom",
Expand Down

0 comments on commit 4274407

Please sign in to comment.