New in Symfony 8.2: Security Expressions Everywhere
Security expressions let you use functions such as is\_granted() and is\_authenticated() to define complex access rules in access\_control, #\[IsGranted\] and other security features. Symfony 8.2 makes these functions available in more expressions, such as validation…
Security expressions let you use functions such as is_granted() and is_authenticated() to define complex access rules in access_control, #[IsGranted] and other security features. Symfony 8.2 makes these functions available in more expressions, such as validation constraints and controller attributes.
Security Functions in Validation Constraints
Contributed by Matthias Perret in #63719
Sometimes, validation rules depend on who's submitting the data. For example, you might want to limit the length of a blog post summary for most users, while letting editors write longer ones.
In Symfony 8.2, when your application uses both the Validator and Security components, the Expression constraint and the When constraint can use the is_granted(), is_authenticated(), is_fully_authenticated() and is_remember_me() functions:
// src/Entity/BlogPost.php
use Symfony\Component\Validator\Constraints as Assert;
class BlogPost
{ …