Skip to content

Commit

Permalink
Merge pull request #19 from formapro/user-refresh
Browse files Browse the repository at this point in the history
[user] refresh user after approved.
  • Loading branch information
makasim committed Mar 22, 2012
2 parents 5edc936 + cc7833c commit 4f4bf9a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
23 changes: 9 additions & 14 deletions DependencyInjection/Security/Factory/OpenIdFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory;

class OpenIdFactory extends AbstractFactory
{
/**
*
* {@inheritDoc}
*/
public function getPosition()
{
return 'form';
return 'pre_auth';
}

/**
*
* {@inheritDoc}
*/
public function getKey()
Expand All @@ -26,7 +25,6 @@ public function getKey()
}

/**
*
* {@inheritDoc}
*/
protected function getListenerId()
Expand All @@ -40,15 +38,12 @@ protected function getListenerId()
*/
protected function createAuthProvider(ContainerBuilder $container, $id, $config, $userProviderId)
{
return 'security.authentication.provider.openid';
}
$providerId = 'security.authentication.provider.openid.'.$id;
$container
->setDefinition($providerId, new DefinitionDecorator('security.authentication.provider.openid'))
->replaceArgument(3, new Reference($userProviderId))
;

/**
*
* {@inheritDoc}
*/
protected function createEntryPoint($container, $id, $config, $defaultEntryPoint)
{
return $defaultEntryPoint;
}
return $providerId;
}
}
7 changes: 5 additions & 2 deletions Resources/config/openid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@

<services>

<service id="security.authentication.provider.openid" class="%fp_openid.security.authentication.provider.class%" >
<service id="security.authentication.provider.openid" class="%fp_openid.security.authentication.provider.class%" public="false">
<argument type="service" id="fp_openid.consumer.provider" />
<argument type="service" id="router" />
<argument type="service" id="fp_openid.security.authentication.token_persister" />
<argument /> <!-- user provider -->
<argument>%fp_openid.security.authentication.provider.parameters%</argument>
</service>

<service
id="security.authentication.listener.openid"
class="%fp_openid.security.authentication.listener.class%"
parent="security.authentication.listener.abstract"
abstract="true">
public="false"
abstract="true"
>
</service>

<service id="fp_openid.consumer.provider" class="%fp_openid.consumer.provider.class%">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;

use Fp\OpenIdBundle\Security\Core\Authentication\Token\TokenPersister;
use Fp\OpenIdBundle\Security\Core\Authentication\Token\OpenIdToken;
Expand All @@ -19,13 +20,21 @@ class OpenIdAuthenticationProvider implements AuthenticationProviderInterface

protected $tokenPersister;

protected $userProvider;

protected $parameters;

public function __construct(ConsumerProvider $consumerProvider, RouterInterface $router, TokenPersister $tokenPersister, array $parameters)
{
public function __construct(
ConsumerProvider $consumerProvider,
RouterInterface $router,
TokenPersister $tokenPersister,
UserProviderInterface $userProvider,
array $parameters
) {
$this->consumerProvider = $consumerProvider;
$this->router = $router;
$this->tokenPersister = $tokenPersister;
$this->userProvider = $userProvider;

$this->parameters = array_merge(array(
'return_route' => null,
Expand Down Expand Up @@ -97,6 +106,8 @@ public function processApproved(OpenIdToken $token)
throw new AuthenticationException('Authentication approving was canceled');
}

$token->setUser($this->userProvider->refreshUser($token->getUser()));

return $token;
}

Expand Down

0 comments on commit 4f4bf9a

Please sign in to comment.