In case you don’t use FOSRestBundle and you don’t use login form in your app
and have finally a response with “html meta refresh” to an “afterlogin” page after successful login, but you want a REST resource output instead to be returned directly,
you will need to create additionally an “entrypoint” class, something like :
in Acme/DemoBundle/Resources/config/security.yml
demo.entry_point: class: Acme\DemoBundle\DemoEntryPoint
in Acme/DemoBundle/ :
namespace Acme\DemoBundle; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; use Symfony\Component\Security\Http\HttpUtils; class DemoEntryPoint implements AuthenticationEntryPointInterface { private $httpUtils; private $redirectPath; public function __construct() { } /** * {@inheritdoc} */ public function start(Request $request, AuthenticationException $authException = null) { //redirect action goes here //return $this->httpUtils->createRedirectResponse($request, $this->redirectPath); } }
For a more detailed help check http://stackoverflow.com/questions/10089816/symfony2-how-to-check-if-an-action-is-secured