3 namespace Acme\DemoBundle\Controller
;
5 use Symfony\Component\HttpFoundation\Request
;
6 use Symfony\Component\Security\Core\SecurityContext
;
7 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
8 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
9 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template
;
10 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security
;
13 * @Route("/demo/secured")
15 class SecuredController
extends Controller
18 * @Route("/login", name="_demo_login")
21 public function loginAction(Request
$request)
23 if ($request->attributes
->has(SecurityContext
::AUTHENTICATION_ERROR
)) {
24 $error = $request->attributes
->get(SecurityContext
::AUTHENTICATION_ERROR
);
26 $error = $request->getSession()->get(SecurityContext
::AUTHENTICATION_ERROR
);
30 'last_username' => $request->getSession()->get(SecurityContext
::LAST_USERNAME
),
36 * @Route("/login_check", name="_demo_security_check")
38 public function securityCheckAction()
40 // The security layer will intercept this request
44 * @Route("/logout", name="_demo_logout")
46 public function logoutAction()
48 // The security layer will intercept this request
52 * @Route("/hello", defaults={"name"="World"}),
53 * @Route("/hello/{name}", name="_demo_secured_hello")
56 public function helloAction($name)
58 return array('name' => $name);
62 * @Route("/hello/admin/{name}", name="_demo_secured_hello_admin")
63 * @Security("is_granted('ROLE_ADMIN')")
66 public function helloadminAction($name)
68 return array('name' => $name);