Skip to main content
http://meta.stackoverflow.com/q/137230/182741
Link
j0k
  • 22.8k
  • 28
  • 81
  • 90
added 16 characters in body
Source Link
alexfv
  • 1.9k
  • 2
  • 19
  • 23
<?php /** * @Route("/testLogin", name="testLogin") */ public function testLoginAction() { $em = $this->getDoctrine()->getEntityManager(); $user = $em->getRepository('ApplicationDefaultBundle:User')->findOneBy(array('id' => 126)); $providerKey = 'main'; $token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles()); $this->container->get('security.context')->setToken($token); return $this->redirect($this->generateUrl('testCheck')); } /** * @Route("/testCheck", name="testCheck") */ public function testCheckAction() { if (false === $this->get('security.context')->isGranted( 'IS_AUTHENTICATED_REMEMBERED' )) { return new Response('Not logged'); } $user = $this->container->get('security.context')->getToken()->getUser(); return new Response($user->getUsername.' is logged'); } 
/** * @Route("/testLogin", name="testLogin") */ public function testLoginAction() { $em = $this->getDoctrine()->getEntityManager(); $user = $em->getRepository('ApplicationDefaultBundle:User')->findOneBy(array('id' => 126)); $providerKey = 'main'; $token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles()); $this->container->get('security.context')->setToken($token); return $this->redirect($this->generateUrl('testCheck')); } /** * @Route("/testCheck", name="testCheck") */ public function testCheckAction() { if (false === $this->get('security.context')->isGranted( 'IS_AUTHENTICATED_REMEMBERED' )) { return new Response('Not logged'); } $user = $this->container->get('security.context')->getToken()->getUser(); return new Response($user->getUsername.' is logged'); } 
<?php /** * @Route("/testLogin", name="testLogin") */ public function testLoginAction() { $em = $this->getDoctrine()->getEntityManager(); $user = $em->getRepository('ApplicationDefaultBundle:User')->findOneBy(array('id' => 126)); $providerKey = 'main'; $token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles()); $this->container->get('security.context')->setToken($token); return $this->redirect($this->generateUrl('testCheck')); } /** * @Route("/testCheck", name="testCheck") */ public function testCheckAction() { if (false === $this->get('security.context')->isGranted( 'IS_AUTHENTICATED_REMEMBERED' )) { return new Response('Not logged'); } $user = $this->container->get('security.context')->getToken()->getUser(); return new Response($user->getUsername.' is logged'); } 
added 513 characters in body
Source Link
alexfv
  • 1.9k
  • 2
  • 19
  • 23

Security.yml:

security: encoders: Application\Bundle\DefaultBundle\Entity\User: algorithm: sha512 iterations: 24 encode_as_base64: true role_hierarchy: ROLE_ADMIN: ROLE_USER ROLE_SPECIALIST: ROLE_USER ROLE_EMPLOYER: ROLE_USER ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] providers:   main:   entity: { class: Application\Bundle\DefaultBundle\Entity\User, property: username }    firewalls:   secured_area:   remember_me:   key: MySecretKeyMySecretKeyBlablabla   lifetime: 36000000   path: /   domain: ~   pattern: ^/   form_login:   check_path: /login_check   login_path: /login   provider: main   logout:   path: /logout   target: /   anonymous: true    access_control:   - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } 

Security.yml:

providers: main: entity: { class: Application\Bundle\DefaultBundle\Entity\User, property: username } firewalls: secured_area: remember_me: key: MySecretKey lifetime: 36000000 path: / domain: ~ pattern: ^/ form_login: check_path: /login_check login_path: /login provider: main logout: path: /logout target: / anonymous: true access_control: - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } 
security: encoders: Application\Bundle\DefaultBundle\Entity\User: algorithm: sha512 iterations: 24 encode_as_base64: true role_hierarchy: ROLE_ADMIN: ROLE_USER ROLE_SPECIALIST: ROLE_USER ROLE_EMPLOYER: ROLE_USER ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] providers:   main:   entity: { class: Application\Bundle\DefaultBundle\Entity\User, property: username }    firewalls:   secured_area:   remember_me:   key: MySecretKeyBlablabla   lifetime: 36000000   path: /   domain: ~   pattern: ^/   form_login:   check_path: /login_check   login_path: /login   provider: main   logout:   path: /logout   target: /   anonymous: true    access_control:   - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } 
added 266 characters in body
Source Link
alexfv
  • 1.9k
  • 2
  • 19
  • 23
Loading
Source Link
alexfv
  • 1.9k
  • 2
  • 19
  • 23
Loading