2016-11-16 4 views
0

Lexik 번들에 대한 UserProvider가 있고 세션을 통해 사용자가 존재하는지 확인하지만 특정 요청을 할 때 세션이 누군가가 알고있는 값을 잃어 버리면 문제가 발생합니다.Symfony 서비스에서 세션을 잃었습니다.

서비스

app.user_provider: 
    class: ApiBundle\Security\Userprovider 
    arguments: ["@session","@switchconnection","@doctrine.orm.entity_manager" , "@doctrine.dbal.default_connection" , "@doctrine"] 

내 제공

나는 또한 VAR/세션/dev에 폴더에 2 Phpsession 거의 동일와 세션 레지스터가 있음을 확인
use Symfony\Component\Security\Core\User\UserProviderInterface; 
use Symfony\Component\Security\Core\User\UserInterface; 
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; 
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; 
use ApiBundle\Entity\Utilizador; 
use Symfony\Component\HttpFoundation\Session\Session;  
public function __construct(Session $session,$switchconnection ,\Doctrine\ORM\EntityManager $em , \Doctrine\DBAL\Connection $dbalConnection , \Doctrine\Bundle\DoctrineBundle\Registry $doctrine) { 
    $this->session = $session; 
    $this->switchconnection = $switchconnection; 
    $this->em = $em; 
    $this->connection = $dbalConnection; 
    $this->doctrine = $doctrine; 
    } 

    public function loadUserByUsername($username) 
    { 
    if($this->session->get("currentuser") == $username){  
     $this->switchconnection->switchDatabase($this->session->get("dbconnection"), $this->connection , $this->doctrine); 
     $conn = $this->em->getConnection(); 
     $stmt = $conn->prepare("....."); 
     $stmt->bindParam(1, $username); 
     $stmt->execute(); 
     $results = $stmt->fetchAll(); 
     $count = count($results); 
      if($count != 0) 
      { 
       $user= new Utilizador(); 
       $user->setUsername($results[0]['username']); 
       $user->setEmail($results[0]['email']); 
       return $user; 
      } 
      } 
    throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username)); 
    } 

.

enter image description here

업데이트 이것은 단지 웹킷 브라우저에서 일어나는 일

중요 정보

답변

0

ApiBundle\Security\Userprovidersession 요소를 포함하십시오.

use Symfony\Component\HttpFoundation\Session\Session; 

세션 구성 요소를 추가하는 것을 잊어 버린 것 같습니다.

업데이트-1 서비스를 전달하여

사용자 service_container. 나를 위해 그것의 일 벌금.

services.yml

app.user_provider: 
    class: ApiBundle\Security\Userprovider 
    arguments: ["@service_container", "@session","@switchconnection","@doctrine.orm.entity_manager" , "@doctrine.dbal.default_connection" , "@doctrine"] 

제공

protected $container; 
protected $session; 

public function __construct($container, Session $session,$switchconnection ,\Doctrine\ORM\EntityManager $em , \Doctrine\DBAL\Connection $dbalConnection , \Doctrine\Bundle\DoctrineBundle\Registry $doctrine) { 

    $this->container = $container; 
    $this->session = $container->get('session'); 

} 
+0

내가 확인 질문 – user26776

+0

의 수입을 입력하지 않은 죄송 추가했습니다. 나는 지금 pls 업데이트 답을 가지고있다. –

+0

고맙지 만 작동하지 않습니다. – user26776