SlideShare a Scribd company logo
Keep It Simple Security (Symfony cafe 28-01-2016)
cystbear
Erlanger
Symfony expert
MongoDB adept
OSS doer
https://twitter.com/1cdecoder
https://github.com/cystbear
http://trinity.ck.ua/
Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)
+ = ❤
Keep It Simple Security (Symfony cafe 28-01-2016)
security.yml
security:
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
form_login:
login_path: /login
check_path: /login_check
provider: fos_userbundle
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user, role: ROLE_USER }
- { path: ^/admin/, role: ROLE_ADMIN }
http://www.xml.com/pub/a/2003/12/17/dive.html
http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html
Good Parts
Token
Listener
Authentication Manager/Provider
Factory
Token
<?php
namespace AppBundleSecurityAuthenticationToken;
use SymfonyComponentSecurityCoreAuthenticationTokenAbstractToken;
class WsseUserToken extends AbstractToken
{
public $created;
public $digest;
public $nonce;
public function __construct(array $roles = array())
{
parent::__construct($roles);
// If the user has roles, consider it authenticated
$this->setAuthenticated(count($roles) > 0);
}
public function getCredentials()
{
return '';
}
}
Listener
<?php
namespace AppBundleSecurityFirewall;
use AppBundleSecurityAuthenticationTokenWsseUserToken;
class WsseListener implements ListenerInterface
{
protected $tokenStorage;
protected $authenticationManager;
public function handle(GetResponseEvent $event)
{
$request = $event->getRequest();
$wsseRegex = '/UsernameToken Username="([^"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/';
if (!$request->headers->has('x-wsse') || 1 !== preg_match($wsseRegex, $request->headers->get('x-wsse'), $matches)) {
return;
}
$token = new WsseUserToken(); $token->setUser($matches[1]); ...
try {
$authToken = $this->authenticationManager->authenticate($token);
$this->tokenStorage->setToken($authToken);
return;
} catch (AuthenticationException $failed) { ... }
$response = new Response();
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$event->setResponse($response);
}
}
Authentication Manager
<?php
namespace AppBundleSecurityAuthenticationProvider;
use AppBundleSecurityAuthenticationTokenWsseUserToken;
class WsseProvider implements AuthenticationProviderInterface
{
private $userProvider;
public function authenticate(TokenInterface $token)
{
$user = $this->userProvider->loadUserByUsername($token->getUsername());
if ($user && $this->validateDigest($token->digest, $token->nonce, $token->created, $user->getPassword())) {
$authenticatedToken = new WsseUserToken($user->getRoles());
$authenticatedToken->setUser($user);
return $authenticatedToken;
}
throw new AuthenticationException('The WSSE authentication failed.');
}
protected function validateDigest($digest, $nonce, $created, $secret)
{ ... }
public function supports(TokenInterface $token)
{
return $token instanceof WsseUserToken;
}
}
Factory
<?php
namespace AppBundleDependencyInjectionSecurityFactory;
use SymfonyBundleSecurityBundleDependencyInjectionSecurityFactorySecurityFactoryInterface;
class WsseFactory implements SecurityFactoryInterface
{
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
{
$providerId = 'security.authentication.provider.wsse.'.$id;
$container
->setDefinition($providerId, new DefinitionDecorator('wsse.security.authentication.provider'))
->replaceArgument(0, new Reference($userProvider))
;
$listenerId = 'security.authentication.listener.wsse.'.$id;
$listener = $container->setDefinition($listenerId, new DefinitionDecorator('wsse.security.authentication.listener'));
return array($providerId, $listenerId, $defaultEntryPoint);
}
public function getPosition()
{ return 'pre_auth'; }
public function getKey()
{ return 'wsse'; }
public function addConfiguration(NodeDefinition $node)
{
}
}
ACE
http://symfony.com/doc/current/cookbook/security/acl.html
Voters
http://symfony.com/doc/current/cookbook/security/voters.html
https://www.youtube.com/watch?v=e7HfW4TgnUY
Voter (1)
<?php
namespace AppBundleSecurity;
use SymfonyComponentSecurityCoreAuthorizationVoterVoter;
class PostVoter extends Voter
{
const VIEW = 'view';
const EDIT = 'edit';
protected function supports($attribute, $subject)
{
if (!in_array($attribute, array(self::VIEW, self::EDIT))) { return false; }
if (!$subject instanceof Post) { return false; }
return true;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof User) { return false; }
$post = $subject;
switch($attribute) {
case self::VIEW: return $this->canView($post, $user);
case self::EDIT: return $this->canEdit($post, $user);
}
throw new LogicException('This code should not be reached!');
}
}
Voter (2)
<?php
private function canView(Post $post, User $user)
{
if ($this->canEdit($post, $user)) { return true; }
return !$post->isPrivate();
}
private function canEdit(Post $post, User $user)
{
return $user === $post->getOwner();
}
}
Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)

More Related Content

What's hot (20)

PDF
Consuming Web Services with Swift and Rx
Guillermo Gonzalez
 
PDF
RESTful web services
Tudor Constantin
 
PDF
Mojolicious. Веб в коробке!
Anatoly Sharifulin
 
ODP
Mojolicious on Steroids
Tudor Constantin
 
KEY
Silex, the microframework
Inviqa
 
PDF
Keeping it Small: Getting to know the Slim Micro Framework
Jeremy Kendall
 
PDF
Bullet: The Functional PHP Micro-Framework
Vance Lucas
 
PDF
Keeping it small - Getting to know the Slim PHP micro framework
Jeremy Kendall
 
KEY
Mojo as a_client
Marcus Ramberg
 
PDF
Mojolicious
Marcos Rebelo
 
ZIP
Web Apps in Perl - HTTP 101
hendrikvb
 
PPT
Slim RedBeanPHP and Knockout
Vic Metcalfe
 
PDF
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
Kana Natsuno
 
PPTX
Paypal REST api ( Japanese version )
Yoshi Sakai
 
PDF
Mojolicious
Lenz Gschwendtner
 
PDF
Developing apps using Perl
Anatoly Sharifulin
 
KEY
And the Greatest of These Is ... Rack Support
Ben Scofield
 
PDF
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
PPTX
Node.js for PHP developers
Andrew Eddie
 
PDF
Great Developers Steal
Ben Scofield
 
Consuming Web Services with Swift and Rx
Guillermo Gonzalez
 
RESTful web services
Tudor Constantin
 
Mojolicious. Веб в коробке!
Anatoly Sharifulin
 
Mojolicious on Steroids
Tudor Constantin
 
Silex, the microframework
Inviqa
 
Keeping it Small: Getting to know the Slim Micro Framework
Jeremy Kendall
 
Bullet: The Functional PHP Micro-Framework
Vance Lucas
 
Keeping it small - Getting to know the Slim PHP micro framework
Jeremy Kendall
 
Mojo as a_client
Marcus Ramberg
 
Mojolicious
Marcos Rebelo
 
Web Apps in Perl - HTTP 101
hendrikvb
 
Slim RedBeanPHP and Knockout
Vic Metcalfe
 
PHP「参照渡しできるよ」(君の考えている参照渡しと同じとは言ってない)
Kana Natsuno
 
Paypal REST api ( Japanese version )
Yoshi Sakai
 
Mojolicious
Lenz Gschwendtner
 
Developing apps using Perl
Anatoly Sharifulin
 
And the Greatest of These Is ... Rack Support
Ben Scofield
 
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
Node.js for PHP developers
Andrew Eddie
 
Great Developers Steal
Ben Scofield
 

Viewers also liked (19)

PDF
Php Security
guest7cf35c
 
PPT
Circo Surrealista
guest07ae47
 
PDF
Vortrag hdi 12-2010
Stephan Raimer
 
PPT
Future Rural Public Services: Can The DIY Approach Work? [Kate Stephen & Cli...
University of the Highlands and Islands
 
PDF
Dr. Patrick Treacy Profile
Dr. Patrick J. Treacy
 
PPTX
How to Improve Your Business Performance with Operational Excellence
Operational Excellence Society
 
PPS
1952
Simon Nazrul
 
PPSX
43 pagpuputol ng tinapay
Iglesia Ng Dios
 
PDF
Towards Full MembershipToEUby2014
PARIS
 
PPT
University Star Media Convergence Studio
mattylynch
 
PDF
El cambio empresarial bajo parámetros ágiles. XSpain2015
Roberto Canales
 
PDF
#doctorbridge So... is this my country? Un paese cosi?
Salvo Fedele
 
PPTX
Back to school 2012
Erik Tjersland
 
PPT
PSICOLOGIA SOCIAL COMO CIENCIA, EVOLUCION HISTORIA, METODOS DE APLICACION
Gisel Milagros Vaderna Martinez
 
PDF
Children story teller
Abby Deng
 
PPTX
VSC Presentation
primeteacher32
 
PPTX
Windows Registry
primeteacher32
 
PDF
Kompletter Studienbericht Social Media Delphi 2012
Fink & Fuchs AG
 
PDF
Rodenstock
Sebastian Franz
 
Php Security
guest7cf35c
 
Circo Surrealista
guest07ae47
 
Vortrag hdi 12-2010
Stephan Raimer
 
Future Rural Public Services: Can The DIY Approach Work? [Kate Stephen & Cli...
University of the Highlands and Islands
 
Dr. Patrick Treacy Profile
Dr. Patrick J. Treacy
 
How to Improve Your Business Performance with Operational Excellence
Operational Excellence Society
 
43 pagpuputol ng tinapay
Iglesia Ng Dios
 
Towards Full MembershipToEUby2014
PARIS
 
University Star Media Convergence Studio
mattylynch
 
El cambio empresarial bajo parámetros ágiles. XSpain2015
Roberto Canales
 
#doctorbridge So... is this my country? Un paese cosi?
Salvo Fedele
 
Back to school 2012
Erik Tjersland
 
PSICOLOGIA SOCIAL COMO CIENCIA, EVOLUCION HISTORIA, METODOS DE APLICACION
Gisel Milagros Vaderna Martinez
 
Children story teller
Abby Deng
 
VSC Presentation
primeteacher32
 
Windows Registry
primeteacher32
 
Kompletter Studienbericht Social Media Delphi 2012
Fink & Fuchs AG
 
Rodenstock
Sebastian Franz
 
Ad

Similar to Keep It Simple Security (Symfony cafe 28-01-2016) (20)

KEY
Phpne august-2012-symfony-components-friends
Michael Peacock
 
PPTX
What mom never told you about bundle configurations - Symfony Live Paris 2012
D
 
PDF
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Ryan Weaver
 
PDF
How Kris Writes Symfony Apps
Kris Wallsmith
 
PDF
Refactoring using Codeception
Jeroen van Dijk
 
PDF
Virtual Madness @ Etsy
Nishan Subedi
 
PPTX
Authenticating and Securing Node.js APIs
Jimmy Guerrero
 
PDF
Doctrine For Beginners
Jonathan Wage
 
PDF
Dependency injection-zendcon-2010
Fabien Potencier
 
PDF
Separation of concerns - DPC12
Stephan Hochdörfer
 
PDF
Symfony components in the wild, PHPNW12
Jakub Zalas
 
KEY
BEAR DI
Akihito Koriyama
 
KEY
Symfony2 Building on Alpha / Beta technology
Daniel Knell
 
PDF
Building Persona: federated and privacy-sensitive identity for the Web (Open ...
Francois Marier
 
PDF
Building Persona: federated and privacy-sensitive identity for the Web (LCA 2...
Francois Marier
 
PDF
Guard Authentication: Powerful, Beautiful Security
Ryan Weaver
 
PDF
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
James Titcumb
 
PDF
How kris-writes-symfony-apps-london
Kris Wallsmith
 
PDF
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
James Titcumb
 
PDF
Persona: in your browsers, killing your passwords
Francois Marier
 
Phpne august-2012-symfony-components-friends
Michael Peacock
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
D
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Ryan Weaver
 
How Kris Writes Symfony Apps
Kris Wallsmith
 
Refactoring using Codeception
Jeroen van Dijk
 
Virtual Madness @ Etsy
Nishan Subedi
 
Authenticating and Securing Node.js APIs
Jimmy Guerrero
 
Doctrine For Beginners
Jonathan Wage
 
Dependency injection-zendcon-2010
Fabien Potencier
 
Separation of concerns - DPC12
Stephan Hochdörfer
 
Symfony components in the wild, PHPNW12
Jakub Zalas
 
Symfony2 Building on Alpha / Beta technology
Daniel Knell
 
Building Persona: federated and privacy-sensitive identity for the Web (Open ...
Francois Marier
 
Building Persona: federated and privacy-sensitive identity for the Web (LCA 2...
Francois Marier
 
Guard Authentication: Powerful, Beautiful Security
Ryan Weaver
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
James Titcumb
 
How kris-writes-symfony-apps-london
Kris Wallsmith
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
James Titcumb
 
Persona: in your browsers, killing your passwords
Francois Marier
 
Ad

More from Oleg Zinchenko (7)

PDF
Erlang (GeekTalks)
Oleg Zinchenko
 
PDF
Welcome to Erlang
Oleg Zinchenko
 
PDF
Erlang/N2O at KNPMeetup 2015
Oleg Zinchenko
 
PDF
DDD on example of Symfony (SfCampUA14)
Oleg Zinchenko
 
PDF
DDD on example of Symfony (Webcamp Odessa 2014)
Oleg Zinchenko
 
PDF
PHP. Trends, implementations, frameworks and solutions
Oleg Zinchenko
 
PDF
Введение в REST API
Oleg Zinchenko
 
Erlang (GeekTalks)
Oleg Zinchenko
 
Welcome to Erlang
Oleg Zinchenko
 
Erlang/N2O at KNPMeetup 2015
Oleg Zinchenko
 
DDD on example of Symfony (SfCampUA14)
Oleg Zinchenko
 
DDD on example of Symfony (Webcamp Odessa 2014)
Oleg Zinchenko
 
PHP. Trends, implementations, frameworks and solutions
Oleg Zinchenko
 
Введение в REST API
Oleg Zinchenko
 

Recently uploaded (20)

PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
PDF
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
PDF
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
PDF
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
PPTX
Wondershare Filmora Crack Free Download 2025
josanj305
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PDF
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
PDF
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
Wondershare Filmora Crack Free Download 2025
josanj305
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 

Keep It Simple Security (Symfony cafe 28-01-2016)