Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Controller/SAMLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ private function autoprovisionIfPossible(array $auth) {
$uid = $auth[$uidMapping];
}

$uidRewritePattern = $this->config->getAppValue('user_saml', $prefix . 'general-uid_rewrite_pattern');
$uidRewriteReplacement = $this->config->getAppValue('user_saml', $prefix . 'general-uid_rewrite_replacement');
if (!empty($uidRewritePattern) && !empty($uidRewriteReplacement)) {
$uid = preg_replace($uidRewritePattern, $uidRewriteReplacement, $uid);
}

// make sure that a valid UID is given
if (empty($uid)) {
$this->logger->error('Uid "' . $uid . '" is not a valid uid please check your attribute mapping', ['app' => $this->appName]);
Expand Down
8 changes: 7 additions & 1 deletion lib/DavPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ public function beforeMethod(RequestInterface $request, ResponseInterface $respo
!$this->session->exists('user_saml.samlUserData')
) {
$uidMapping = $this->config->getAppValue('user_saml', 'general-uid_mapping');
$uidRewritePattern = $this->config->getAppValue('user_saml', 'general-uid_rewrite_pattern');
$uidRewriteReplacement = $this->config->getAppValue('user_saml', 'general-uid_rewrite_replacement');
if (isset($this->auth[$uidMapping])) {
$this->session->set(Auth::DAV_AUTHENTICATED, $this->auth[$uidMapping]);
$uid = $this->auth[$uidMapping];
if (!empty($uidRewritePattern) && !empty($uidRewriteReplacement)) {
$uid = preg_replace($uidRewritePattern, $uidRewriteReplacement, $uid);
}
$this->session->set(Auth::DAV_AUTHENTICATED, $uid);
$this->session->set('user_saml.samlUserData', $this->auth);
}
}
Expand Down
8 changes: 8 additions & 0 deletions lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public function getForm() {
'type' => 'line',
'required' => true,
],
'uid_rewrite_pattern' => [
'text' => $this->l10n->t('UID rewrite pattern RegEx (PHP preg_replace pattern)'),
'type' => 'line',
],
'uid_rewrite_replacement' => [
'text' => $this->l10n->t('UID rewrite replacement (PHP preg_replace pattern)'),
'type' => 'line',
],
'require_provisioned_account' => [
'text' => $this->l10n->t('Only allow authentication if an account exists on some other backend. (e.g. LDAP)'),
'type' => 'checkbox',
Expand Down
14 changes: 13 additions & 1 deletion lib/UserBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,14 @@ private function formatUserData($attributes) {
$uidMapping = $this->config->getAppValue('user_saml', $prefix . 'general-uid_mapping');
$result['formatted']['uid'] = '';
if (isset($attributes[$uidMapping])) {
$result['formatted']['uid'] = $attributes[$uidMapping][0];
$uid = $attributes[$uidMapping][0];
$uidRewritePattern = $this->config->getAppValue('user_saml', $prefix . 'general-uid_rewrite_pattern');
$uidRewriteReplacement = $this->config->getAppValue('user_saml', $prefix . 'general-uid_rewrite_replacement');
if (!empty($uidRewritePattern) && !empty($uidRewriteReplacement)) {
$uid = preg_replace($uidRewritePattern, $uidRewriteReplacement, $uid);
}

$result['formatted']['uid'] = $uid;
}

return $result;
Expand All @@ -506,6 +513,11 @@ public function getCurrentUserId() {
} else {
$uid = $samlData[$uidMapping];
}
$uidRewritePattern = $this->config->getAppValue('user_saml', $prefix . 'general-uid_rewrite_pattern');
$uidRewriteReplacement = $this->config->getAppValue('user_saml', $prefix . 'general-uid_rewrite_replacement');
if (!empty($uidRewritePattern) && !empty($uidRewriteReplacement)) {
$uid = preg_replace($uidRewritePattern, $uidRewriteReplacement, $uid);
}
if($this->userExists($uid)) {
$this->session->set('last-password-confirm', strtotime('+4 year', time()));
return $uid;
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/Settings/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ public function formDataProvider() {
'type' => 'line',
'required' => true,
],
'uid_rewrite_pattern' => [
'text' => 'UID rewrite pattern RegEx (PHP preg_replace pattern)',
'type' => 'line',
],
'uid_rewrite_replacement' => [
'text' => 'UID rewrite replacement (PHP preg_replace pattern)',
'type' => 'line',
],
'require_provisioned_account' => [
'text' => 'Only allow authentication if an account exists on some other backend. (e.g. LDAP)',
'type' => 'checkbox',
Expand Down