security core
v7.2.0
การรักษาความปลอดภัยจัดเตรียมโครงสร้างพื้นฐานสำหรับระบบการอนุญาตที่ซับซ้อน ซึ่งทำให้สามารถแยกตรรกะการอนุญาตจริงออกจากสิ่งที่เรียกว่าผู้ให้บริการผู้ใช้ที่เก็บข้อมูลประจำตัวของผู้ใช้ได้อย่างง่ายดาย
composer require symfony/security-core
use Symfony Component Security Core Authentication AuthenticationTrustResolver ;
use Symfony Component Security Core Authentication Token UsernamePasswordToken ;
use Symfony Component Security Core Authorization AccessDecisionManager ;
use Symfony Component Security Core Authorization Voter AuthenticatedVoter ;
use Symfony Component Security Core Authorization Voter RoleVoter ;
use Symfony Component Security Core Authorization Voter RoleHierarchyVoter ;
use Symfony Component Security Core Exception AccessDeniedException ;
use Symfony Component Security Core Role RoleHierarchy ;
$ accessDecisionManager = new AccessDecisionManager ([
new AuthenticatedVoter ( new AuthenticationTrustResolver ()),
new RoleVoter (),
new RoleHierarchyVoter ( new RoleHierarchy ([
' ROLE_ADMIN ' => [ ' ROLE_USER ' ],
]))
]);
$ user = new App Entity User (...);
$ token = new UsernamePasswordToken ( $ user , ' main ' , $ user -> getRoles ());
if (! $ accessDecisionManager -> decide ( $ token , [ ' ROLE_ADMIN ' ])) {
throw new AccessDeniedException ();
}
องค์ประกอบความปลอดภัยสำหรับ Symfony 7.1 ได้รับการสนับสนุนโดย SymfonyCasts
เรียนรู้ Symfony เร็วขึ้นด้วยการดูโปรเจ็กต์จริงที่ถูกสร้างขึ้นและเขียนโค้ดไปพร้อมกับพวกเขา SymfonyCasts เชื่อมช่องว่างการเรียนรู้ดังกล่าว โดยนำเสนอวิดีโอบทช่วยสอนและความท้าทายในการเขียนโค้ด รหัสเปิด!
ช่วย Symfony ด้วยการสนับสนุนการพัฒนา!