Saturday, 15 August 2015

symfony2 - Roles in login not being stored in User of security context -



symfony2 - Roles in login not being stored in User of security context -

after searching 2 days , trying many different solutions couldn't find answer. have followed steps of tutorial (http://roberto.costumero.es/2011/08/15/creando-un-login-simple-con-symfony2/) build simple login process have:

table user table role

many many relation between them (user_rol). mysql tables correctly created , have orm doctrine classes also.

if load user hand , load roles works fine when utilize automatic login

{% block body %} {% if error %} <div>{{ error.message }}</div> {% endif %} <form action="{{ path('login_check') }}" method="post"> <label for="username">usuario:</label> <input id="username" type="text" name="_username" value="{{ last_username }}" /> <label for="password">contraseƱa:</label> <input id="password" type="password" name="_password" /> {# if want command url user redirected on success (more details below) <input type="hidden" name="_target_path" value="/account" /> #} <input type="submit" name="login" /> </form> {% endblock %}

after login in user identified there warning message in _profiler saying "authenticated no" (probably because user has no roles)

so in code:

$user = $this->get('security.context')->gettoken()->getuser(); print_r(count($user->getroles()))

and roles empty. ideas?

p.d: tried overwriting serialize function of object , including roles didn't work.

just few questions:

does user entity extends symfony\component\security\core\user class? does getroles() homecoming array string each role?

maybe need forcefulness in constructor set roles in user, because if using entity manage roles, haver role objects, not array of strings identifying roles.

symfony2 authentication login orm doctrine

No comments:

Post a Comment