/**
  * @param ConnectionInterface $connection
  *
  * @return false|string|\Symfony\Component\Security\Core\User\UserInterface
  */
 public function getClient(ConnectionInterface $connection)
 {
     $storageId = $this->clientStorage->getStorageId($connection);
     try {
         return $this->clientStorage->getClient($storageId);
     } catch (ClientNotFoundException $e) {
         //User is gone due to ttl
         $this->authenticationProvider->authenticate($connection);
         return $this->getClient($connection);
     }
 }
 /**
  * @param ConnectionInterface        $conn
  * @param \Ratchet\Wamp\Topic|string $topic
  */
 public function onUnSubscribe(ConnectionInterface $conn, $topic)
 {
     $user = $this->clientStorage->getClient($conn->WAMP->clientStorageId);
     $username = $user instanceof UserInterface ? $user->getUsername() : $user;
     $this->logger->info(sprintf('User %s unsubscribed to %s', $username, $topic->getId()));
     $wampRequest = $this->wampRouter->match($topic);
     $this->topicDispatcher->onUnSubscribe($conn, $topic, $wampRequest);
 }
 /**
  * @param TokenInterface $token
  */
 public function authenticate(ConnectionInterface $conn)
 {
     if (1 === count($this->firewalls) && 'ws_firewall' === $this->firewalls[0]) {
         $this->logger->warning(sprintf('User firewall is not configured, we have set %s by default', $this->firewalls[0]));
     }
     $loggerContext = array('connection_id' => $conn->resourceId, 'session_id' => $conn->WAMP->sessionId);
     $token = $this->getToken($conn);
     $user = $token->getUser();
     $username = $user instanceof UserInterface ? $user->getUsername() : $user;
     try {
         $identifier = $this->clientStorage->getStorageId($conn, $username);
     } catch (StorageException $e) {
         $this->logger->error($e->getMessage(), $loggerContext);
         throw $e;
     }
     $loggerContext['storage_id'] = $identifier;
     $this->clientStorage->addClient($identifier, $token->getUser());
     $conn->WAMP->clientStorageId = $identifier;
     $this->logger->info(sprintf('%s connected [%]', $username, $user instanceof UserInterface ? implode(', ', $user->getRoles()) : array()), $loggerContext);
     return $token;
 }
 /**
  * @param ConnectionInterface $connection
  *
  * @return false|string|\Symfony\Component\Security\Core\User\UserInterface
  */
 public function getCurrentUser(ConnectionInterface $connection)
 {
     @trigger_error('User ClientManipulator service instead, will be remove in 2.0', E_USER_DEPRECATED);
     return $this->clientStorage->getClient($this->clientStorage->getStorageId($connection));
 }
 /**
  * @param ConnectionInterface $connection
  *
  * @return false|string|\Symfony\Component\Security\Core\User\UserInterface
  */
 public function getCurrentUser(ConnectionInterface $connection)
 {
     return $this->clientStorage->getClient($this->clientStorage->getStorageId($connection));
 }