egulias/security-debug-command-bundle
Installation:
composer require egulias/security-debug-command-bundle
Add the bundle to config/bundles.php:
Egulias\SecurityDebugCommandBundle\EguliasSecurityDebugCommandBundle::class => ['all' => true],
First Use Case:
Run the security:debug:firewalls command to inspect firewall configurations:
php bin/console security:debug:firewalls /login main anonymous
Replace /login, main, and anonymous with your target URI, firewall name, and user type (e.g., user).
EguliasSecurityDebugCommandBundle/Command/ for available commands and their logic.security:debug:voters command for voter inspection, especially if authorization issues arise.Debugging Access Denied Issues:
Use security:debug:voters to inspect why a user is being denied access:
php bin/console security:debug:voters /admin user ROLE_ADMIN
VotersInterface::ACCESS_GRANTED).Firewall Configuration Validation: Verify firewall mappings and listeners with:
php bin/console security:debug:firewalls /api authenticated
security.yaml to ensure URIs and firewalls align.ACL Debugging (if enabled):
Use security:debug:acl_voters or security:debug:acl_object to inspect ACL permissions:
php bin/console security:debug:acl_object /object/123 MASK_EDIT
MASK_OWNER, MASK_EDIT) to validate object-level permissions.Symfony Events:
if (!$this->isDebugging())) in your listeners.EventDispatcher to conditionally skip logic:
if (!$event->isDebug()) { /* ... */ }
Custom Voters:
AbstractVote or implement VoterInterface and test with:
php bin/console security:debug:voters /custom-route user ROLE_CUSTOM
supportsAttribute() and voteOnAttribute() methods to ensure your voter logic matches the debug output.Role Hierarchy:
security:debug:voters:
php bin/console security:debug:voters /admin user ROLE_USER ROLE_ADMIN
security.yaml role hierarchy (e.g., role_hierarchy: { ROLE_ADMIN: ROLE_USER }).Token Impersonation:
TokenStorage service temporarily:
$this->container->get('security.token_storage')->setToken($realToken);
Double Event Firing:
public function onKernelRequest(GetResponseEvent $event) {
if (!$event->isDebug()) {
// Your side-effect logic here
}
}
Outdated Output:
symfony/security-bundle).symfony/debug-bundle as an alternative for modern Symfony versions.ACL Limitations:
acl_voters, acl_object) may not work if ACL is not properly configured.symfony/security-acl is installed and configured in security.yaml:
security:
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
acl:
connection: default
Token Security Warning:
username: admin should be a test user).Voter Logic:
ACCESS_ABSTAIN, the next voter in the chain decides. Use security:debug:voters to trace the chain:
php bin/console security:debug:voters /route user ROLE_TEST --verbose
Firewall Mismatches:
/login vs /login/).security.yaml (first match wins).Performance:
--no-debug flag to skip verbose output:
php bin/console security:debug:voters /route user ROLE_TEST --no-debug
Custom Commands:
EguliasSecurityDebugCommandBundle\Command\DebugVotersCommand).Custom Voters/Listeners:
config/services.yaml:
services:
App\Security\CustomDebugVoter:
tags: { name: security.voter }
arguments: ['@security.token_storage']
Event Subscribers:
public static function getSubscribedEvents() {
return [
KernelEvents::REQUEST => 'onDebugRequest',
];
}
public function onDebugRequest(GetResponseEvent $event) {
if ($event->isDebug()) {
// Modify debug behavior
}
}
DataCollector Integration:
config/packages/dev/security.yaml includes:
security:
debug: true
How can I help you explore Laravel packages today?