nette/security
Security utilities for Nette apps: authentication and authorization helpers, user identity and roles, access control checks, and related infrastructure for building secure login flows and protecting resources with a consistent API.
User, Authenticator, and Authorizator can be adapted to Laravel’s ecosystem with minimal abstraction.Gate and Policy systems but offer more granularity (e.g., resource-level permissions) without requiring custom middleware for every use case.SessionStorage, CookieStorage) can replace Laravel’s default session handling for auth, but database-backed sessions (Laravel’s default) require a custom adapter.Auth facade, session drivers, or CSRF protection.auth.attempting, auth.loggedOut) is not natively integrated.Passwords class (BCrypt by default), which can coexist with Laravel’s Hash helper but may require duplication.Nette\Security\User to Laravel’s Auth facade via a custom guard.Authenticator interfaces to wrap Laravel’s UserProvider or Guard.Role/Resource to Laravel’s Gate definitions.User::isAllowed().SessionStorage/CookieStorage is non-trivial and may conflict with Laravel’s session lifecycle (e.g., start()/regenerate()).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Laravel integration | High | Build a thin adapter layer (e.g., NetteAuthServiceProvider, NetteAuthMiddleware) to bridge gaps. |
| Session conflicts | Medium | Use Laravel’s session only for non-auth data or implement a hybrid storage adapter. |
| Password hashing | Low | Standardize on Laravel’s Hash helper and treat Nette’s Passwords as a secondary utility. |
| BC breaks | Medium | Pin to v3.2.x (stable) and test against Laravel’s PHP 8.1+ requirements. |
| Performance | Low | Benchmark User::isAllowed() vs. Laravel’s Gate::allows(); cache ACL checks if needed. |
| Testing | Medium | Write integration tests for auth flows, focusing on middleware and service interactions. |
User and Laravel’s Auth::user()?SessionStorage/CookieStorage?auth:timeout) vs. Nette’s sliding expiration?Passwords class, or keep using Laravel’s Hash?User::checkPermission() in every controller, or create a global middleware?guest), or can we handle this via Laravel’s Guest middleware?User::isAllowed() for high-traffic routes (e.g., API gateways)?NetteAuthServiceProvider)?Auth contract).Passwords can coexist but may require hash migration).Auth contract compatibility).| Phase | Tasks | Tools/Libraries |
|---|---|---|
| Assessment | Audit current auth stack (Laravel Gates, Policies, middleware). Identify gaps (e.g., missing RBAC, session issues). | php artisan route:list, php artisan gate:list |
| Adapter Layer | Create a custom service provider (NetteAuthServiceProvider) to bind Nette components to Laravel’s container. |
Laravel’s ServiceProvider, AuthManager, Guard |
| Auth Integration | Replace Auth::attempt() with Authenticator; bind User to Laravel’s Auth facade. |
Nette\Security\User, Nette\Security\Authenticator |
| ACL Integration | Build middleware to short-circuit Laravel’s auth when using Nette’s User::isAllowed(). Map roles/resources to Laravel’s Gates. |
Laravel’s Middleware, Gate |
| Session Strategy | Decide: Hybrid (Laravel sessions + Nette storage) or Full Switch (Nette’s SessionStorage). Implement custom session driver if needed. |
Laravel’s SessionManager, Nette\Security\SessionStorage |
| Password Sync | Migrate existing hashes to Nette’s Passwords class or wrap Laravel’s Hash in a compatibility layer. |
Laravel’s Hash, Nette\Security\Passwords |
| Testing | Write integration tests for auth flows, ACL checks, and session behavior. | Laravel’s HttpTests, Pest/PHPUnit |
| Deployment | Roll out in stages: Start with auth, then ACL, then sessions. Monitor for session conflicts or permission denials. | Feature flags, Laravel Forge/Envoyer for zero-downtime deploys |
| Component | Laravel Equivalent | Compatibility Notes |
|---|---|---|
User |
Auth::user() |
Bind Nette\Security\User to Laravel’s Auth facade via a custom guard. |
Authenticator |
UserProvider |
Implement Nette\Security\IAuthenticator to wrap Laravel’s UserProvider. |
Authorizator |
Gate/Policy |
Use middleware to short-circuit Laravel’s auth when checking Nette’s ACL. |
SessionStorage |
Session |
Low compatibility: Conflicts with Laravel’s session lifecycle. Use a hybrid approach or custom driver. |
Passwords |
Hash |
Medium compatibility: Can coexist but may require hash migration. |
Identity |
Auth::guard()->user() |
Map Nette’s Identity to Laravel’s User model. |
| Middleware | Laravel Middleware |
How can I help you explore Laravel packages today?