SlideShare a Scribd company logo
Love & Loss
A Symfony Security Play
brewcycleportland.com
@kriswallsmith
assetic
Buzz
Spork
Love and Loss: A Symfony Security Play
Love and Loss: A Symfony Security Play
“…the current implementation of the Security
Component is … not easily accessible”
http://www.testically.org/2011/03/14/why-i-gave-up-on-the-symfony2-security-component/
“I would rather see Symfony2 postponed again
or the Security Component removed …
I don’t think it is even near of being usable to
the community outside the core.”
http://www.testically.org/2011/03/14/why-i-gave-up-on-the-symfony2-security-component/
“The past few days I have really be struggling
with the Symfony2 security component.
It is the most complex component of
Symfony2 if you ask me!”
http://blog.vandenbrand.org/2012/06/19/symfony2-authentication-provider-authenticate-against-webservice/
“(I’m) wondering if I should just work around
rather than work with the framework”
https://groups.google.com/forum/#!msg/symfony2/AZpgbEk4Src/73P99zOmq2YJ
Love and Loss: A Symfony Security Play
Love and Loss: A Symfony Security Play
Enhance your
PHPfun!
http://curiouscomedy.org
Love and Loss: A Symfony Security Play
Love and Loss: A Symfony Security Play
HttpKernel
kernel.exception
kernel.request kernel.terminatekernel.controller kernel.view kernel.response
kernel.request kernel.controller kernel.view kernel.response kernel.terminate
kernel.exception
HttpKernel
kernel.request kernel.controller kernel.view kernel.response kernel.terminate
kernel.exception
HttpKernel
HttpKernel
Get the response and get out
kernel.request
Routeretc…
Firewall
Firewall
Just another listener
class YesFirewall
{
public function handle($event)
{
// always say yes
}
}
use SymfonyComponentHttpFoundationResponse;
class NoFirewall
{
public function handle($event)
{
// always say no
$event->setResponse(
new Response('go away', 401)
);
}
}
use SymfonyComponentHttpFoundationResponse;
class PickyFirewall
{
public function handle($event)
{
$request = $event->getRequest();
$user = $request->headers->get('PHP_AUTH_USER');
// only names that start with "Q"
if ('Q' == $user[0]) return;
$event->setResponse(new Response('go away', 401));
}
}
Security Listeners
The firewall’s henchmen
Firewall
Listeners
kernel.request
class Firewall
{
public $listeners = array();
public function handle($event)
{
foreach ($this->listeners as $listener) {
$listener->handle($event);
if ($event->hasResponse()) return;
}
}
}
class YesListener
{
public function handle($event)
{
// always say yes
}
}
use SymfonyComponentHttpFoundationResponse;
class NoListener
{
public function handle($event)
{
// always say no
$event->setResponse(
new Response('go away', 401)
);
}
}
use SymfonyComponentHttpFoundationResponse;
class PickyListener
{
public function handle($event)
{
$request = $event->getRequest();
$user = $request->headers->get('PHP_AUTH_USER');
// only names that start with "Q"
if ('Q' == $user[0]) return;
$event->setResponse(new Response('go away', 401));
}
}
Authentication
Are you who you say you are?
Authorization
Are you allowed to ____?
Tokens
The Language of Security
Authentication Listeners
Map from request to token
Request
Response (?) Token
CoreHTTP
Love and Loss: A Symfony Security Play
Love and Loss: A Symfony Security Play
Authentication
Listener A
Authentication
Listener B
Authentication
Manager
Firewall
class AuthenticationListener
{
public $authMan, $context;
public function handle($e)
{
$r = $e->getRequest();
$u = $r->headers->get('PHP_AUTH_USER');
$t = new AnonToken($u);
$t = $this->authMan->authenticate($t);
$this->context->setToken($t);
}
}
class AuthenticationManager
{
public function authenticate($t)
{
// always say no
}
}
class AuthenticationManager
{
public function authenticate($t)
{
// always say yes
return new AuthToken($t->getUser());
}
}
class AuthenticationManager
{
public function authenticate($t)
{
$u = $t->getUser();
// only names that start with "Q"
if ('Q' == $u[0]) {
return new AuthToken($u);
}
}
}
Authentication Manager
Responsible for authenticating
the token
Authentication Providers
Do the actual authentication work
User
Providers
Authentication
Providers
Authentication
Listener A
Authentication
Listener B
Authentication
Manager
User Providers
Access the repository of users
class AuthenticationManager
{
public $providers = array();
public function authenticate($t)
{
foreach ($this->providers as $p) {
if ($p->supports($t)) {
return $p->authenticate($t);
}
}
}
}
class AuthenticationProvider
{
public $up;
public function authenticate($t)
{
$u = $t->getUser();
$u = $this->up->loadUserByUsername($u);
if ($u) return new AuthToken($u);
}
}
class UserProvider
{
public $repo;
public function loadUserByUsername($u)
{
return ($this->repo->find(array(
'username' => $u,
)));
}
}
Authentication
Authentication Listeners
• Map client data from request to
token
• Pass token to authentication
manager
• Update state of security context
Authentication Manager
• Responsible for authenticating the
token
• Calls the appropriate
authentication provider
• Handles exceptions
Authentication Providers
• Performs authentication using client
data in the token
• Marks the token as authenticated
• Attaches the user object to the
token
User Providers
• Retrieves the user from the database
Authorization
class AuthorizationListener
{
public function handle($e)
{
// always say yes
}
}
use SymfonyComponentHttpFoundationResponse;
class AuthorizationListener
{
public function handle($e)
{
// always say no
$e->setResponse(
new Response('go away', 403)
);
}
}
Access Map
Looks at a request and determines
token requirements
Access Decision Manager
The gatekeeper
Voters
Decision
Manager
Listener Map
use SymfonyComponentHttpFoundationResponse;
class AccessListener
{
public $context, $map, $decider;
public function handle($e)
{
$r = $e->getRequest();
$t = $this->context->getToken();
$reqs = $this->map->getRequirements($r);
if (!$this->decider->decide($t, $reqs)) {
$e->setResponse(
new Response('go away', 403)
);
}
}
}
class AccessMap
{
public function getRequirements($r)
{
$path = $r->getPathInfo();
if (0 === strpos($path, '/admin')) {
return array('ADMIN');
}
}
}
class AccessDecisionManager
{
public $voters;
public function decide($t, $reqs)
{
foreach ($this->voters as $v) {
if ($v->vote($t, null, $reqs)) {
return true;
}
}
return false;
}
}
class AccessVoter
{
public function vote($t, $obj, $reqs)
{
foreach ($reqs as $req) {
if (!$t->hasAttribute($req)) {
return false;
}
}
return true;
}
}
Authorization
Extension Points
The firewall has many listeners
The authentication manager has
many authentication providers
Which MAY rely on
user providers
The access decision manager
has many voters
Authenticated
Roles
ACL
Questions?
is hiring
Love and Loss: A Symfony Security Play
“Horrible”
“Worst talk ever”
“Go back to high school”
https://joind.in/8665

More Related Content

PDF
Guard Authentication: Powerful, Beautiful Security
PDF
Matters of State
PDF
Design how your objects talk through mocking
PDF
How Kris Writes Symfony Apps
PDF
Symfony & Javascript. Combining the best of two worlds
PDF
How Kris Writes Symfony Apps
PDF
How I started to love design patterns
PDF
How kris-writes-symfony-apps-london
Guard Authentication: Powerful, Beautiful Security
Matters of State
Design how your objects talk through mocking
How Kris Writes Symfony Apps
Symfony & Javascript. Combining the best of two worlds
How Kris Writes Symfony Apps
How I started to love design patterns
How kris-writes-symfony-apps-london

What's hot (20)

PDF
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
PDF
How I started to love design patterns
PDF
Symfony CoP: Form component
PDF
Decoupling with Design Patterns and Symfony2 DIC
PDF
CQRS and Event Sourcing in a Symfony application
PDF
Symfony Messenger (Symfony Live San Francisco)
PDF
Introduction to CQRS and Event Sourcing
PDF
Symfony tips and tricks
PDF
The state of Symfony2 - SymfonyDay 2010
PDF
Symfony components in the wild, PHPNW12
PDF
Doctrine For Beginners
ODP
Symfony2, creare bundle e valore per il cliente
PDF
Decoupling the Ulabox.com monolith. From CRUD to DDD
PPTX
Dealing with Continuous Data Processing, ConFoo 2012
ODP
Rich domain model with symfony 2.5 and doctrine 2.5
PDF
Symfony War Stories
PDF
Symfony2 - WebExpo 2010
PDF
Design Patterns avec PHP 5.3, Symfony et Pimple
KEY
Symfony2 Building on Alpha / Beta technology
PDF
Symfony2 - OSIDays 2010
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
How I started to love design patterns
Symfony CoP: Form component
Decoupling with Design Patterns and Symfony2 DIC
CQRS and Event Sourcing in a Symfony application
Symfony Messenger (Symfony Live San Francisco)
Introduction to CQRS and Event Sourcing
Symfony tips and tricks
The state of Symfony2 - SymfonyDay 2010
Symfony components in the wild, PHPNW12
Doctrine For Beginners
Symfony2, creare bundle e valore per il cliente
Decoupling the Ulabox.com monolith. From CRUD to DDD
Dealing with Continuous Data Processing, ConFoo 2012
Rich domain model with symfony 2.5 and doctrine 2.5
Symfony War Stories
Symfony2 - WebExpo 2010
Design Patterns avec PHP 5.3, Symfony et Pimple
Symfony2 Building on Alpha / Beta technology
Symfony2 - OSIDays 2010
Ad

Viewers also liked (20)

PDF
The Wonderful World of Symfony Components
PDF
Get Soaked - An In Depth Look At PHP Streams
ODP
Elastic Searching With PHP
PDF
Diving deep into twig
PDF
Techniques d'accélération des pages web
PDF
Automation using-phing
ODP
PHP5.5 is Here
PPTX
Electrify your code with PHP Generators
PDF
The quest for global design principles (SymfonyLive Berlin 2015)
PDF
Top tips my_sql_performance
PDF
Mocking Demystified
PDF
Understanding Craftsmanship SwanseaCon2015
PDF
Why elasticsearch rocks!
PDF
Si le tdd est mort alors pratiquons une autopsie mix-it 2015
PDF
Writing infinite scalability web applications with PHP and PostgreSQL
PDF
L'ABC du BDD (Behavior Driven Development)
PDF
Caching on the Edge
PDF
Behat 3.0 meetup (March)
PDF
TDD with PhpSpec - Lone Star PHP 2016
PDF
Performance serveur et apache
The Wonderful World of Symfony Components
Get Soaked - An In Depth Look At PHP Streams
Elastic Searching With PHP
Diving deep into twig
Techniques d'accélération des pages web
Automation using-phing
PHP5.5 is Here
Electrify your code with PHP Generators
The quest for global design principles (SymfonyLive Berlin 2015)
Top tips my_sql_performance
Mocking Demystified
Understanding Craftsmanship SwanseaCon2015
Why elasticsearch rocks!
Si le tdd est mort alors pratiquons une autopsie mix-it 2015
Writing infinite scalability web applications with PHP and PostgreSQL
L'ABC du BDD (Behavior Driven Development)
Caching on the Edge
Behat 3.0 meetup (March)
TDD with PhpSpec - Lone Star PHP 2016
Performance serveur et apache
Ad

Similar to Love and Loss: A Symfony Security Play (20)

PDF
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
PDF
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
PDF
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
PDF
オレオレSecurityバンドル作っちゃいました
PDF
Symfony 4 Workshop - Limenius
KEY
Phpne august-2012-symfony-components-friends
PDF
Great Developers Steal
PDF
Unittests für Dummies
PPTX
Code generation for alternative languages
PDF
JavaFest. Nanne Baars. Web application security for developers
PDF
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
PDF
Better Testing With PHP Unit
PDF
JavaZone 2017 - The Hitchhiker’s guide to Java class reloading
PDF
PhpUnit - The most unknown Parts
PDF
Isolated development in python
PDF
Php unit the-mostunknownparts
PDF
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
PDF
Oliver hookins puppetcamp2011
PDF
Symfony: Your Next Microframework (SymfonyCon 2015)
KEY
Android workshop
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
オレオレSecurityバンドル作っちゃいました
Symfony 4 Workshop - Limenius
Phpne august-2012-symfony-components-friends
Great Developers Steal
Unittests für Dummies
Code generation for alternative languages
JavaFest. Nanne Baars. Web application security for developers
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
Better Testing With PHP Unit
JavaZone 2017 - The Hitchhiker’s guide to Java class reloading
PhpUnit - The most unknown Parts
Isolated development in python
Php unit the-mostunknownparts
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
Oliver hookins puppetcamp2011
Symfony: Your Next Microframework (SymfonyCon 2015)
Android workshop

More from Kris Wallsmith (13)

PDF
Unleash the Power of Symfony Messenger
PDF
The View From Inside
PDF
Drupal, meet Assetic
PDF
Assetic (Zendcon)
PDF
Assetic (OSCON)
PDF
Assetic (Symfony Live Paris)
PDF
Introducing Assetic (NYPHP)
PDF
Introducing Assetic: Asset Management for PHP 5.3
PDF
Doctrine MongoDB ODM (PDXPHP)
PDF
Advanced symfony Techniques
PDF
A Practical Introduction to Symfony2
PDF
Symfony 2
PDF
Symfony in the Cloud
Unleash the Power of Symfony Messenger
The View From Inside
Drupal, meet Assetic
Assetic (Zendcon)
Assetic (OSCON)
Assetic (Symfony Live Paris)
Introducing Assetic (NYPHP)
Introducing Assetic: Asset Management for PHP 5.3
Doctrine MongoDB ODM (PDXPHP)
Advanced symfony Techniques
A Practical Introduction to Symfony2
Symfony 2
Symfony in the Cloud

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation theory and applications.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Machine learning based COVID-19 study performance prediction
Spectral efficient network and resource selection model in 5G networks
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Diabetes mellitus diagnosis method based random forest with bat algorithm
20250228 LYD VKU AI Blended-Learning.pptx
Understanding_Digital_Forensics_Presentation.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Advanced methodologies resolving dimensionality complications for autism neur...
The AUB Centre for AI in Media Proposal.docx
Unlocking AI with Model Context Protocol (MCP)
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Network Security Unit 5.pdf for BCA BBA.
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Electronic commerce courselecture one. Pdf
Encapsulation theory and applications.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Per capita expenditure prediction using model stacking based on satellite ima...
Machine learning based COVID-19 study performance prediction

Love and Loss: A Symfony Security Play