/**
* Retrieves an existing user by the given username
*
* @param string $username The username
* @param string $authenticationProviderName Name of the authentication provider to use. Example: "Typo3BackendProvider"
* @return User The user, or null if the user does not exist
* @throws Exception
* @api
*/
public function getUser($username, $authenticationProviderName = null)
{
if ($authenticationProviderName !== null && isset($this->runtimeUserCache['a_' . $authenticationProviderName][$username])) {
return $this->runtimeUserCache['a_' . $authenticationProviderName][$username];
} elseif (isset($this->runtimeUserCache['u_' . $username])) {
return $this->runtimeUserCache['u_' . $username];
}
$account = $this->accountRepository->findByAccountIdentifierAndAuthenticationProviderName($username, $authenticationProviderName ?: $this->defaultAuthenticationProviderName);
if (!$account instanceof Account) {
return null;
}
$user = $this->partyService->getAssignedPartyOfAccount($account);
if (!$user instanceof User) {
throw new Exception(sprintf('Unexpected user type "%s". An account with the identifier "%s" exists, but the corresponding party is not a Neos User.', get_class($user), $username), 1422270948);
}
if ($authenticationProviderName !== null) {
if (!isset($this->runtimeUserCache['a_' . $authenticationProviderName])) {
$this->runtimeUserCache['a_' . $authenticationProviderName] = [];
}
$this->runtimeUserCache['a_' . $authenticationProviderName][$username] = $user;
} else {
$this->runtimeUserCache['u_' . $username] = $user;
}
return $user;
}