Skip to content
Merged
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: 3 additions & 3 deletions lib/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public function getEffectiveUid(): string {
}
$this->assertIsInitialized();
try {
$uid = $this->extractSamlUserId();
$uid = $this->testEncodedObjectGUID($uid);
$uid = $this->userResolver->findExistingUserId($uid, true);
$providedUid = $this->extractSamlUserId();
$uid = $this->testEncodedObjectGUID($providedUid);
$uid = $this->userResolver->findExistingUserId($uid, true, $providedUid !== $uid);
$this->uid = $uid;
} catch (NoUserFoundException) {
return '';
Expand Down
44 changes: 42 additions & 2 deletions lib/UserResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ public function __construct(IUserManager $userManager) {
/**
* @throws NoUserFoundException
*/
public function findExistingUserId(string $rawUidCandidate, bool $force = false): string {
public function findExistingUserId(string $rawUidCandidate, bool $force = false, bool $isActiveDirectory = false): string {
if ($force) {
$this->ensureUser($rawUidCandidate);
if ($isActiveDirectory) {
$this->ensureUser($this->formatGuid2ForFilterUser($rawUidCandidate));
} else {
$this->ensureUser($rawUidCandidate);
}
}
if ($this->userManager->userExists($rawUidCandidate)) {
return $rawUidCandidate;
Expand All @@ -41,6 +45,42 @@ public function findExistingUserId(string $rawUidCandidate, bool $force = false)
throw new NoUserFoundException('User' . $rawUidCandidate . ' not valid or not found');
}

/**
* @see \OCA\User_LDAP\Access::formatGuid2ForFilterUser
*/
private function formatGuid2ForFilterUser(string $guid): string {
$blocks = explode('-', $guid);
if (count($blocks) !== 5) {
/*
* Why not throw an Exception instead? This method is a utility
* called only when trying to figure out whether a "missing" known
* LDAP user was or was not renamed on the LDAP server. And this
* even on the use case that a reverse lookup is needed (UUID known,
* not DN), i.e. when finding users (search dialog, users page,
* login, …) this will not be fired. This occurs only if shares from
* a users are supposed to be mounted who cannot be found. Throwing
* an exception here would kill the experience for a valid, acting
* user. Instead we write a log message.
*/
\OCP\Log\logger()->info(
'Passed string does not resemble a valid GUID. Known UUID '
. '({uuid}) probably does not match UUID configuration.',
['app' => 'user_saml', 'uuid' => $guid]
);
return $guid;
}
for ($i = 0; $i < 3; $i++) {
$pairs = str_split($blocks[$i], 2);
$pairs = array_reverse($pairs);
$blocks[$i] = implode('', $pairs);
}
for ($i = 0; $i < 5; $i++) {
$pairs = str_split($blocks[$i], 2);
$blocks[$i] = '\\' . implode('\\', $pairs);
}
return implode('', $blocks);
}

/**
* @throws NoUserFoundException
*/
Expand Down
Loading