A Vue screen submits a note for an insurance claim. The JSON contains the claim ID and the text. The backend needs to verify that the user can create notes and that this claim falls within their work scope. If the text is blank and the claim belongs to another company, which response should the API return first? That decision affects the frontend, query costs, and how you test permissions.
On November 17, Symfony detailed a change to controller arguments for version 8.2 in its blog. An IsGranted attribute can use an argument converted and validated by MapRequestPayload, MapQueryString, or MapUploadedFile as the subject of a decision. On November 19, the release page still listed 8.2.0-BETA2, published on November 13, with a requirement of PHP 8.4 or later. Teams can use this phase to try their endpoints in staging and check how the order of operations affects the contract.
The example in this article is an insurance claims portal that separates companies. Its user has the ROLE_CLAIM_AGENT role but can add notes only to certain claims. The role grants access to the general function. The object rule decides whether the specific operation is allowed. In Symfony, a voter is the class that implements that decision. It receives an operation, a subject, and the security token to assess permission.
The 8.2 change allows the role check to run first, before building an object from the JSON. When authorization reaches the check whose subject is the mapped argument, the framework performs the required conversion and validation before calling the voter. A user who passes the first check and submits invalid data receives a validation error before that second decision. The contribution also records a compatibility break for voters that previously received the mapping attribute itself as the subject. Look for that case in existing security rules when testing the upgrade.
Turn this ordering into a contract test. Suppose the frontend treats every 403 as an instruction to leave the screen and every 422 as a form error the user can correct. A change to which error appears first can make the frontend keep a screen open when it previously closed it. Define the expected behavior for requests with more than one problem and test with the same role, JSON, and records on both application versions. Also check whether the response exposes identifiers or fields the user is allowed to inspect.
Start with the object that represents the input, called a DTO. It should declare what the operation accepts. In this example, the ID is a positive integer and the text has a maximum length of two thousand characters, with content beyond whitespace. The NotBlank normalizer participates in validation. The service still receives explicitly trimmed text when the product rule calls for removing whitespace at either end. Enable constraints and payload mapping in the test application.
namespace App\Dto;
use Symfony\Component\Validator\Constraints as Assert;
final readonly class AddClaimNote
{
public function __construct(
#[Assert\Positive]
public int $claimId,
#[Assert\NotBlank(normalizer: 'trim')]
#[Assert\Length(max: 2000)]
public string $text,
) {
}
}
The controller below shows the entry point for a Symfony 8.2 trial. The role attribute precedes the attribute that uses input. CLAIM_NOTE_CREATE and ClaimNoteWriter belong to the example. The application needs to implement the voter for that operation, register the service, and configure the endpoint's firewall and authenticator. This is a JSON API. The format option also guides the format of error responses generated by the framework.
namespace App\Controller;
use App\Dto\AddClaimNote;
use App\Service\ClaimNoteWriter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
final class ClaimNoteController extends AbstractController
{
#[Route('/api/claim-notes', methods: ['POST'], format: 'json')]
#[IsGranted('ROLE_CLAIM_AGENT')]
#[IsGranted('CLAIM_NOTE_CREATE', 'input')]
public function create(
#[MapRequestPayload(acceptFormat: 'json')] AddClaimNote $input,
ClaimNoteWriter $writer,
): JsonResponse {
$noteId = $writer->appendFor(
$this->getUser(),
$input->claimId,
trim($input->text),
);
return $this->json(['id' => $noteId], 201);
}
}
In the example's voter, check the subject's type and use the authenticated identity to find the company and the set of claims the user can access. The ID sent by the browser is a reference to look up within that set. If someone belongs to several companies, the server should already have validated the active company against their memberships. An extra tenantId in the JSON needs to be rejected or ignored according to the serialization contract, without determining the permission.
A dedicated DTO gives this review a defined scope. Anyone changing the input can see that the endpoint accepts claimId and text. Values such as the author, creation time, and user role come from other server sources. The Serializer configuration can reject extra attributes. If your team adopts that option, add a test for an unknown field to verify the expected error and align the frontend with the contract. Inspect the defaults and contexts used by existing endpoints before copying the example.
The example's appendFor() service receives the identity, finds the claim within the permitted scope, and writes according to the same business rule. That gives the rule a place to run when another entry point performs the operation. If a queued message can add a note, for instance, it needs to establish whose operation it is and which permission and state conditions apply at processing time. The controller attribute belongs to the HTTP flow. The queue handler needs its own check that reuses the business policy.
There is an interval between authorization and commit. If an operation requires the claim to stay open, another request might close it during that interval. Decide which consistency guarantee the rule needs. Doctrine offers version based optimistic locking and pessimistic locking, with different costs and requirements. The choice should work with a transaction covering the relevant condition and the write. Test the concurrent case the product needs to preserve, such as closing a claim while another session attempts to add a note.
Validation consumes resources too. A constraint that queries the database or calls another service can run before the voter that examines the DTO. Review the validators used at this entry point and keep the checks needed to produce valid input there. Observe what a rejected request does before it finishes. A role check before mapping reduces that work for users without the role, while accepted body size and request rate still depend on the limits configured in the infrastructure and application.
To measure the effect, prepare three staging scenarios with synthetic data. In the first, an authenticated user has the general role and attempts an allowed operation. In the second, the user has the role but the claim is outside their scope. In the third, the user has the role and submits invalid text. Record total duration, query count, and whether the write service was called. The profiler can collect query counts in functional tests. Latency comparisons need the same load, data, and equivalent configuration, particularly for cache and debug settings.
A possible target for this trial is zero claim queries when the text is blank. Count that access separately from authentication and session queries. If the test shows a business query before rejection, investigate which listener, resolver, or validator ran it. For a valid note, track the query used by the policy and the one used by the write service. The team can then assess whether it is repeating an expensive lookup and how to share operation context without reusing a decision from another person or request.
Add a test that records the type of subject delivered to the voter. On the candidate version, a valid note should deliver AddClaimNote to the CLAIM_NOTE_CREATE voter. Replace the write service with a test double that counts invocations. For denied permission, the count should be zero. The HTTP test confirms the result seen by the client, while these observations show which steps actually ran.
For this example, the table sets expected outcomes for users who are already authenticated. It assumes no project configuration overrides the default validation status and that the specific operation returns 403 when access is denied. Tests should verify that rejected requests create no notes, as well as checking the HTTP status.
Scenario with an authenticated user
Expected status
Persisted effect
No general role, valid JSON
403
No note
Has the role, claim outside scope, valid text
403
No note
Has the role, blank text
422
No note
Has the role, allowed claim, valid text
201
One note on the correct claim
The third row needs an additional case with a claim belonging to another company. That verifies the new ordering when one request has both an input and a permission problem. Add separate tests for malformed JSON, incompatible types, content format, and missing fields. These differ from a valid string that fails NotBlank. For a user without authentication, verify the response defined by the authenticator and firewall rules, including the JSON format the client expects.
Use two companies and users with the same role in the scope test. Change only the claim and confirm that a user from one company cannot gain access to the other company's claim. Also make a request with an expired session. In a Vue application using session cookies, keep CSRF handling appropriate to the application flow. Controller permission checks need to coexist with protection against forged requests that take advantage of browser cookies. The Symfony guide describes how to generate and validate tokens when the flow requires that protection.
Before opening the change, check composer.lock, the installed Symfony components, and the PHP versions running the server and workers. The runtime handling HTTP can differ from the runner's CLI version. The BETA2 announcement provides commands for testing the prerelease. Your team can apply them in a branch and a trial environment, review dependency resolution, and retain the lockfile used in the tests. At the time of this edition, Symfony 8.2's published requirement is PHP 8.4 or later.
A useful trial result includes the error contract observed by Vue, the scope and concurrency test results, and query counts for rejected requests. If the team decides to adopt the feature after the final release, it can rerun the same suite against the approved dependencies. For an endpoint like this one, the most useful evidence shows that an allowed user creates a note on the correct claim and that every rejected request finishes without a write.