If you are using symfony 2.4, then there is a way you can specify this in the security.yml file. The the docs Securing by expression.
Basically, in your access_control
section, you can have a allow_if
entry that allows you to have a custom conditional expression.
You can use an expression similar to this:
allow_if: "not is_authenticated()"