
ความปลอดภัยขั้นสูง
Custom authenticator, voter, security expression, การป้องกัน CSRF, การป้องกัน XSS, rate limiting, การเสริมความแข็งแกร่งในโปรดักชัน, การตั้งค่า JWT/OAuth2 ที่ผิดพลาด
1ใน Symfony 6+ custom authenticator ต้องใช้งานอินเทอร์เฟซใด?
ใน Symfony 6+ custom authenticator ต้องใช้งานอินเทอร์เฟซใด?
คำตอบ
ใน Symfony 6+ custom authenticator ต้องใช้งาน AuthenticatorInterface จากคอมโพเนนต์ Security HTTP อินเทอร์เฟซนี้กำหนดเมธอด supports(), authenticate(), onAuthenticationSuccess(), onAuthenticationFailure() และ createToken() ที่เป็นทางเลือก โดยมาแทนที่ระบบ Guard เดิมที่ใช้ใน Symfony 4/5
2เมธอด supports() ใน custom authenticator มีบทบาทอะไร?
เมธอด supports() ใน custom authenticator มีบทบาทอะไร?
คำตอบ
เมธอด supports() จะกำหนดว่า authenticator ควรจัดการคำขอปัจจุบันหรือไม่ โดยจะรับ Request และคืนค่าบูลีน หากเป็น true เมธอด authenticate() จะถูกเรียก ตามด้วย onAuthenticationSuccess() หรือ onAuthenticationFailure() ซึ่งทำให้สามารถมี authenticator ที่ทำงานอยู่หลายตัวบน firewall เดียวกัน โดยแต่ละตัวจัดการประเภทการยืนยันตัวตนที่เฉพาะเจาะจง
3เมธอด authenticate() ของ custom authenticator ควรคืนค่าอะไรเมื่อสำเร็จ?
เมธอด authenticate() ของ custom authenticator ควรคืนค่าอะไรเมื่อสำเร็จ?
คำตอบ
เมธอด authenticate() ต้องคืนค่าออบเจ็กต์ Passport ที่มี UserBadge (ตัวระบุผู้ใช้) และ credentials badge นอกจากนี้ Passport ยังสามารถมี badge เพิ่มเติม เช่น CsrfTokenBadge หรือ RememberMeBadge ได้ จากนั้น Symfony จะใช้ Passport นี้เพื่อสร้าง token การยืนยันตัวตนและโหลดผู้ใช้ผ่าน UserProvider
จะกำหนด Voter แบบกำหนดเองเพื่อควบคุมการเข้าถึงทรัพยากรเฉพาะได้อย่างไร?
กลยุทธ์ AccessDecisionManager แบบใดที่แนะนำสำหรับแอปพลิเคชันที่ต้องการความปลอดภัยที่เข้มงวด?
+19 คำถามสัมภาษณ์
หัวข้อสัมภาษณ์ Symfony อื่นๆ
PHP สมัยใหม่ (8.1+)
พื้นฐาน Symfony
Routing & Controllers
Twig & Templates
พื้นฐาน Doctrine ORM
ฟอร์ม Symfony
การตรวจสอบความถูกต้องของข้อมูล
Dependency Injection & Services
Security & Authentication
Doctrine ขั้นสูง
API Platform
Serializer Component
Events & Event Subscribers
Console & Commands
Messenger Component
HTTP Client
Cache & ประสิทธิภาพ
Workflow Component
Testing Symfony
Mailer Component
การแปลและ i18n
EasyAdmin Bundle
สถาปัตยกรรม Symfony
ประสิทธิภาพและการเพิ่มประสิทธิภาพ
Custom Bundles
Microservices ด้วย Symfony
Real-time & WebSockets
Deployment & DevOps
เชี่ยวชาญ Symfony สำหรับการสัมภาษณ์ครั้งถัดไป
เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์
เริ่มใช้ฟรี