Skip to content
This repository has been archived by the owner on Feb 15, 2020. It is now read-only.

Commit

Permalink
Add HttpAuthFactory priority
Browse files Browse the repository at this point in the history
  • Loading branch information
fivestar committed Jan 6, 2015
1 parent 301b503 commit a9676c4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
18 changes: 10 additions & 8 deletions Security/AnnotationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Crocos\SecurityBundle\Security\AuthLogic\AuthLogicResolver;
use Crocos\SecurityBundle\Security\Role\RoleManagerResolver;
use Crocos\SecurityBundle\Security\HttpAuth\HttpAuthFactoryInterface;
use SplPriorityQueue;

/**
* AnnotationLoader.
Expand Down Expand Up @@ -36,9 +37,9 @@ class AnnotationLoader
protected $roleManagerResolver;

/**
* @var HttpAuthFactoryInterface
* @var SplPriorityQueue
*/
protected $httpAuthFactory;
protected $httpAuthFactories;

/**
* @var ParameterResolverInterface
Expand All @@ -48,16 +49,16 @@ class AnnotationLoader
/**
* Constructor.
*
* @param Reader $reader Annotation reader
* @param AuthLogicResolver $resolver
* @param RoleManagerResolver $roleManagerResolver
* @param HttpAuthFactoryInterface $httpAuthFactory
* @param Reader $reader Annotation reader
* @param AuthLogicResolver $resolver
* @param RoleManagerResolver $roleManagerResolver
*/
public function __construct(Reader $reader, AuthLogicResolver $resolver, RoleManagerResolver $roleManagerResolver)
{
$this->reader = $reader;
$this->resolver = $resolver;
$this->roleManagerResolver = $roleManagerResolver;
$this->httpAuthFactories = new SplPriorityQueue();
}

/**
Expand All @@ -67,7 +68,7 @@ public function __construct(Reader $reader, AuthLogicResolver $resolver, RoleMan
*/
public function addHttpAuthFactory(HttpAuthFactoryInterface $httpAuthFactory)
{
$this->httpAuthFactories[$httpAuthFactory->getName()] = $httpAuthFactory;
$this->httpAuthFactories->insert($httpAuthFactory, $httpAuthFactory->getPriority());

SecureConfig::extendAttrs([$httpAuthFactory->getName() => null]);
}
Expand Down Expand Up @@ -221,7 +222,8 @@ protected function loadHttpAuth(SecurityContext $context, SecureConfig $annotati
return;
}

foreach ($this->httpAuthFactories as $name => $httpAuthFactory) {
foreach ($this->httpAuthFactories as $httpAuthFactory) {
$name = $httpAuthFactory->getName();
$value = $annotation->{$name}();
if ($value === null) {
continue;
Expand Down
8 changes: 8 additions & 0 deletions Security/HttpAuth/BasicAuthFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public function getName()
return 'basic';
}

/**
* {@ihneritdoc}
*/
public function getPriority()
{
return HttpAuthFactoryInterface::PRIORITY_HIGH;
}

/**
* {@inheritDoc}
*/
Expand Down
11 changes: 10 additions & 1 deletion Security/HttpAuth/HttpAuthFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@
*/
interface HttpAuthFactoryInterface
{
const PRIORITY_HIGH = 20;
const PRIORITY_MID = 10;
const PRIORITY_LOW = 0;

/**
* @return string
*/
public function getName();
public function getname();

/**
* @return integer
*/
public function getPriority();

/**
* @param string $value
Expand Down

0 comments on commit a9676c4

Please sign in to comment.