Skip to content

[DX][SecurityBundle] UserPasswordEncoderCommand: ask user class choice question #20677

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

Merged
merged 1 commit into from
Feb 16, 2017
Merged

[DX][SecurityBundle] UserPasswordEncoderCommand: ask user class choice question #20677

merged 1 commit into from
Feb 16, 2017

Conversation

ogizanagi
Copy link
Contributor

@ogizanagi ogizanagi commented Nov 28, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR N/A

Typing the user class is quite annoying so I'd suggest to ask the user to select it using a choice question.

This changes however requires to inject configured encoders' user classes. Making the command a service and providing it in the constructor from the extension is probably the cleanest way, but it deprecates:

  • registering the command by convention (registered as a service now, so potential commands extending this one should do the same)
  • relying on the fact the command extends ContainerAwareCommand and implements ContainerAwareInterface (will not extends/implements it anymore in 4.0 because it's not required anymore)

@@ -24,7 +24,7 @@
"require-dev": {
"symfony/asset": "~2.8|~3.0",
"symfony/browser-kit": "~2.8|~3.0",
"symfony/console": "~2.8|~3.0",
"symfony/console": "~3.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ogizanagi ogizanagi changed the title [SecurityBundle] UserPasswordEncoderCommand: ask user class choice question [DX][SecurityBundle] UserPasswordEncoderCommand: ask user class choice question Nov 29, 2016

if (empty($this->userClasses)) {
if (null === $this->encoderFactory) {
// BC to be remove and simply keep the exception whenever there is no configured user classes in 4.0
Copy link
Contributor

Choose a reason for hiding this comment

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

s/remove/removed/

throw new \RuntimeException('There are no configured encoders for the "security" extension.');
}

if (!$input->isInteractive() || count($this->userClasses) === 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

1 === count($this->userClasses)

Choose a reason for hiding this comment

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

Yoda conditions +1

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
@javiereguiluz javiereguiluz added the DX DX = Developer eXperience (anything that improves the experience of using Symfony) label Dec 30, 2016
@javiereguiluz
Copy link
Member

I'm sorry that the title of my e99cbe7 commit is so ugly. I just used GitHub interface to test the new feature to resolve conflicts.

@javiereguiluz
Copy link
Member

👍

Status: reviewed.

@ogizanagi thanks for this DX improvement.

@fabpot
Copy link
Member

fabpot commented Dec 31, 2016

This PR should be rebased as we don't merge PR with merge commits.

@ogizanagi
Copy link
Contributor Author

Sorry @javiereguiluz , I don't know what I should have done eventually in order to keep authorship for the conflict resolution. But anyway, thank you for that.

PR rebased on master.

@xabbuh
Copy link
Member

xabbuh commented Dec 31, 2016

The changelog file of the SecurityBundle must be updated too.

@ogizanagi
Copy link
Contributor Author

@xabbuh : Thanks. I've updated it. Let me know how it can possibly be enhanced. :)

UPGRADE-4.0.md Outdated
SecurityBundle
--------------

* The `UserPasswordEncoderCommand` class does not allow `null` as first argument anymore.
Copy link
Member

Choose a reason for hiding this comment

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

[...] as the first [...]

public function __construct(EncoderFactoryInterface $encoderFactory = null, array $userClasses = array())
{
if (null === $encoderFactory) {
@trigger_error(sprintf('Passing null as first argument of "%s" is deprecated since version 3.3 and will be removed in 4.0. If the command was registered by convention, make it a service instead.', __METHOD__), E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

[...] as the first [...]

UPGRADE-4.0.md Outdated

* The `UserPasswordEncoderCommand` class does not allow `null` as first argument anymore.

* `UserPasswordEncoderCommand` does not extend `ContainerAwareCommand` nor implement
Copy link
Member

Choose a reason for hiding this comment

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

Not sure we need to talk about the class. Not implementing the interface implies that the command cannot be an instance of ContainerAwareCommand anymore.

3.3.0
-----

* Deprecated registering by convention the `UserPasswordEncoderCommand` command
Copy link
Member

Choose a reason for hiding this comment

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

Is this deprecation necessary? The command will be registered by the SecurityBundle anyway, won't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's more about extending the command and registering it from another bundle actually. Can be rephrased I guess.

@ogizanagi
Copy link
Contributor Author

I think this one is ready :)

@javiereguiluz
Copy link
Member

@ogizanagi I've tested this and it works nice! Thanks.

I'm not sure this idea belongs to this PR, but the list of user classes maybe could be sorted alphabetically to make it easier to find them. At the moment the are displayed in the same order as defined in the security file:

available-users

@ogizanagi
Copy link
Contributor Author

@javiereguiluz : That's a nice suggestion indeed. I've updated the code to use natcasesort. :)

Copy link
Contributor

@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

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

👍

return reset($this->userClasses);
}

$userClasses = $this->userClasses;
Copy link
Contributor

Choose a reason for hiding this comment

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

$userClasses = array_values($this->userClasses);
natcasesort($userClasses);

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

natcasesort preserves keys. Hence the array_values call afterwards :)

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('security:encode-password')
Copy link
Member

Choose a reason for hiding this comment

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

Should be kept and the call in __construct changed to: parent::__construct(null);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks.

If you execute the command non-interactively, the default Symfony User class
is used and a random salt is generated to encode the password:
If you execute the command non-interactively, the first available configured user class under
the security.encoders key is used and a random salt is generated to encode the password:
Copy link
Member

Choose a reason for hiding this comment

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

security.encoders could be wrapped with a <comment> tag

If you execute the command non-interactively, the default Symfony User class
is used and a random salt is generated to encode the password:
If you execute the command non-interactively, the first available configured
user class under the <comment>security.encoders</comment> key is used and a
Copy link
Member

Choose a reason for hiding this comment

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

You should split lines at 80 chars (excluding the tags)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@fabpot
Copy link
Member

fabpot commented Feb 16, 2017

Thank you @ogizanagi.

@fabpot fabpot merged commit 366aefd into symfony:master Feb 16, 2017
fabpot added a commit that referenced this pull request Feb 16, 2017
…ser class choice question (ogizanagi)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DX][SecurityBundle] UserPasswordEncoderCommand: ask user class choice question

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

Typing the user class is quite annoying so I'd suggest to ask the user to select it using a choice question.

This changes however requires to inject configured encoders' user classes. Making the command a service and providing it in the constructor from the extension is probably the cleanest way, but it deprecates:

-  registering the command by convention (registered as a service now, so potential commands extending this one should do the same)
-  relying on the fact the command extends `ContainerAwareCommand` and implements `ContainerAwareInterface` (will not extends/implements it anymore in 4.0 because it's not required anymore)

Commits
-------

366aefd [SecurityBundle] UserPasswordEncoderCommand: ask user class choice question
@ogizanagi ogizanagi deleted the feature/security_bundle/enc_pwd_select_user_class branch February 16, 2017 15:36
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
@fabpot fabpot mentioned this pull request May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecation DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature SecurityBundle Status: Reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants