2013-03-09 3 views
4

심포니 2와 특별한 종류의 URL로 자동 로그인을 시도하고 있습니다. 그냥 described here과 같습니다.심포니 2 URL을 통한 자동 로그인

하지만 symfony2 디버그 도구 모음을 사용할 때 "인증되지 않았습니다"라는 메시지가 나타납니다. 하지만 세션이 있는데 사용자 개체가 있는데 모두 잘 작동하는 것 같습니다. 왜 디버그 툴바는 이것을 말하고 있습니까?

zadbuchy가 설명하는 방법에 문제가 있습니까? symfony 2.1.6을 사용하고 있습니다.

편집 : 이것이 '안전한'방법으로 로그인 할 수 없다는 것을 알고 있습니다. @Bart에게 감사드립니다.)하지만 symfony2가 로그인을 올바르게 인식하지 못하는 이유가 궁금합니다.

내 코드는 다음과 같습니다

$firewall = "support_secured_area"; 
$token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles()); 
$this->get('security.context')->setToken($token); 
$session = $this->get('session'); 
$session->set('_security_'.$firewall, serialize($token)); 

// Fire the login event (Suggestion from the answer, but unfortunately it doesn't work :(). 
$event = new InteractiveLoginEvent($this->getRequest(), $token); 
$this->get("event_dispatcher")->dispatch("security.interactive_login", $event); 
+2

사용자 인증에 매우 안전한 방법이 아닌 것으로 보입니다. – Bart

+0

그 말 주셔서 감사합니다. 나는 그것을 설계하는 동안 그것을 고려했다. 보안 문제는 알고 있지만 대안 (전자 메일 쓰기)은 똑같이 안전합니다 (S/MIME 및 GnuPG가 적용되지 않기 때문에). 주요 용도는 티켓을 요청하고 티켓 상태를 보는 간단한 방법을 제공하는 것입니다. 그래서 나는 괜찮다고 생각한다. –

+0

전혀 사실이 아닙니다. 전자 메일은 대부분 일회성 이벤트입니다. 사용자는 암호를 변경할 수 있어야하며 우편으로 보낼 경우 암호를 변경할 수 있어야합니다. 고정 URL에서는 불가능합니다. URL을 변경할 수는 있지만 사용자 이름만으로 인증하는 것만 큼 안전합니다. – Bart

답변

6

당신은 사용자가 로그인 할의 InteractiveLoginEvent 일이 필요 나는 몇 년 위의 해결책을 적용

// Here, "public" is the name of the firewall in your security.yml 
$token = new UsernamePasswordToken($user, $user->getPassword(), "public", $user->getRoles()); 
$this->get("security.context")->setToken($token); 

// Fire the login event 
$event = new InteractiveLoginEvent($request, $token); 
$this->get("event_dispatcher")->dispatch("security.interactive_login", $event); 
+0

'$ user'은 어디에서 왔습니까? – Henry

1
$token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles()); 
$this->get('security.context')->setToken($token); 
$session = $this->get('session'); 
$session->set('_security_'.$firewall, serialize($token)); 

우리. 프로젝트. 하나는 효과가 있었지만 다른 것은 효과가 없었습니다.

마지막 해결책은 아래 줄에 firewall_name 대신 security_context_name을 사용하고 있습니다. 그런 다음 모든 프로젝트에서 작업했습니다.

$session->set('_security_'.$security_context_name, serialize($token)); 

제 동료 중 한 명에게 감사드립니다.