forked from formapro/FpOpenIdBundle
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request formapro#11 from formapro/trust-root-from-request
Trust root from request
- Loading branch information
Showing
10 changed files
with
286 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
namespace Fp\OpenIdBundle\Consumer; | ||
|
||
class ConsumerProvider | ||
{ | ||
protected $consumers = array(); | ||
|
||
protected $defaultConsumer; | ||
|
||
public function addConsumer(ConsumerInterface $consumer) | ||
{ | ||
$this->consumers[] = $consumer; | ||
} | ||
|
||
public function setDefault(ConsumerInterface $consumer) | ||
{ | ||
$this->defaultConsumer = $consumer; | ||
} | ||
|
||
/** | ||
* @throws \InvalidArgumentException | ||
* | ||
* @param string $identifier | ||
* | ||
* @return \Fp\OpenIdBundle\Consumer\ConsumerInterface | ||
*/ | ||
public function provide($identifier) | ||
{ | ||
foreach ($this->consumers as $consumer) { | ||
if ($consumer->supports($identifier)) { | ||
return $consumer; | ||
} | ||
} | ||
|
||
if ($this->defaultConsumer && $this->defaultConsumer->supports($identifier)) { | ||
return $this->defaultConsumer; | ||
} | ||
|
||
throw new \InvalidArgumentException(sprintf('Cannot provide consumer for the identifier: %s', $identifier)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
namespace Fp\OpenIdBundle\Event; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\EventDispatcher\Event; | ||
|
||
use Fp\OpenIdBundle\Security\Core\Authentication\Token\OpenIdToken; | ||
|
||
class AuthenticationEvent extends Event | ||
{ | ||
/** | ||
* @var Request | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* @var OpenIdToken | ||
*/ | ||
protected $token; | ||
|
||
public function __construct(Request $request, OpenIdToken $token) | ||
{ | ||
$this->token = $token; | ||
$this->request = $request; | ||
} | ||
|
||
/** | ||
* @return \Fp\OpenIdBundle\Security\Core\Authentication\Token\OpenIdToken | ||
*/ | ||
public function getToken() | ||
{ | ||
return $this->token; | ||
} | ||
|
||
/** | ||
* @return \Symfony\Component\HttpFoundation\Request | ||
*/ | ||
public function getRequest() | ||
{ | ||
return $this->request; | ||
} | ||
} |
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,46 @@ | ||
<?php | ||
namespace Fp\OpenIdBundle\EventListener; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
use Fp\OpenIdBundle\Event\AuthenticationEvent; | ||
use Fp\OpenIdBundle\Consumer\ConsumerInterface; | ||
|
||
class TrustRootListener implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $consumers = array(); | ||
|
||
/** | ||
* @param \Fp\OpenIdBundle\Consumer\ConsumerInterface $consumer | ||
* | ||
* @return void | ||
*/ | ||
public function addConsumer(ConsumerInterface $consumer) | ||
{ | ||
$this->consumers[] = $consumer; | ||
} | ||
|
||
/** | ||
* @param \Fp\OpenIdBundle\Event\AuthenticationEvent $event | ||
* | ||
* @return void | ||
*/ | ||
public function onOpenidBeforeAuthentication(AuthenticationEvent $event) | ||
{ | ||
$request = $event->getRequest(); | ||
foreach ($this->consumers as $consumer) { | ||
$consumer->changeTrustRoot($request->getHttpHost()); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
static function getSubscribedEvents() | ||
{ | ||
return array('fp_openid.before_authentication' => 'onOpenidBeforeAuthentication'); | ||
} | ||
} |
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
Oops, something went wrong.