symfony - Login in symfony2 -


i'm trying implement basic authentication in symfony2. here main parts of code don't see problem

edit complete security.yml

jms_security_extra:     secure_all_services: false     expressions: true  security:     encoders:         symfony\component\security\core\user\user: plaintext      role_hierarchy:         role_admin:       role_user         role_super_admin: [role_user, role_admin, role_allowed_to_switch]      providers:         in_memory:             memory:                 users:                     user:  { password: userpass, roles: [ 'role_user' ] }                     admin: { password: adminpass, roles: [ 'role_admin' ] }      firewalls:         login:             pattern:    ^/login             anonymous: ~          secured_area:             pattern:    ^/             stateless:  true             form_login:                 login_path:  /login                 check_path:  /login_check      access_control:         - { path: ^/login, roles: is_authenticated_anonymously }         - { path: ^/, roles: role_user }     

this works fine, anonymous user redirected loginaction controller.

edit here complete code

<?php  namespace acmebundle\controller;  use symfony\bundle\frameworkbundle\controller\controller; use symfony\component\security\core\authentication\token\usernamepasswordtoken;  class securitycontroller extends controller {      public function loginaction() {          $providerkey = 'secured_area';         $token = new usernamepasswordtoken('test', 'test', $providerkey, array('role_user'));         $this->container->get('security.context')->settoken($token);          return $this->redirect($this->generateurl('fronthomepage'));      } } 

i don't see problem, anonymous user redirected loginaction, there created authenticated user, saved token , redirected secured area authenticated user. unfortunately code ends redirect loop looks security firewall doesn't accept user authenticated. see problem?

well, controller job render form not populate security context. symfony2 security firewall automatically. don't need handle unless want build own custom authentication.

in other words, job display login form , login errors may have occurred, security system takes care of checking submitted username , password , authenticating user.

please read document clear picture.

if want custom stuff when user logs in, in symfony2 have add event listener fire after user logged in. event fired security.interactive_login , hook have specify in services.yml file form bundle resources/config directory:


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -