-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow being linked to multiple user types * Fixed Archive command
- Loading branch information
1 parent
418af61
commit b9b6fe9
Showing
16 changed files
with
248 additions
and
218 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,41 +3,26 @@ | |
namespace Yokai\SecurityTokenBundle\Command; | ||
|
||
use DateTime; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Helper\QuestionHelper; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Yokai\SecurityTokenBundle\Archive\ArchivistInterface; | ||
|
||
/** | ||
* @author Yann Eugoné <[email protected]> | ||
*/ | ||
class ArchiveTokenCommand extends Command | ||
class ArchiveTokenCommand extends ContainerAwareCommand | ||
{ | ||
/** | ||
* @var ContainerInterface | ||
*/ | ||
private $container; | ||
|
||
/** | ||
* @param ContainerInterface $container | ||
*/ | ||
public function __construct(ContainerInterface $container) | ||
{ | ||
$this->container = $container; | ||
|
||
parent::__construct('yokai:security-token:archive'); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('yokai:security-token:archive') | ||
->addOption('purpose', null, InputOption::VALUE_OPTIONAL, 'Filter tokens to archive on purpose.') | ||
->addOption('before', null, InputOption::VALUE_OPTIONAL, 'Filter tokens to archive on created date.') | ||
; | ||
|
@@ -71,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
} | ||
|
||
/** @var $archivist ArchivistInterface */ | ||
$archivist = $this->container->get('yokai_security_token.resolved.archivist'); | ||
$archivist = $this->getContainer()->get('yokai_security_token.archivist'); | ||
|
||
$count = $archivist->archive($purpose, $beforeDate); | ||
|
||
|
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 |
---|---|---|
|
@@ -5,32 +5,25 @@ | |
use Symfony\Component\Config\Definition\Builder\NodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
use Yokai\SecurityTokenBundle\Archive\DeleteArchivist; | ||
use Yokai\SecurityTokenBundle\Factory\TokenFactory; | ||
use Yokai\SecurityTokenBundle\InformationGuesser\InformationGuesser; | ||
use Yokai\SecurityTokenBundle\Manager\TokenManager; | ||
use Yokai\SecurityTokenBundle\Manager\UserManager; | ||
use Yokai\SecurityTokenBundle\Repository\TokenRepository; | ||
|
||
/** | ||
* @author Yann Eugoné <[email protected]> | ||
*/ | ||
class Configuration implements ConfigurationInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @param string $name | ||
*/ | ||
public function __construct($name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$builder = new TreeBuilder(); | ||
$root = $builder->root($this->name); | ||
$root = $builder->root('yokai_security_token'); | ||
|
||
$root | ||
->addDefaultsIfNotSet() | ||
|
@@ -80,16 +73,19 @@ private function getServicesNode() | |
->addDefaultsIfNotSet() | ||
->children() | ||
->scalarNode('information_guesser') | ||
->defaultValue('yokai_security_token.information_guesser') | ||
->defaultValue('yokai_security_token.default_information_guesser') | ||
->end() | ||
->scalarNode('token_factory') | ||
->defaultValue('yokai_security_token.default_token_factory') | ||
->end() | ||
->scalarNode('factory') | ||
->defaultValue('yokai_security_token.token_factory') | ||
->scalarNode('token_repository') | ||
->defaultValue('yokai_security_token.default_token_repository') | ||
->end() | ||
->scalarNode('repository') | ||
->defaultValue('yokai_security_token.token_repository') | ||
->scalarNode('token_manager') | ||
->defaultValue('yokai_security_token.default_token_manager') | ||
->end() | ||
->scalarNode('manager') | ||
->defaultValue('yokai_security_token.token_manager') | ||
->scalarNode('user_manager') | ||
->defaultValue('yokai_security_token.default_user_manager') | ||
->end() | ||
->scalarNode('archivist') | ||
->defaultValue('yokai_security_token.delete_archivist') | ||
|
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 |
---|---|---|
|
@@ -2,32 +2,23 @@ | |
|
||
namespace Yokai\SecurityTokenBundle\DependencyInjection; | ||
|
||
use ReflectionClass; | ||
use Symfony\Component\Config\Resource\FileResource; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
use Yokai\SecurityTokenBundle\Archive\ArchivistInterface; | ||
use Yokai\SecurityTokenBundle\DependencyInjection\Factory\TokenConfigurationFactory; | ||
use Yokai\SecurityTokenBundle\Factory\TokenFactoryInterface; | ||
use Yokai\SecurityTokenBundle\InformationGuesser\InformationGuesserInterface; | ||
use Yokai\SecurityTokenBundle\Manager\TokenManagerInterface; | ||
use Yokai\SecurityTokenBundle\Manager\UserManagerInterface; | ||
use Yokai\SecurityTokenBundle\Repository\TokenRepositoryInterface; | ||
|
||
/** | ||
* @author Yann Eugoné <[email protected]> | ||
*/ | ||
class YokaiSecurityTokenExtension extends Extension | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @param string $name | ||
*/ | ||
public function __construct($name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
|
@@ -42,18 +33,6 @@ public function load(array $configs, ContainerBuilder $container) | |
$this->registerAliases($config, $container); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getConfiguration(array $config, ContainerBuilder $container) | ||
{ | ||
$configuration = new Configuration($this->name); | ||
$reflection = new ReflectionClass($configuration); | ||
$container->addResource(new FileResource($reflection->getFileName())); | ||
|
||
return $configuration; | ||
} | ||
|
||
/** | ||
* @param array $config | ||
* @param ContainerBuilder $container | ||
|
@@ -72,7 +51,7 @@ private function registerTokens(array $config, ContainerBuilder $container) | |
private function registerAliases(array $config, ContainerBuilder $container) | ||
{ | ||
foreach ($config['services'] as $name => $service) { | ||
$container->setAlias(sprintf('yokai_security_token.resolved.%s', $name), $service); | ||
$container->setAlias(sprintf('yokai_security_token.%s', $name), $service); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
namespace Yokai\SecurityTokenBundle\Entity; | ||
|
||
use DateTime; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
/** | ||
* @author Yann Eugoné <[email protected]> | ||
|
@@ -16,9 +15,14 @@ class Token | |
private $id; | ||
|
||
/** | ||
* @var UserInterface | ||
* @var string | ||
*/ | ||
private $userClass; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $user; | ||
private $userId; | ||
|
||
/** | ||
* @var string | ||
|
@@ -56,15 +60,17 @@ class Token | |
private $usedInformation; | ||
|
||
/** | ||
* @param UserInterface $user | ||
* @param string $value | ||
* @param string $purpose | ||
* @param string $duration | ||
* @param array $information | ||
* @param string $userClass | ||
* @param string $userId | ||
* @param string $value | ||
* @param string $purpose | ||
* @param string $duration | ||
* @param array $information | ||
*/ | ||
public function __construct(UserInterface $user, $value, $purpose, $duration, array $information) | ||
public function __construct($userClass, $userId, $value, $purpose, $duration, array $information) | ||
{ | ||
$this->user = $user; | ||
$this->userClass = $userClass; | ||
$this->userId = $userId; | ||
$this->value = $value; | ||
$this->purpose = $purpose; | ||
$this->createdAt = new DateTime(); | ||
|
@@ -81,11 +87,19 @@ public function getId() | |
} | ||
|
||
/** | ||
* @return UserInterface | ||
* @return string | ||
*/ | ||
public function getUserClass() | ||
{ | ||
return $this->userClass; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getUser() | ||
public function getUserId() | ||
{ | ||
return $this->user; | ||
return $this->userId; | ||
} | ||
|
||
/** | ||
|
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 |
---|---|---|
|
@@ -2,10 +2,10 @@ | |
|
||
namespace Yokai\SecurityTokenBundle\Factory; | ||
|
||
use Symfony\Component\Security\Core\User\UserInterface; | ||
use Yokai\SecurityTokenBundle\Configuration\TokenConfigurationRegistry; | ||
use Yokai\SecurityTokenBundle\Entity\Token; | ||
use Yokai\SecurityTokenBundle\InformationGuesser\InformationGuesserInterface; | ||
use Yokai\SecurityTokenBundle\Manager\UserManagerInterface; | ||
|
||
/** | ||
* @author Yann Eugoné <[email protected]> | ||
|
@@ -23,24 +23,35 @@ class TokenFactory implements TokenFactoryInterface | |
private $informationGuesser; | ||
|
||
/** | ||
* @param TokenConfigurationRegistry $registry | ||
* @var UserManagerInterface | ||
*/ | ||
private $userManager; | ||
|
||
/** | ||
* @param TokenConfigurationRegistry $registry | ||
* @param InformationGuesserInterface $informationGuesser | ||
* @param UserManagerInterface $userManager | ||
*/ | ||
public function __construct(TokenConfigurationRegistry $registry, InformationGuesserInterface $informationGuesser) | ||
{ | ||
public function __construct( | ||
TokenConfigurationRegistry $registry, | ||
InformationGuesserInterface $informationGuesser, | ||
UserManagerInterface $userManager | ||
) { | ||
$this->registry = $registry; | ||
$this->informationGuesser = $informationGuesser; | ||
$this->userManager = $userManager; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function create(UserInterface $user, $purpose) | ||
public function create($user, $purpose) | ||
{ | ||
$configuration = $this->registry->get($purpose); | ||
|
||
return new Token( | ||
$user, | ||
$this->userManager->getClass($user), | ||
$this->userManager->getId($user), | ||
$configuration->getGenerator()->generate(), | ||
$purpose, | ||
$configuration->getDuration(), | ||
|
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.