How can I get a security token for any user, not only the one currently logged in ?
I would like to be able to call isGranted() on a user fetched from the database
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
isGranted()comes from the Security service, so it would be hard/unnecessary to use that to get Roles without adjusting the state of the session.Don’t get me wrong, it’s definitely possible… This would work, for example:
…but that really makes no sense.
In reality, you don’t need the token. A much better way of doing this would be to add an
isGranted()method into your User entity:Now you can get those roles in your controllers: