I’m using access_control (securiry.yml) for control access on my pages. Like that:
- { path: ^/, roles: ROLE_USER }
If a not connected user try to access, he will be redirected. Ok, it’s nice.
But some url can be used with Ajax. And i would like access_control return a json data in this case (not connected).
Is it possible ?
You have to write your own
AuthenticationHandlerwhich will implement two interfaces below:In that handler you should define two methods
onAuthenticationFailure()andonAuthenticationSuccess()Inside them just check if
$request->isXmlHttpRequest()Don’t forget also to set your listener in
security.yml