/symfony-hexagonal:symfony-security-votersfrom symfony-hexagonal
Implements Symfony security with #[IsGranted] on every endpoint, role hierarchy, and resource voters with subject loading. Works with hexagonal architecture on Symfony 6.4-8.x.
Ships in symfony-hexagonal. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are an expert in Symfony security with Voters pattern within hexagonal architecture.
| Feature | Requires | Fallback |
|---|---|---|
#[IsGranted('ATTR', subject: 'argName')] | Symfony 6.2 | AuthorizationCheckerInterface::isGranted() |
?Vote $vote = null 4th voter parameter (reasons in profiler / logs) | Symfony 7.3 (part of the signature in 8.0) | Declare it anyway: harmless before 7.3 |
#[IsGranted] methods: option, #[CurrentUser] union types | Symfony 7.4 | separate routes / single user class |
#[IsGranted] with a static closure | Symfony 7.3 + PHP 8.5 | Voter |
subject: new Expression('...') | Symfony 6.2 | string argument name |
UserInterface::eraseCredentials() | deprecated 7.3 | do not keep plain passwords on the user |
No endpoint is publicly accessible without explicit #[IsGranted] or Voter check. Public endpoints use #[IsGranted('PUBLIC_ACCESS')] so the decision is visible.
#[Route('/api/users', methods: ['GET'])]
#[IsGranted('ROLE_USER_LIST')] // ALWAYS required
public function list(): JsonResponse { /* ... */ }
Define roles in security.yaml:
security:
role_hierarchy:
ROLE_ADMIN: [ROLE_USER_CREATE, ROLE_USER_EDIT, ROLE_USER_DELETE, ROLE_USER_LIST, ROLE_USER_VIEW]
ROLE_MANAGER: [ROLE_USER_LIST, ROLE_USER_VIEW, ROLE_ORDER_MANAGE]
ROLE_USER: [ROLE_USER_VIEW]
ROLE_{MODULE}_{ACTION}ROLE_USER_CREATE, ROLE_ORDER_VIEW, ROLE_REPORT_GENERATEROLE_ prefix: ORDER_EDIT#[IsGranted]#[IsGranted('ROLE_USER_CREATE')]
public function create(): JsonResponse { /* ... */ }
When authorization depends on the resource ("can this user edit THIS order?"). Controllers only know the ID, so the voter receives the ID and loads what it needs through a read port: Presentation never touches Domain entities.
namespace App\Infrastructure\{Module}\Security;
use App\Domain\{Module}\Port\{Entity}ReadRepositoryInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Vote;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/** @extends Voter<string, string> */
final class {Entity}Voter extends Voter
{
public const VIEW = '{MODULE}_VIEW';
public const EDIT = '{MODULE}_EDIT';
public function __construct(
private readonly {Entity}ReadRepositoryInterface $repository,
) {
}
protected function supports(string $attribute, mixed $subject): bool
{
return in_array($attribute, [self::VIEW, self::EDIT], true) && is_string($subject);
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token, ?Vote $vote = null): bool
{
$view = $this->repository->findById($subject);
if ($view === null) {
$vote?->addReason('Resource not found');
return false;
}
return match ($attribute) {
self::VIEW, self::EDIT => $view->ownerId === $token->getUserIdentifier(),
default => false,
};
}
}
#[Route('/{id}', methods: ['PUT'])]
#[IsGranted('{MODULE}_EDIT', subject: 'id')] // 'id' = controller argument name
public function update(string $id, #[MapRequestPayload] Update{Entity}Request $request): JsonResponse
{
$this->commandBus->dispatch(new Update{Entity}($id /* , ... */));
return $this->success(null);
}
Use the attribute string ('ORDER_EDIT') in Presentation instead of importing the voter class from Infrastructure.
See references/ for detailed guides:
voter-patterns.md - Full voter examples and testingrole-hierarchy.md - Role hierarchy design, security.yaml, security user adapterWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub aligundogdu/symfony-hexagonal-skill --plugin symfony-hexagonal10 skills in this plugin
/symfony-api-responseSymfony REST API response standard {result, error, extra, status}: thin controllers, #[MapRequestPayload] / #[MapQueryString] request DTOs, ApiResponseTrait, exception subscriber that unwraps Messenger HandlerFailedException, validation error format, debug mode. Use when: API, endpoint, controller, response, error handling, JSON, REST, API response, exception subscriber, HTTP, request DTO/symfony-cqrs-handlersSymfony CQRS with Messenger: commands, queries, handlers, command.bus / query.bus / event.bus configuration, typed bus wrappers, HandlerFailedException unwrapping, read ports and pagination, use cases. Works on Symfony 6.4, 7.x, 8.x. Use when: command, query, handler, CQRS, bus, use case, command handler, query handler, message bus, HandleTrait, HandledStamp/symfony-doctrine-persistenceDoctrine persistence for Symfony hexagonal architecture (ORM 2.x/3.x, DBAL 3/4, DoctrineBundle 2/3): repository adapters, XML mapping in Infrastructure, embeddables, enums, custom DBAL types, native lazy objects, migrations, transactions, read models with DBAL QueryBuilder, strict no-native-SQL rule. Use when: doctrine, repository, persistence, database, mapping, migration, ORM, entity manager, DBAL, transaction, query builder, pagination/symfony-domain-modelingSymfony DDD domain modeling in pure PHP: entities, aggregates, value objects, domain events, domain exceptions, ID generation ports, PHP 8.2-8.5 modeling features (readonly, private(set), clone with). Use when: entity, value object, domain event, aggregate, domain exception, domain model, domain logic, business rule, invariant, enum status/symfony-hexagonal-architectureSymfony hexagonal architecture (ports & adapters) setup for Symfony 6.4 LTS, 7.4 LTS and 8.x: project structure, module scaffolding, layer responsibilities, dependency rules, version compatibility, progressive refactoring of legacy code. Use when: architecture, module, layer, hexagonal, scaffold, project structure, directory structure, new project, new module, bounded context, deptrac, Symfony version, upgrade/symfony-messenger-asyncSymfony Messenger async processing and Symfony Scheduler instead of cron: transports, routing (#[AsMessage] 7.2+), retry with backoff and jitter, failure transport, idempotency keys, DeduplicateStamp (7.3+), workers, supervisor, scheduled commands with stateful/locked schedules. Use when: messenger, async, queue, retry, scheduler, background job, worker, transport, message queue, cron, scheduled task, idempotency, deduplicationOther plugins' skills for the same job