craftcamp/abac-bundle
Symfony bundle integrating CraftCamp’s PHP ABAC library for attribute-based access control. Define policy rules based on user and resource attributes (roles as attributes too) and enforce permissions via a security service that can return denied attributes for debugging.
AppKernel) may need adaptation.AppKernel; Laravel would need a service provider to register config files (attributes.yml, policy_rules.yml).craftcamp_abac.security service must be bound to Laravel’s container (e.g., via bind() in a service provider).KernelEvents) would map to Laravel’s middleware or events (e.g., Authorizing).AttributeInterface or expose attributes via getters/setters. Laravel’s eloquent models or DTOs can adapt with minimal effort.CacheManager.| Risk Area | Severity | Mitigation |
|---|---|---|
| Symfony-Specific Abstractions | Medium | Abstract bundle logic into a Laravel-compatible facade (e.g., AbacFacade). |
| Configuration Complexity | High | Provide Laravel-specific config helpers (e.g., config('abac.rules')). |
| Performance Overhead | Low | Enable caching via Laravel’s cache system. |
| Attribute Mapping | Medium | Use traits or interfaces to standardize user/resource attribute access. |
| Middleware Integration | Low | Create a Laravel middleware to enforce ABAC rules globally. |
AppKernel with a Laravel Service Provider (AbacServiceProvider) to register:
attributes.yml, policy_rules.yml).Abac service (bound to Laravel’s container).AbacFacade to simplify usage:
use Illuminate\Support\Facades\Abac;
$access = Abac::enforce('rule_name', $user, $resource);
AbacMiddleware to enforce rules on routes:
Route::middleware([AbacMiddleware::class])->group(function () {
// Protected routes
});
HasAbacAttributes trait to auto-map attributes:
class User extends Model {
use HasAbacAttributes;
protected $abacAttributes = ['age', 'department'];
}
HttpKernel (if using Lumen/Symfony bridge).AbacServiceProvider and AbacFacade.ConfigurationInterface with Laravel’s config system.| Laravel Feature | Compatibility | Workaround |
|---|---|---|
| Service Container | High (DI bindings) | Use bind() in AbacServiceProvider. |
| Eloquent Models | Medium (needs trait/interface) | Implement AttributeInterface or use getters. |
| Middleware | High | Create AbacMiddleware. |
| Caching | High (supports Redis, file, etc.) | Configure via cache_options in config. |
| Events | Medium (Symfony events → Laravel events) | Map KernelEvents to Authorizing events. |
| Artisan Commands | Low (Symfony-specific) | Rebuild as Laravel commands. |
composer require craftcamp/abac-bundle.php artisan vendor:publish --tag=abac-config.attributes.yml (user/resource schemas).policy_rules.yml (e.g., document_edit_rule).AbacServiceProvider.AbacFacade for easy access.dd($access) to inspect rejected attributes (debugging tool).owner_id == user_id").rejected_attributes, aiding troubleshooting.user.department) may require N+1 queries; use eager loading.user.has_license) for frequent checks.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Misconfigured Rules | Silent denials (403) |
How can I help you explore Laravel packages today?