Skip to content

Commit

Permalink
Refactor security services
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jun 27, 2011
1 parent 2f3b242 commit a65ccb5
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 103 deletions.
15 changes: 12 additions & 3 deletions Deleter/Deleter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace Ornicar\MessageBundle\Deleter;

use Ornicar\MessageBundle\Authorizer\AuthorizerInterface;
use Ornicar\MessageBundle\Security\AuthorizerInterface;
use Ornicar\MessageBundle\Model\ThreadInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Ornicar\MessageBundle\Security\ParticipantProviderInterface;

/**
* Marks threads as deleted
Expand All @@ -20,9 +21,17 @@ class Deleter implements ReaderInterface
*/
protected $authorizer;

public function __construct(AuthorizerInterface $authorizer)
/**
* The participant provider instance
*
* @var ParticipantProviderInterface
*/
protected $participantProvider;

public function __construct(AuthorizerInterface $authorizer, ParticipantProviderInterface $participantProvider)
{
$this->authorizer = $authorizer;
$this->participantProvider = $participantProvider;
}

/**
Expand Down Expand Up @@ -58,6 +67,6 @@ public function markAsUndeleted(ThreadInterface $thread)
*/
protected function getAuthenticatedParticipant()
{
return $this->authorizer->getAuthenticatedParticipant();
return $this->participantProvider->getAuthenticatedParticipant();
}
}
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function getConfigTreeBuilder()
->scalarNode('sender')->defaultValue('ornicar_message.sender.default')->cannotBeEmpty()->end()
->scalarNode('composer')->defaultValue('ornicar_message.composer.default')->cannotBeEmpty()->end()
->scalarNode('provider')->defaultValue('ornicar_message.provider.default')->cannotBeEmpty()->end()
->scalarNode('participant_provider')->defaultValue('ornicar_message.participant_provider.default')->cannotBeEmpty()->end()
->scalarNode('authorizer')->defaultValue('ornicar_message.authorizer.default')->cannotBeEmpty()->end()
->scalarNode('message_reader')->defaultValue('ornicar_message.message_reader.default')->cannotBeEmpty()->end()
->scalarNode('thread_reader')->defaultValue('ornicar_message.thread_reader.default')->cannotBeEmpty()->end()
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/OrnicarMessageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function load(array $configs, ContainerBuilder $container)
$container->setAlias('ornicar_message.sender', $config['sender']);
$container->setAlias('ornicar_message.composer', $config['composer']);
$container->setAlias('ornicar_message.provider', $config['provider']);
$container->setAlias('ornicar_message.participant_provider', $config['participant_provider']);
$container->setAlias('ornicar_message.authorizer', $config['authorizer']);
$container->setAlias('ornicar_message.message_reader', $config['message_reader']);
$container->setAlias('ornicar_message.thread_reader', $config['thread_reader']);
Expand Down
10 changes: 5 additions & 5 deletions FormHandler/AbstractMessageFormHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
use Symfony\Component\HttpFoundation\Request;
use Ornicar\MessageBundle\Composer\ComposerInterface;
use Ornicar\MessageBundle\FormModel\AbstractMessage;
use Ornicar\MessageBundle\Authorizer\AuthorizerInterface;
use Ornicar\MessageBundle\Security\ParticipantProviderInterface;
use Ornicar\MessageBundle\Model\ParticipantInterface;

abstract class AbstractMessageFormHandler
{
protected $form;
protected $request;
protected $composer;
protected $authorizer;
protected $participantProvider;

public function __construct(Request $request, ComposerInterface $composer, AuthorizerInterface $authorizer)
public function __construct(Request $request, ComposerInterface $composer, ParticipantProviderInterface $participantProvider)
{
$this->request = $request;
$this->composer = $composer;
$this->authorizer = $authorizer;
$this->participantProvider = $participantProvider;
}

/**
Expand Down Expand Up @@ -58,6 +58,6 @@ abstract protected function composeAndSend(AbstractMessage $message);
*/
public function getAuthenticatedParticipant()
{
return $this->authorizer->getAuthenticatedParticipant();
return $this->participantProvider->getAuthenticatedParticipant();
}
}
31 changes: 20 additions & 11 deletions Provider/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Ornicar\MessageBundle\ModelManager\ThreadManagerInterface;
use Ornicar\MessageBundle\Authorizer\AuthorizerInterface;
use Ornicar\MessageBundle\Security\AuthorizerInterface;
use Ornicar\MessageBundle\Reader\ReaderInterface;
use Ornicar\MessageBundle\Security\ParticipantProviderInterface;

/**
* Provides threads for the current authenticated user
Expand All @@ -15,13 +16,6 @@
*/
class Provider implements ProviderInterface
{
/**
* The authorizer manager
*
* @var authorizerInterface
*/
protected $authorizer;

/**
* The thread manager
*
Expand All @@ -36,11 +30,26 @@ class Provider implements ProviderInterface
*/
protected $threadReader;

public function __construct(ThreadManagerInterface $threadManager, AuthorizerInterface $authorizer, ReaderInterface $threadReader)
/**
* The authorizer manager
*
* @var authorizerInterface
*/
protected $authorizer;

/**
* The participant provider instance
*
* @var ParticipantProviderInterface
*/
protected $participantProvider;

public function __construct(ThreadManagerInterface $threadManager, ReaderInterface $threadReader, AuthorizerInterface $authorizer, ParticipantProviderInterface $participantProvider)
{
$this->authorizer = $authorizer;
$this->threadManager = $threadManager;
$this->threadReader = $threadReader;
$this->authorizer = $authorizer;
$this->participantProvider = $participantProvider;
}

/**
Expand Down Expand Up @@ -98,6 +107,6 @@ public function getThread($threadId)
*/
protected function getAuthenticatedParticipant()
{
return $this->authorizer->getAuthenticatedParticipant();
return $this->participantProvider->getAuthenticatedParticipant();
}
}
14 changes: 7 additions & 7 deletions Reader/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Ornicar\MessageBundle\Reader;

use Ornicar\MessageBundle\Authorizer\AuthorizerInterface;
use Ornicar\MessageBundle\Security\ParticipantProviderInterface;
use Ornicar\MessageBundle\Model\ReadableInterface;
use Ornicar\MessageBundle\ModelManager\ReadableManagerInterface;

Expand All @@ -14,11 +14,11 @@
class Reader implements ReaderInterface
{
/**
* The authorizer instance
* The participantProvider instance
*
* @var AuthorizerInterface
* @var ParticipantProviderInterface
*/
protected $authorizer;
protected $participantProvider;

/**
* The readable manager
Expand All @@ -27,9 +27,9 @@ class Reader implements ReaderInterface
*/
protected $readableManager;

public function __construct(AuthorizerInterface $authorizer, ReadableManagerInterface $readableManager)
public function __construct(ParticipantProviderInterface $participantProvider, ReadableManagerInterface $readableManager)
{
$this->authorizer = $authorizer;
$this->participantProvider = $participantProvider;
$this->readableManager = $readableManager;
}

Expand Down Expand Up @@ -60,6 +60,6 @@ public function markAsUnread(ReadableInterface $readable)
*/
protected function getAuthenticatedParticipant()
{
return $this->authorizer->getAuthenticatedParticipant();
return $this->participantProvider->getAuthenticatedParticipant();
}
}
18 changes: 12 additions & 6 deletions Resources/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,38 @@
<argument type="service" id="ornicar_message.sender" />
</service>

<service id="ornicar_message.authorizer.default" class="Ornicar\MessageBundle\Authorizer\Authorizer" public="false">
<service id="ornicar_message.participant_provider.default" class="Ornicar\MessageBundle\Security\ParticipantProvider" public="false">
<argument type="service" id="security.context" />
</service>

<service id="ornicar_message.authorizer.default" class="Ornicar\MessageBundle\Security\Authorizer" public="false">
<argument type="service" id="ornicar_message.participant_provider" />
</service>

<service id="ornicar_message.provider.default" class="Ornicar\MessageBundle\Provider\Provider" public="false">
<argument type="service" id="ornicar_message.thread_manager" />
<argument type="service" id="ornicar_message.authorizer" />
<argument type="service" id="ornicar_message.thread_reader" />
<argument type="service" id="ornicar_message.authorizer" />
<argument type="service" id="ornicar_message.participant_provider" />
</service>

<service id="ornicar_message.message_reader.default" class="Ornicar\MessageBundle\Reader\Reader" public="false">
<argument type="service" id="ornicar_message.authorizer" />
<argument type="service" id="ornicar_message.participant_provider" />
<argument type="service" id="ornicar_message.message_manager" />
</service>

<service id="ornicar_message.thread_reader.default" class="Ornicar\MessageBundle\Reader\Reader" public="false">
<argument type="service" id="ornicar_message.authorizer" />
<argument type="service" id="ornicar_message.participant_provider" />
<argument type="service" id="ornicar_message.thread_manager" />
</service>

<service id="ornicar_message.deleter.default" class="Ornicar\MessageBundle\Deleter\Deleter" public="false">
<argument type="service" id="ornicar_message.authorizer" />
<argument type="service" id="ornicar_message.participant_provider" />
</service>

<service id="ornicar_message.twig_extension" class="Ornicar\MessageBundle\Twig\Extension\MessageExtension" public="false">
<argument type="service" id="ornicar_message.authorizer" />
<argument type="service" id="ornicar_message.participant_provider" />
<tag name="twig.extension" alias="ornicar_message" />
</service>

Expand All @@ -51,7 +57,7 @@
</service>

<service id="ornicar_message.search_finder.default" class="Ornicar\MessageBundle\Search\Finder" public="true">
<argument type="service" id="ornicar_message.authorizer" />
<argument type="service" id="ornicar_message.participant_provider" />
<argument type="service" id="ornicar_message.thread_manager" />
</service>

Expand Down
4 changes: 2 additions & 2 deletions Resources/config/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
<service id="ornicar_message.new_thread_form.handler.default" class="Ornicar\MessageBundle\FormHandler\NewThreadMessageFormHandler" scope="request" public="false">
<argument type="service" id="request" />
<argument type="service" id="ornicar_message.composer" />
<argument type="service" id="ornicar_message.authorizer" />
<argument type="service" id="ornicar_message.participant_provider" />
</service>

<service id="ornicar_message.reply_form.handler.default" class="Ornicar\MessageBundle\FormHandler\ReplyMessageFormHandler" scope="request" public="false">
<argument type="service" id="request" />
<argument type="service" id="ornicar_message.composer" />
<argument type="service" id="ornicar_message.authorizer" />
<argument type="service" id="ornicar_message.participant_provider" />
</service>

<service id="ornicar_message.username_to_user_transformer" class="Ornicar\MessageBundle\DataTransformer\UsernameToUserTransformer" public="false">
Expand Down
47 changes: 24 additions & 23 deletions Resources/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -281,32 +281,33 @@ All configuration options are listed below::
# app/config/config.yml

ornicar_message
db_driver: mongodb
thread_class: Acme\MessageBundle\Document\Thread
message_class: Acme\MessageBundle\Document\Message
message_manager: ornicar_message.message_manager # See ModelManager\MessageManagerInterface
thread_manager: ornicar_message.thread_manager # See ModelManager\ThreadManagerInterface
sender: ornicar_message.sender # See Sender\SenderInterface
composer: ornicar_message.composer # See Composer\ComposerInterface
provider: ornicar_message.provider # See Provider\ProviderInterface
authorizer: ornicar_message.authorizer # See Authorizer\AuthorizerInterface
message_reader: ornicar_message.message_reader # See Reader\ReaderInterface
thread_reader: ornicar_message.thread_reader # See Reader\ReaderInterface
deleter: ornicar_message.deleter # See Deleter\DeleterInterface
db_driver: mongodb
thread_class: Acme\MessageBundle\Document\Thread
message_class: Acme\MessageBundle\Document\Message
message_manager: ornicar_message.message_manager # See ModelManager\MessageManagerInterface
thread_manager: ornicar_message.thread_manager # See ModelManager\ThreadManagerInterface
sender: ornicar_message.sender # See Sender\SenderInterface
composer: ornicar_message.composer # See Composer\ComposerInterface
provider: ornicar_message.provider # See Provider\ProviderInterface
participant_provider: ornicar_message.participant_provider # See Security\ParticipantProviderInterface
authorizer: ornicar_message.authorizer # See Security\AuthorizerInterface
message_reader: ornicar_message.message_reader # See Reader\ReaderInterface
thread_reader: ornicar_message.thread_reader # See Reader\ReaderInterface
deleter: ornicar_message.deleter # See Deleter\DeleterInterface
search:
finder: ornicar_message.search_finder # See Finder\FinderInterface
query_factory: ornicar_message.search_query_factory # See Finder\QueryFactoryInterface
query_parameter: 'q' # Request query parameter containing the term
finder: ornicar_message.search_finder # See Finder\FinderInterface
query_factory: ornicar_message.search_query_factory # See Finder\QueryFactoryInterface
query_parameter: 'q' # Request query parameter containing the term
new_thread_form:
factory: ornicar_message.new_thread_form.factory # See FormFactory\NewThreadMessageFormFactory
type: ornicar_message.new_thread_form.type # See FormType\NewThreadMessageFormType
handler: ornicar_message.new_thread_form.handler # See FormHandler\NewThreadMessageFormHandler
name: message
factory: ornicar_message.new_thread_form.factory # See FormFactory\NewThreadMessageFormFactory
type: ornicar_message.new_thread_form.type # See FormType\NewThreadMessageFormType
handler: ornicar_message.new_thread_form.handler # See FormHandler\NewThreadMessageFormHandler
name: message
reply_form:
factory: ornicar_message.reply_form.factory # See FormFactory\ReplyMessageFormFactory
type: ornicar_message.reply_form.type # See FormType\ReplyMessageFormType
handler: ornicar_message.reply_form.handler # See FormHandler\ReplyMessageFormHandler
name: message
factory: ornicar_message.reply_form.factory # See FormFactory\ReplyMessageFormFactory
type: ornicar_message.reply_form.type # See FormType\ReplyMessageFormType
handler: ornicar_message.reply_form.handler # See FormHandler\ReplyMessageFormHandler
name: message

Implement a new persistence backend
===================================
Expand Down
14 changes: 7 additions & 7 deletions Search/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Ornicar\MessageBundle\Search;

use Ornicar\MessageBundle\ModelManager\ThreadManagerInterface;
use Ornicar\MessageBundle\Authorizer\AuthorizerInterface;
use Ornicar\MessageBundle\Security\ParticipantProviderInterface;

/**
* Finds threads of a participant, matching a given query
Expand All @@ -13,11 +13,11 @@
class Finder implements FinderInterface
{
/**
* The authorizer instance
* The participant provider instance
*
* @var AuthorizerInterface
* @var ParticipantProviderInterface
*/
protected $authorizer;
protected $participantProvider;

/**
* The thread manager
Expand All @@ -26,9 +26,9 @@ class Finder implements FinderInterface
*/
protected $threadManager;

public function __construct(AuthorizerInterface $authorizer, ThreadManagerInterface $threadManager)
public function __construct(ParticipantProviderInterface $participantProvider, ThreadManagerInterface $threadManager)
{
$this->authorizer = $authorizer;
$this->participantProvider = $participantProvider;
$this->threadManager = $threadManager;
}

Expand Down Expand Up @@ -61,6 +61,6 @@ public function getQueryBuilder(Query $query)
*/
protected function getAuthenticatedParticipant()
{
return $this->authorizer->getAuthenticatedParticipant();
return $this->participantProvider->getAuthenticatedParticipant();
}
}
Loading

0 comments on commit a65ccb5

Please sign in to comment.