6

From the symfony book http://symfony.com/doc/current/book/security.html#security-authorization I'm trying to set up the basic http authentication.

The security.yml file looks like this:

security:
    providers:
        in_memory:
            memory: ~

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt|error)|css|images|js)/
            security: false

        default:
            anonymous: ~
            http_basic: ~

        access_control:
            - { path: ^/login, roles: ROLE_USER }

But as soon as I add

    access_control:
        - { path: ^/login, roles: ROLE_USER }

I get a symfony error saying:

InvalidConfigurationException in ArrayNode.php line 309:
Unrecognized option "0" under "security.firewalls.access_control"

What am I doing wrong? What to do to fix it?

2 Answers 2

24

Your indentation isn't good

access_control key can't stay under firewalls node

You should modify your security.yml as follows

security:
    providers:
        in_memory:
            memory: ~

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt|error)|css|images|js)/
            security: false

        default:
            anonymous: ~
            http_basic: ~

    access_control:
        - { path: ^/login, roles: ROLE_USER }
Sign up to request clarification or add additional context in comments.

2 Comments

oooh thank you @DonCallisto! Now I know that whitespace also really matters a lot in .yml files! Will accepct as soon as I can
@caramba: Of course they matter, otherwise file can't be parsed
2

Remember that if you require ROLE_USER to your /login path then an unauthorised user can't login to your app.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.