Skip to content

[SecurityBundle] Throw a meaningful exception when an undefined user provider is used inside a firewall #24114

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
Sep 7, 2017

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Sep 6, 2017

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

Before

The service "security.authentication.manager" has a dependency on a non-existent service "security.user.provider.concrete.undefined_provider".

After

Invalid firewall "main": user provider "undefined_provider" not found.

@chalasr chalasr added DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature SecurityBundle labels Sep 6, 2017
@chalasr chalasr added this to the 3.4 milestone Sep 6, 2017
@@ -332,6 +332,9 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
// Provider id (take the first registered provider if none defined)
if (isset($firewall['provider'])) {
$defaultProvider = $this->getUserProviderId($firewall['provider']);
if (!in_array($defaultProvider, $providerIds, true)) {
throw new InvalidConfigurationException(sprintf('User provider "%s" used for firewall "%s" does not exist.', $firewall['provider'], $id));
Copy link
Member

Choose a reason for hiding this comment

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

would that be more readable (similar below)?
Invalid firewall "%s": user provider "%s" not found.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 should we use the very same message for the case where the provider is configured under a listener (handled below)? I think so

Copy link
Member

Choose a reason for hiding this comment

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

LGTM

@chalasr chalasr force-pushed the secu-dx-missng-provider-error branch from e58bed4 to b884c66 Compare September 7, 2017 08:20
@fabpot
Copy link
Member

fabpot commented Sep 7, 2017

Thank you @chalasr.

@fabpot fabpot merged commit b884c66 into symfony:3.4 Sep 7, 2017
fabpot added a commit that referenced this pull request Sep 7, 2017
…undefined user provider is used inside a firewall (chalasr)

This PR was merged into the 3.4 branch.

Discussion
----------

[SecurityBundle] Throw a meaningful exception when an undefined user provider is used inside a firewall

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

Before

> The service "security.authentication.manager" has a dependency on a non-existent service "security.user.provider.concrete.undefined_provider".

After

> Invalid firewall "main": user provider "undefined_provider" not found.

Commits
-------

b884c66 Throw a meaningful exception when an undefined user provider is used inside a firewall
@chalasr chalasr deleted the secu-dx-missng-provider-error branch September 7, 2017 14:48
@mvrhov
Copy link

mvrhov commented Sep 7, 2017

I'm getting this error in project that worked with 2days old 3.4 What else has changed?

@mvrhov
Copy link

mvrhov commented Sep 7, 2017

Addon This PR is the culprit for the error. I've checked out 7dfb5aa which is one commit before this one was merged and everything works.

This is the excerpt from the security.yml

security:
    encoders:
        'Foo\Bundle\AccountBundle\Security\User':
            algorithm: bcrypt
    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
    providers:
        account:
            id: account.security.user_provider
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt|error|pomm))/
            security: false
        assets:
            pattern: ^/(bundles|compiled)/
            security: false
        default:
            pattern:    .*
            anonymous:  true
            user_checker: account.security.user_checker
            logout:
                path:   /logout
                target: /
                invalidate_session: true
                delete_cookies:
                    PHPSESSID: { path: null, domain: null }
            form_login:
                provider:   account
                login_path: account_security_login
                check_path: account_security_check
                username_parameter: 'login[username]'
                password_parameter: 'login[password]'
            remember_me:
                secret:   '%remember_me_key%'
                lifetime: 2592000 # one month
                path:     /
                domain:   ~ # Defaults to the current domain from $_SERVER
    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/, role: [IS_AUTHENTICATED_FULLY,IS_AUTHENTICATED_REMEMBERED] }

@mvrhov
Copy link

mvrhov commented Sep 7, 2017

@chalasr ping

@chalasr
Copy link
Member Author

chalasr commented Sep 7, 2017

@mvrhov I'm on it.

@chalasr
Copy link
Member Author

chalasr commented Sep 7, 2017

Can you try #24132 and confirm it fixes it? Sorry for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature SecurityBundle Status: Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants