SlideShare a Scribd company logo
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
cystbear
Erlanger
Symfony expert
MongoDB adept
OSS doer
https://twitter.com/1cdecoder
https://github.com/cystbear
http://trinity.ck.ua/
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
+ = ❤
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
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();
}
}
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv

More Related Content

PDF
Security and Mobility - WordCamp Porto 2016
PDF
The Web beyond "usernames & passwords" (OSDC12)
DOCX
PDF
How Kris Writes Symfony Apps
PDF
News of the Symfony2 World
PDF
Practica csv
PDF
Persona: in your browsers, killing your passwords
PDF
An Introduction to Jquery
Security and Mobility - WordCamp Porto 2016
The Web beyond "usernames & passwords" (OSDC12)
How Kris Writes Symfony Apps
News of the Symfony2 World
Practica csv
Persona: in your browsers, killing your passwords
An Introduction to Jquery

What's hot (19)

PDF
How Kris Writes Symfony Apps
DOC
PDF
PhoneGap: Local Storage
PDF
Drupal, meet Assetic
PDF
PythonでJWT生成からボット作成、投稿までやってみた
PPTX
PDF
jQuery: Events, Animation, Ajax
PDF
Your Entity, Your Code
PDF
How to work with legacy code PHPers Rzeszow #2
PDF
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
PDF
How to work with legacy code
PDF
PuppetCamp SEA 1 - Version Control with Puppet
PDF
Pemrograman Web 8 - MySQL
PPTX
HirshHorn theme: how I created it
PDF
Coding website
PDF
Pemrograman Web 9 - Input Form DB dan Session
PDF
Guard Authentication: Powerful, Beautiful Security
PDF
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
PPTX
Building Your First Widget
How Kris Writes Symfony Apps
PhoneGap: Local Storage
Drupal, meet Assetic
PythonでJWT生成からボット作成、投稿までやってみた
jQuery: Events, Animation, Ajax
Your Entity, Your Code
How to work with legacy code PHPers Rzeszow #2
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
How to work with legacy code
PuppetCamp SEA 1 - Version Control with Puppet
Pemrograman Web 8 - MySQL
HirshHorn theme: how I created it
Coding website
Pemrograman Web 9 - Input Form DB dan Session
Guard Authentication: Powerful, Beautiful Security
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Building Your First Widget
Ad

Similar to KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv (20)

KEY
Phpne august-2012-symfony-components-friends
PPTX
What mom never told you about bundle configurations - Symfony Live Paris 2012
 
PDF
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
PDF
Refactoring using Codeception
PDF
Virtual Madness @ Etsy
PPTX
Authenticating and Securing Node.js APIs
PDF
Doctrine For Beginners
PDF
Dependency injection-zendcon-2010
PDF
Separation of concerns - DPC12
PDF
Symfony components in the wild, PHPNW12
KEY
KEY
Symfony2 Building on Alpha / Beta technology
PDF
Building Persona: federated and privacy-sensitive identity for the Web (Open ...
PDF
Building Persona: federated and privacy-sensitive identity for the Web (LCA 2...
PDF
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
PDF
How kris-writes-symfony-apps-london
PDF
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
PDF
Great Developers Steal
PDF
前端MVC 豆瓣说
Phpne august-2012-symfony-components-friends
What mom never told you about bundle configurations - Symfony Live Paris 2012
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Refactoring using Codeception
Virtual Madness @ Etsy
Authenticating and Securing Node.js APIs
Doctrine For Beginners
Dependency injection-zendcon-2010
Separation of concerns - DPC12
Symfony components in the wild, PHPNW12
Symfony2 Building on Alpha / Beta technology
Building Persona: federated and privacy-sensitive identity for the Web (Open ...
Building Persona: federated and privacy-sensitive identity for the Web (LCA 2...
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
How kris-writes-symfony-apps-london
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Great Developers Steal
前端MVC 豆瓣说
Ad

More from Grossum (7)

PPTX
PHP7 - Предрелизный обзор
PPTX
Employee Motivation - Grossum
PDF
Symfony Dependency Injection (DI) in Practice - Denis Malavsky, Grossum
PDF
Doctrine Tips and Tricks - Ilya Antipenko, Grossum
PDF
Grossum Software Outsourcing
PDF
Grossum: Инструменты управления IT компанией
PPTX
Why Drupal?
PHP7 - Предрелизный обзор
Employee Motivation - Grossum
Symfony Dependency Injection (DI) in Practice - Denis Malavsky, Grossum
Doctrine Tips and Tricks - Ilya Antipenko, Grossum
Grossum Software Outsourcing
Grossum: Инструменты управления IT компанией
Why Drupal?

Recently uploaded (20)

PDF
MCP Security Tutorial - Beginner to Advanced
PPTX
Patient Appointment Booking in Odoo with online payment
PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
"Secure File Sharing Solutions on AWS".pptx
PDF
Topaz Photo AI Crack New Download (Latest 2025)
PPTX
GSA Content Generator Crack (2025 Latest)
PPTX
Introduction to Windows Operating System
PDF
Website Design Services for Small Businesses.pdf
PDF
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
PPTX
Custom Software Development Services.pptx.pptx
PDF
Autodesk AutoCAD Crack Free Download 2025
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
STL Containers in C++ : Sequence Container : Vector
MCP Security Tutorial - Beginner to Advanced
Patient Appointment Booking in Odoo with online payment
How Tridens DevSecOps Ensures Compliance, Security, and Agility
Wondershare Recoverit Full Crack New Version (Latest 2025)
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
"Secure File Sharing Solutions on AWS".pptx
Topaz Photo AI Crack New Download (Latest 2025)
GSA Content Generator Crack (2025 Latest)
Introduction to Windows Operating System
Website Design Services for Small Businesses.pdf
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
Custom Software Development Services.pptx.pptx
Autodesk AutoCAD Crack Free Download 2025
How to Use SharePoint as an ISO-Compliant Document Management System
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
iTop VPN Crack Latest Version Full Key 2025
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
Designing Intelligence for the Shop Floor.pdf
STL Containers in C++ : Sequence Container : Vector

KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv