I try to authenticate user:
<?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'); } But I get permanent 302 redirect to /login page.
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 } Code for authenticate I take from https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Controller/RegistrationController.php
Error in app/logs/dev.log:
redirecting to authentication entry point (No Authentication Provider found for token of class "Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken".) [] [] I can't access to site until I clean cookies.