-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
override TokenBasedRememberMeServices and authenticate user also in z…
…end_auth
- Loading branch information
1 parent
8fecf4d
commit e4b97fa
Showing
4 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
newscoop/src/Newscoop/NewscoopBundle/Security/Http/Authentication/InteractiveLogin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/** | ||
* @package Newscoop\NewscoopBundle | ||
* @author Paweł Mikołajczuk <[email protected]> | ||
* @copyright 2015 Sourcefabric o.p.s. | ||
* @license http://www.gnu.org/licenses/gpl-3.0.txt | ||
*/ | ||
|
||
namespace Newscoop\NewscoopBundle\Security\Http\Authentication; | ||
|
||
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; | ||
use Symfony\Component\Security\Core\SecurityContext; | ||
use Symfony\Component\Security\Http\RememberMe\TokenBasedRememberMeServices; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* Temporary class for remember_me token based authentication | ||
*/ | ||
class InteractiveDoctrineAuthService implements \Zend_Auth_Adapter_Interface | ||
{ | ||
public $user = null; | ||
|
||
/** | ||
* Perform authentication attempt | ||
* | ||
* @return \Zend_Auth_Result | ||
*/ | ||
public function authenticate() | ||
{ | ||
if (empty($this->user)) { | ||
return new \Zend_Auth_Result(\Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, NULL); | ||
} | ||
|
||
if (!$this->user->isActive()) { | ||
return new \Zend_Auth_Result(\Zend_Auth_Result::FAILURE_UNCATEGORIZED, NULL); | ||
} | ||
|
||
return new \Zend_Auth_Result(\Zend_Auth_Result::SUCCESS, $this->user->getId()); | ||
} | ||
} | ||
|
||
/** | ||
* Custom login listener. | ||
*/ | ||
class InteractiveLogin extends TokenBasedRememberMeServices | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function processAutoLoginCookie(array $cookieParts, Request $request) | ||
{ | ||
$user = parent::processAutoLoginCookie($cookieParts, $request); | ||
|
||
$zendAuth = \Zend_Auth::getInstance(); | ||
|
||
$authAdapter = new InteractiveDoctrineAuthService(); | ||
$authAdapter->user = $user; | ||
|
||
$zendAuth->authenticate($authAdapter); | ||
|
||
return $user; | ||
} | ||
} |