Get Configured Firewalls using Console Command in Symfony 7

Get Configured Firewalls using Console Command in Symfony 7

Symfony framework provides built-in commands that allow to debug various application parts. This tutorial explains how to use console command to get configured firewalls in Symfony 7 application.

Let's say we have the following security.yaml file which defines two firewalls dev and main:

config/packages/security.yaml

security:
  providers:
    in_memory_users:
      memory: ~
  firewalls:
    dev:
      pattern: ^/(_(profiler|wdt)|css|images|js)/
      security: false
    main:
      pattern: ^/
      http_basic: ~

The debug:firewall command can be used to display the firewalls that are configured in Symfony application.

php bin/console debug:firewall

Output:

Firewalls 
=========

 The following firewalls are defined:
 * dev
 * main

To get detailed information about a specific firewall, its name can be provided as argument.

php bin/console debug:firewall main

A part of the output:

Firewall "main" 
===============

 ----------------------- -------------------------------------------------  
  Option                  Value                                           
 ----------------------- -------------------------------------------------
  Name                    main
  Context                 main
  Lazy                    No
  Stateless               No
  User Checker            security.user_checker
  Provider                security.user.provider.concrete.in_memory_users
...

The --events option can be used to display events and event listeners related with specific firewall.

php bin/console debug:firewall main --events

A part of the output:

Firewall "main" 
===============

 ----------------------- -------------------------------------------------  
  Option                  Value                                           
 ----------------------- -------------------------------------------------
  Name                    main
...

Event listeners for firewall "main"
===================================

"Symfony\Component\Security\Http\Event\LoginSuccessEvent" event 
---------------------------------------------------------------

 ------- -------------------------------------------------------------------------------------------- ----------
  Order   Callable                                                                                     Priority 
 ------- -------------------------------------------------------------------------------------------- ----------
  #1      Symfony\Component\Security\Http\EventListener\SessionStrategyListener::onSuccessfulLogin()   0
  #2      Symfony\Component\Security\Http\EventListener\PasswordMigratingListener::onLoginSuccess()    0
 ------- -------------------------------------------------------------------------------------------- ----------
...

Leave a Comment

Cancel reply

Your email address will not be published.