Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MakeAuthenticator : update security.yaml #261

Merged
merged 5 commits into from
Sep 11, 2018
Merged

MakeAuthenticator : update security.yaml #261

merged 5 commits into from
Sep 11, 2018

Conversation

nikophil
Copy link
Contributor

@nikophil nikophil commented Sep 6, 2018

This PR adds the newly created authenticator to security.yaml

The process is the following :

  • if no firewall exist, a "main" firewall is automatically created (this should never happen)
  • if there is only one "real" firewall (i.e. : a firewall withou security: false"), the authenticator is added to this firewall
  • if there are more than one firewall, the user is asked to which firewall the authenticator should be added
  • if the target firewall already has an authenticator, the user is asked which authenticator should be the entry point.

Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nikophil!

GREAT work! I left comments - a lot of minor stuff. You handled the flow, questions, edge-cases and tests very well. Super excited about this!

src/Maker/MakeAuthenticator.php Show resolved Hide resolved
{
$fs = new Filesystem();

if (!$fs->exists($path = 'config/packages/security.yaml')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use $this->fileManager->fileExists() instead - you already did this below in generate() :)

$interactiveSecurityHelper = new InteractiveSecurityHelper();

$command->addOption('firewall-name', null, InputOption::VALUE_OPTIONAL, '');
$interactiveSecurityHelper->guessFirewallName($input, $io, $securityData);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think guessFirewallName() and guessEntryPoint() should both return the firewall name & entry point, instead of setting it onto the option. It's just a bit more clear.

]);
$text = ['Next: Customize your new authenticator.'];
if (!$securityYamlUpdated) {
$text[] = 'Then, configure the "guard" key on your firewall to use it.';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job adding a message in this case. Let's make it even more explicit (from MakeUser):

$text[] = "Your <info>security.yaml</info> could not be updated automatically. You'll need to add the following config manually:\n\n".$yamlExample;

Where $yamlExample is a config dump of the stuff they need to add.

*/
public function guessFirewallName(InputInterface $input, SymfonyStyle $io, array $securityData)
{
$firewalls = array_filter(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about $realFirewalls

$finder = new Finder();
$finder->in($directory.'/src/Security')
->name('AppCustomAuthenticator.php');
$this->assertCount(1, $finder);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can avoid this check on all the tests, except for the frist.

[
// class name
'AppCustomAuthenticator',
1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here - comment for what the option is

// class name
'AppCustomAuthenticator',
1,
1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments here

*
* @param array $securityData
* @param string $expectedFirewallName
* @param bool $multipleValues
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these @param

$input = $this->createMock(InputInterface::class);
$input->expects($this->once())
->method('setOption')
->with('firewall-name', $expectedFirewallName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will simplify a but, when we start passing in $firewallName directly :)

*/
final class InteractiveSecurityHelper
{
public function guessFirewallName(SymfonyStyle $io, array $securityData)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type: : string

src/Security/InteractiveSecurityHelper.php Show resolved Hide resolved
@weaverryan
Copy link
Member

Test failures are unrelated - working on them in a different PR :)

@weaverryan
Copy link
Member

This is awesome! Thank you Nicolas!

@weaverryan weaverryan merged commit 3a26d98 into symfony:master Sep 11, 2018
weaverryan added a commit that referenced this pull request Sep 11, 2018
This PR was squashed before being merged into the 1.0-dev branch (closes #261).

Discussion
----------

MakeAuthenticator : update security.yaml

This PR adds the newly created authenticator to `security.yaml`

The process is the following :
- if no firewall exist, a "main" firewall is automatically created (this should never happen)
- if there is only one "real" firewall (i.e. : a firewall withou security: false"), the authenticator is added to this firewall
- if there are more than one firewall, the user is asked to which firewall the authenticator should be added
- if the target firewall already has an authenticator, the user is asked which authenticator should be the entry point.

Commits
-------

3a26d98 add return type to InteractiveSecurityHelper::guessFirewallName
a983caa fixes after PR
2186549 Add entry point if one or more authenticators exist on chosen firewall
c63a86a Add authenticator : let the user chose which firewall to update
2fb5b40 add authenticator in security.yaml the simplest way
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants