login consent app sql
This commit is contained in:
289
vendor/symfony/security-bundle/Command/DebugFirewallCommand.php
vendored
Normal file
289
vendor/symfony/security-bundle/Command/DebugFirewallCommand.php
vendored
Normal file
@ -0,0 +1,289 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\SecurityBundle\Command;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Bundle\SecurityBundle\Security\FirewallContext;
|
||||
use Symfony\Bundle\SecurityBundle\Security\LazyFirewallContext;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Completion\CompletionInput;
|
||||
use Symfony\Component\Console\Completion\CompletionSuggestions;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
|
||||
|
||||
/**
|
||||
* @author Timo Bakx <timobakx@gmail.com>
|
||||
*/
|
||||
final class DebugFirewallCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'debug:firewall';
|
||||
protected static $defaultDescription = 'Display information about your security firewall(s)';
|
||||
|
||||
private $firewallNames;
|
||||
private $contexts;
|
||||
private $eventDispatchers;
|
||||
private $authenticators;
|
||||
private $authenticatorManagerEnabled;
|
||||
|
||||
/**
|
||||
* @param string[] $firewallNames
|
||||
* @param AuthenticatorInterface[][] $authenticators
|
||||
*/
|
||||
public function __construct(array $firewallNames, ContainerInterface $contexts, ContainerInterface $eventDispatchers, array $authenticators, bool $authenticatorManagerEnabled)
|
||||
{
|
||||
if (!$authenticatorManagerEnabled) {
|
||||
trigger_deprecation('symfony/security-bundle', '5.4', 'Setting the $authenticatorManagerEnabled argument of "%s" to "false" is deprecated, use the new authenticator system instead.', __METHOD__);
|
||||
}
|
||||
|
||||
$this->firewallNames = $firewallNames;
|
||||
$this->contexts = $contexts;
|
||||
$this->eventDispatchers = $eventDispatchers;
|
||||
$this->authenticators = $authenticators;
|
||||
$this->authenticatorManagerEnabled = $authenticatorManagerEnabled;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$exampleName = $this->getExampleName();
|
||||
|
||||
$this
|
||||
->setDescription(self::$defaultDescription)
|
||||
->setHelp(<<<EOF
|
||||
The <info>%command.name%</info> command displays the firewalls that are configured
|
||||
in your application:
|
||||
|
||||
<info>php %command.full_name%</info>
|
||||
|
||||
You can pass a firewall name to display more detailed information about
|
||||
a specific firewall:
|
||||
|
||||
<info>php %command.full_name% $exampleName</info>
|
||||
|
||||
To include all events and event listeners for a specific firewall, use the
|
||||
<info>events</info> option:
|
||||
|
||||
<info>php %command.full_name% --events $exampleName</info>
|
||||
|
||||
EOF
|
||||
)
|
||||
->setDefinition([
|
||||
new InputArgument('name', InputArgument::OPTIONAL, sprintf('A firewall name (for example "%s")', $exampleName)),
|
||||
new InputOption('events', null, InputOption::VALUE_NONE, 'Include a list of event listeners (only available in combination with the "name" argument)'),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$name = $input->getArgument('name');
|
||||
|
||||
if (null === $name) {
|
||||
$this->displayFirewallList($io);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$serviceId = sprintf('security.firewall.map.context.%s', $name);
|
||||
|
||||
if (!$this->contexts->has($serviceId)) {
|
||||
$io->error(sprintf('Firewall %s was not found. Available firewalls are: %s', $name, implode(', ', $this->firewallNames)));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** @var FirewallContext $context */
|
||||
$context = $this->contexts->get($serviceId);
|
||||
|
||||
$io->title(sprintf('Firewall "%s"', $name));
|
||||
|
||||
$this->displayFirewallSummary($name, $context, $io);
|
||||
|
||||
$this->displaySwitchUser($context, $io);
|
||||
|
||||
if ($input->getOption('events')) {
|
||||
$this->displayEventListeners($name, $context, $io);
|
||||
}
|
||||
|
||||
if ($this->authenticatorManagerEnabled) {
|
||||
$this->displayAuthenticators($name, $io);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function displayFirewallList(SymfonyStyle $io): void
|
||||
{
|
||||
$io->title('Firewalls');
|
||||
$io->text('The following firewalls are defined:');
|
||||
|
||||
$io->listing($this->firewallNames);
|
||||
|
||||
$io->comment(sprintf('To view details of a specific firewall, re-run this command with a firewall name. (e.g. <comment>debug:firewall %s</comment>)', $this->getExampleName()));
|
||||
}
|
||||
|
||||
protected function displayFirewallSummary(string $name, FirewallContext $context, SymfonyStyle $io): void
|
||||
{
|
||||
if (null === $context->getConfig()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rows = [
|
||||
['Name', $name],
|
||||
['Context', $context->getConfig()->getContext()],
|
||||
['Lazy', $context instanceof LazyFirewallContext ? 'Yes' : 'No'],
|
||||
['Stateless', $context->getConfig()->isStateless() ? 'Yes' : 'No'],
|
||||
['User Checker', $context->getConfig()->getUserChecker()],
|
||||
['Provider', $context->getConfig()->getProvider()],
|
||||
['Entry Point', $context->getConfig()->getEntryPoint()],
|
||||
['Access Denied URL', $context->getConfig()->getAccessDeniedUrl()],
|
||||
['Access Denied Handler', $context->getConfig()->getAccessDeniedHandler()],
|
||||
];
|
||||
|
||||
$io->table(
|
||||
['Option', 'Value'],
|
||||
$rows
|
||||
);
|
||||
}
|
||||
|
||||
private function displaySwitchUser(FirewallContext $context, SymfonyStyle $io)
|
||||
{
|
||||
if ((null === $config = $context->getConfig()) || (null === $switchUser = $config->getSwitchUser())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$io->section('User switching');
|
||||
|
||||
$io->table(['Option', 'Value'], [
|
||||
['Parameter', $switchUser['parameter'] ?? ''],
|
||||
['Provider', $switchUser['provider'] ?? $config->getProvider()],
|
||||
['User Role', $switchUser['role'] ?? ''],
|
||||
]);
|
||||
}
|
||||
|
||||
protected function displayEventListeners(string $name, FirewallContext $context, SymfonyStyle $io): void
|
||||
{
|
||||
$io->title(sprintf('Event listeners for firewall "%s"', $name));
|
||||
|
||||
$dispatcherId = sprintf('security.event_dispatcher.%s', $name);
|
||||
|
||||
if (!$this->eventDispatchers->has($dispatcherId)) {
|
||||
$io->text('No event dispatcher has been registered for this firewall.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var EventDispatcherInterface $dispatcher */
|
||||
$dispatcher = $this->eventDispatchers->get($dispatcherId);
|
||||
|
||||
foreach ($dispatcher->getListeners() as $event => $listeners) {
|
||||
$io->section(sprintf('"%s" event', $event));
|
||||
|
||||
$rows = [];
|
||||
foreach ($listeners as $order => $listener) {
|
||||
$rows[] = [
|
||||
sprintf('#%d', $order + 1),
|
||||
$this->formatCallable($listener),
|
||||
$dispatcher->getListenerPriority($event, $listener),
|
||||
];
|
||||
}
|
||||
|
||||
$io->table(
|
||||
['Order', 'Callable', 'Priority'],
|
||||
$rows
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function displayAuthenticators(string $name, SymfonyStyle $io): void
|
||||
{
|
||||
$io->title(sprintf('Authenticators for firewall "%s"', $name));
|
||||
|
||||
$authenticators = $this->authenticators[$name] ?? [];
|
||||
|
||||
if (0 === \count($authenticators)) {
|
||||
$io->text('No authenticators have been registered for this firewall.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->table(
|
||||
['Classname'],
|
||||
array_map(
|
||||
static function ($authenticator) {
|
||||
return [
|
||||
\get_class($authenticator),
|
||||
];
|
||||
},
|
||||
$authenticators
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function formatCallable($callable): string
|
||||
{
|
||||
if (\is_array($callable)) {
|
||||
if (\is_object($callable[0])) {
|
||||
return sprintf('%s::%s()', \get_class($callable[0]), $callable[1]);
|
||||
}
|
||||
|
||||
return sprintf('%s::%s()', $callable[0], $callable[1]);
|
||||
}
|
||||
|
||||
if (\is_string($callable)) {
|
||||
return sprintf('%s()', $callable);
|
||||
}
|
||||
|
||||
if ($callable instanceof \Closure) {
|
||||
$r = new \ReflectionFunction($callable);
|
||||
if (false !== strpos($r->name, '{closure}')) {
|
||||
return 'Closure()';
|
||||
}
|
||||
if ($class = $r->getClosureScopeClass()) {
|
||||
return sprintf('%s::%s()', $class->name, $r->name);
|
||||
}
|
||||
|
||||
return $r->name.'()';
|
||||
}
|
||||
|
||||
if (method_exists($callable, '__invoke')) {
|
||||
return sprintf('%s::__invoke()', \get_class($callable));
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Callable is not describable.');
|
||||
}
|
||||
|
||||
private function getExampleName(): string
|
||||
{
|
||||
$name = 'main';
|
||||
|
||||
if (!\in_array($name, $this->firewallNames, true)) {
|
||||
$name = reset($this->firewallNames);
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
|
||||
{
|
||||
if ($input->mustSuggestArgumentValuesFor('name')) {
|
||||
$suggestions->suggestValues($this->firewallNames);
|
||||
}
|
||||
}
|
||||
}
|
216
vendor/symfony/security-bundle/Command/UserPasswordEncoderCommand.php
vendored
Normal file
216
vendor/symfony/security-bundle/Command/UserPasswordEncoderCommand.php
vendored
Normal file
@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\SecurityBundle\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\PasswordHasher\Command\UserPasswordHashCommand;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||
use Symfony\Component\Security\Core\Encoder\SelfSaltingEncoderInterface;
|
||||
|
||||
/**
|
||||
* Encode a user's password.
|
||||
*
|
||||
* @author Sarah Khalil <mkhalil.sarah@gmail.com>
|
||||
*
|
||||
* @final
|
||||
*
|
||||
* @deprecated since Symfony 5.3, use {@link UserPasswordHashCommand} instead
|
||||
*/
|
||||
class UserPasswordEncoderCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'security:encode-password';
|
||||
protected static $defaultDescription = 'Encode a password';
|
||||
|
||||
private $encoderFactory;
|
||||
private $userClasses;
|
||||
|
||||
public function __construct(EncoderFactoryInterface $encoderFactory, array $userClasses = [])
|
||||
{
|
||||
$this->encoderFactory = $encoderFactory;
|
||||
$this->userClasses = $userClasses;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDescription(self::$defaultDescription)
|
||||
->addArgument('password', InputArgument::OPTIONAL, 'The plain password to encode.')
|
||||
->addArgument('user-class', InputArgument::OPTIONAL, 'The User entity class path associated with the encoder used to encode the password.')
|
||||
->addOption('empty-salt', null, InputOption::VALUE_NONE, 'Do not generate a salt or let the encoder generate one.')
|
||||
->setHelp(<<<EOF
|
||||
|
||||
The <info>%command.name%</info> command encodes passwords according to your
|
||||
security configuration. This command is mainly used to generate passwords for
|
||||
the <comment>in_memory</comment> user provider type and for changing passwords
|
||||
in the database while developing the application.
|
||||
|
||||
Suppose that you have the following security configuration in your application:
|
||||
|
||||
<comment>
|
||||
# app/config/security.yml
|
||||
security:
|
||||
encoders:
|
||||
Symfony\Component\Security\Core\User\InMemoryUser: plaintext
|
||||
App\Entity\User: auto
|
||||
</comment>
|
||||
|
||||
If you execute the command non-interactively, the first available configured
|
||||
user class under the <comment>security.encoders</comment> key is used and a random salt is
|
||||
generated to encode the password:
|
||||
|
||||
<info>php %command.full_name% --no-interaction [password]</info>
|
||||
|
||||
Pass the full user class path as the second argument to encode passwords for
|
||||
your own entities:
|
||||
|
||||
<info>php %command.full_name% --no-interaction [password] 'App\Entity\User'</info>
|
||||
|
||||
Executing the command interactively allows you to generate a random salt for
|
||||
encoding the password:
|
||||
|
||||
<info>php %command.full_name% [password] 'App\Entity\User'</info>
|
||||
|
||||
In case your encoder doesn't require a salt, add the <comment>empty-salt</comment> option:
|
||||
|
||||
<info>php %command.full_name% --empty-salt [password] 'App\Entity\User'</info>
|
||||
|
||||
EOF
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
|
||||
|
||||
$errorIo->caution('The use of the "security:encode-password" command is deprecated since version 5.3 and will be removed in 6.0. Use "security:hash-password" instead.');
|
||||
|
||||
$input->isInteractive() ? $errorIo->title('Symfony Password Encoder Utility') : $errorIo->newLine();
|
||||
|
||||
$password = $input->getArgument('password');
|
||||
$userClass = $this->getUserClass($input, $io);
|
||||
$emptySalt = $input->getOption('empty-salt');
|
||||
|
||||
$encoder = $this->encoderFactory->getEncoder($userClass);
|
||||
$saltlessWithoutEmptySalt = !$emptySalt && $encoder instanceof SelfSaltingEncoderInterface;
|
||||
|
||||
if ($saltlessWithoutEmptySalt) {
|
||||
$emptySalt = true;
|
||||
}
|
||||
|
||||
if (!$password) {
|
||||
if (!$input->isInteractive()) {
|
||||
$errorIo->error('The password must not be empty.');
|
||||
|
||||
return 1;
|
||||
}
|
||||
$passwordQuestion = $this->createPasswordQuestion();
|
||||
$password = $errorIo->askQuestion($passwordQuestion);
|
||||
}
|
||||
|
||||
$salt = null;
|
||||
|
||||
if ($input->isInteractive() && !$emptySalt) {
|
||||
$emptySalt = true;
|
||||
|
||||
$errorIo->note('The command will take care of generating a salt for you. Be aware that some encoders advise to let them generate their own salt. If you\'re using one of those encoders, please answer \'no\' to the question below. '.\PHP_EOL.'Provide the \'empty-salt\' option in order to let the encoder handle the generation itself.');
|
||||
|
||||
if ($errorIo->confirm('Confirm salt generation ?')) {
|
||||
$salt = $this->generateSalt();
|
||||
$emptySalt = false;
|
||||
}
|
||||
} elseif (!$emptySalt) {
|
||||
$salt = $this->generateSalt();
|
||||
}
|
||||
|
||||
$encodedPassword = $encoder->encodePassword($password, $salt);
|
||||
|
||||
$rows = [
|
||||
['Encoder used', \get_class($encoder)],
|
||||
['Encoded password', $encodedPassword],
|
||||
];
|
||||
if (!$emptySalt) {
|
||||
$rows[] = ['Generated salt', $salt];
|
||||
}
|
||||
$io->table(['Key', 'Value'], $rows);
|
||||
|
||||
if (!$emptySalt) {
|
||||
$errorIo->note(sprintf('Make sure that your salt storage field fits the salt length: %s chars', \strlen($salt)));
|
||||
} elseif ($saltlessWithoutEmptySalt) {
|
||||
$errorIo->note('Self-salting encoder used: the encoder generated its own built-in salt.');
|
||||
}
|
||||
|
||||
$errorIo->success('Password encoding succeeded');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the password question to ask the user for the password to be encoded.
|
||||
*/
|
||||
private function createPasswordQuestion(): Question
|
||||
{
|
||||
$passwordQuestion = new Question('Type in your password to be encoded');
|
||||
|
||||
return $passwordQuestion->setValidator(function ($value) {
|
||||
if ('' === trim($value)) {
|
||||
throw new InvalidArgumentException('The password must not be empty.');
|
||||
}
|
||||
|
||||
return $value;
|
||||
})->setHidden(true)->setMaxAttempts(20);
|
||||
}
|
||||
|
||||
private function generateSalt(): string
|
||||
{
|
||||
return base64_encode(random_bytes(30));
|
||||
}
|
||||
|
||||
private function getUserClass(InputInterface $input, SymfonyStyle $io): string
|
||||
{
|
||||
if (null !== $userClass = $input->getArgument('user-class')) {
|
||||
return $userClass;
|
||||
}
|
||||
|
||||
if (empty($this->userClasses)) {
|
||||
throw new RuntimeException('There are no configured encoders for the "security" extension.');
|
||||
}
|
||||
|
||||
if (!$input->isInteractive() || 1 === \count($this->userClasses)) {
|
||||
return reset($this->userClasses);
|
||||
}
|
||||
|
||||
$userClasses = $this->userClasses;
|
||||
natcasesort($userClasses);
|
||||
$userClasses = array_values($userClasses);
|
||||
|
||||
return $io->choice('For which user class would you like to encode a password?', $userClasses, reset($userClasses));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user