symfony2 - Custom message for @Security annotation -



symfony2 - Custom message for @Security annotation -

i'm trying utilize @security annotations routes. this:

/** * @return response * @route("/action") * @security("has_role('role_user')") * @template() */ public function someaction() { homecoming array(); }

when security restriction fires exception, message expression "has_role('role_user')" denied access.

this not acceptable shown end user, i'm trying find way customize message annotation.

simple workaround not utilize @secutity annotations , write code these:

/** * @return response * @route("/action") * * @template() */ public function someaction() { if (!$this->get('security.context')->isgranted('role_user')) { throw new accessdeniedexception('you have logged in in order utilize feature'); } homecoming array(); }

but less convenient , less readable.

is possible write custom message @security annotations?

as realized not possible, have made pull request sensio frameworkextra bundle create possible.

this pr allows customize displayed message specifying message parameter like

@security("has_role('role_user')",message="you have logged in")

symfony2 symfony-security

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -