Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Demonstrates a simple Symfony REST API with authentication and role-based access control using security.yaml configuration.
// config/packages/security.yaml
security:
encoders:
App\Entity\User:
algorithm: auto
providers:
in_memory:
memory:
users:
admin:
password: 'password'
roles: ['ROLE_ADMIN']
firewalls:
main:
anonymous: true
http_basic: ~
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
// src/Controller/TodoController.php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
class TodoController extends AbstractController {
/**
* @Route("/todos", name="todo_list")
*/
public function list(): JsonResponse {
$todos = ['Task 1', 'Task 2'];
return new JsonResponse($todos);
}
}Symfony Security is a robust component of the Symfony PHP framework that provides authentication, authorization, and secure user management features for web applications.
Origin & Creator
Developed by Fabien Potencier and the Symfony core team, maintained as part of Symfony framework since its early versions.
Industrial Note
Widely used in enterprise PHP applications requiring robust authentication, access control, and compliance with security standards.