/** * @param string $identity * * @throws \RuntimeException if provider did not provide a user implementation. * * @return \Symfony\Component\Security\Core\User\UserInterface */ protected function getProviderUser($identity, array $attributes) { try { $user = $this->userProvider->loadUserByUsername($identity); } catch (UsernameNotFoundException $e) { if (false == $this->createIfNotExists) { throw $e; } $user = $this->userProvider->createUserFromIdentity($identity, $attributes); } if (false == $user instanceof UserInterface) { throw new \RuntimeException('User provider did not return an implementation of user interface.'); } return $user; }