oneup/acl-bundle
Symfony bundle that provides a Doctrine-backed ACL layer for securing application objects. It integrates with Symfony's security component and offers helpers for checking and managing user permissions in controllers and templates, simplifying fine-grained object-level access control.
Install and register
composer require oneup/acl-bundle
// config/bundles.php
Oneup\AclBundle\OneupAclBundle::class => ['all' => true],
Make Symfony's ACL component usable first. The bundle is a management layer, not a replacement, so the underlying security.acl config must be in place before anything works:
# config/packages/security.yaml
security:
acl:
connection: default
Then create the ACL tables (bin/console init:acl, or let the Doctrine schema listener create acl_classes, acl_entries, acl_object_identities, acl_object_identity_ancestors, acl_security_identities).
Tell the bundle about your users. It needs to translate a domain user into a UserSecurityIdentity, and it ships with an adapter for the common user bundle of the era — you point the config at that service, or write a small adapter around your own User class. This is the one piece of glue you will almost certainly have to customize.
Where to look first: DependencyInjection/Configuration.php in the bundle (the authoritative config tree for your installed version), Resources/config/services.xml (the oneup_acl.* service ids), and the Admin/ or Controller/ directory — that is the ACL management UI. Use bin/console debug:container oneup and debug:container --tag=sonata.admin to see what actually got registered before you write any code against guessed service ids.
First real use case: open the ACL admin UI for a record (a Post, an Order, anything you store a DomainObjectInterface or plain entity for), grant VIEW/EDIT/OWNER to a user or role, then in a controller assert $this->denyAccessUnlessGranted('EDIT', $post) and in Twig {% if is_granted('VIEW', post) %}. If that loop works, the plumbing is correct.
Grant on creation, not in the UI. The most valuable day-to-day pattern is seeding ACLs from domain events, so records are never orphaned without an owner:
// Doctrine listener on postPersist
$oid = ObjectIdentity::fromDomainObject($post);
$acl = $this->aclProvider->createAcl($oid);
$sid = UserSecurityIdentity::fromAccount($post->getAuthor());
$acl->insertObjectAce($sid, MaskBuilder::MASK_OWNER);
$this->aclProvider->updateAcl($acl);
Use the bundle's manager service instead of hand-rolling the mutable provider. Look for the Manager/ classes and the oneup_acl manager service; wrapping grant/revoke/setPermission calls there keeps the bundle's object-identity handling and cache invalidation consistent between your code and the admin UI. Dropping down to security.acl.provider for bulk work is fine, but don't mix the two on the same object in the same request without a flush in between.
Admin UI as the operator-facing surface, code as the policy. A healthy division: your code creates the initial OWNER ACE and enforces checks; the bundle's UI lets trusted users add VIEW/EDIT grants. Do not let business-critical rules live only in the UI — they become invisible to code review and untestable.
Integration points:
isGranted('EDIT', $post)) rather than in query logic, so controllers, templates, and API serializers share one answer.ROLE_ADMIN-style gate; the UI can rewrite any permission on any managed object.ObjectIdentity type mapping or use class-name identities so the UI and code agree on the identity string.Batch/preload for lists. If you render a table of 50 records and check each one, you will generate hundreds of queries. Preload identities through the ACL provider (preloadObjectIdentities / preloadAcls on the mutable provider, or an equivalent batch call in the bundle's manager) before the loop.
UserSecurityIdentity stores the username or the id, whichever your adapter returns. Migrating from username to id, or renaming users, silently invalidates every ACE. Pick one and never change it.Post leaves its acl_object_identities and acl_entries rows behind, and a new record reusing that primary key inherits the old permissions. Add an onDelete/postRemove cleanup or a scheduled purge.ObjectIdentity::fromDomainObject() on a lazy-loaded Doctrine proxy can produce the proxy class name on older versions, creating a second, empty ACL. Use ClassUtils::getClass() semantics when building identities manually.security.acl.connection, the UI will look empty while isGranted works. Keep both pointed at the same entity manager.Resources/ convention or by replacing service definitions in your app config.AclProvider::getAces($sid, $oid, $type) is your ground truth when the UI and isGranted disagree; the mismatch is nearly always a different security identity or a different object identity string, not a broken voter.How can I help you explore Laravel packages today?