Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Guard, el nuevo componente Symfony de seguridad

Pedro
September 16, 2016

Guard, el nuevo componente Symfony de seguridad

Slides de la charla en deSymfony sobre Guard.

Pedro

September 16, 2016
Tweet

More Decks by Pedro

Other Decks in Programming

Transcript

  1. GUARD, EL NUEVO COMPONENTE SYMFONY DE SEGURIDAD ¿QUÉ ES GUARD?

    “Un nuevo proveedor de autenticación con un objetivo en mente: poner todo lo que necesitas para cualquier autenticación en un punto.” @weaverryan https://github.com/symfony/symfony/pull/14673
  2. Es quien comprueba si eres quien dices que eres y

    si puedes acceder donde quieres acceder Es quien comprueba si eres quien dices que eres y si puedes acceder donde quieres acceder Es quien comprueba si eres quien dices que eres y si puedes acceder donde quieres acceder COMPONENTE DE SEGURIDAD AUTENTICACIÓN AUTORIZACIÓN
  3. COMPONENTE DE SEGURIDAD AUTORIZACIÓN ‣ Access Decision Manager: decide si

    un token puede realizar una determinada acción. ‣ Varios sistemas: ‣ Security voters ‣ Access Control Lists (ACL)
  4. 1. Extrae las credenciales de una petición. 2. Busca el

    usuario mediante user provider. 3. Comprueba si las credenciales son correctas con el authentication manager. COMPONENTE DE SEGURIDAD AUTENTICACIÓN
  5. ‣ FirewallMap: conjunto de listeners que realizan la labor de

    autenticación. ‣ Los listeners se componen: ‣ Authentication Manager: autentica mediante los authentication providers que tenga el firewall. ‣ Authentication Provider: es quien se encarga de comprobar las credenciales del token. COMPONENTE DE SEGURIDAD AUTENTICACIÓN - ELEMENTOS INVOLUCRADOS
  6. ‣ security.authentication.success: el usuario ha sido autenticado (siempre). ‣ security.authentication.failure:

    la autenticación falla. ‣ security.interactive_login: sólo cuando el usuario hace login. ‣ security.switch_user: se ha activado la impersonación. COMPONENTE DE SEGURIDAD AUTENTICACIÓN - EVENTOS
  7. COMPONENTE DE SEGURIDAD AUTENTICACIÓN - CONFIGURACIÓN security: providers: [] encoders:

    [] firewalls: frontend: pattern: ^/* anonymous: ~ provider: users_chain_provider form_login: login_path: user_login check_path: user_login_check username_parameter: login[email] password_parameter: login[password] logout: path: user_logout target: / remember_me: lifetime: 60000 switch_user: { role: ROLE_ADMIN, provider: users_chain_provider }
  8. GUARD, EL NUEVO COMPONENTE SYMFONY DE SEGURIDAD ¿QUÉ ES GUARD?

    “Un nuevo proveedor de autenticación con un objetivo en mente: poner todo lo que necesitas para cualquier autenticación en un punto.” @weaverryan https://github.com/symfony/symfony/pull/14673 ¡ES UN PROVEEDOR DE AUTENTICACIÓN MÁS! COMO PUEDEN SER EL DE FORMULARIO, LOGOUT, ETC.
  9. GUARD CREAR AUTENTICACIÓN CON GUARD 1. Creamos una clase para

    autenticar extendiendo de AbstractGuardAuthenticator. 2. Configuramos el nuevo autenticador como servicio. 3. Añadimos el servicio en el firewall correspondiente en `guard`.
  10. GUARD IMPLEMENTAMOS AUTHENTICATOR class FooHeaderAuthenticator extends AbstractGuardAuthenticator { public function

    start(Request $request, AuthenticationException $authException = null) {} public function getCredentials(Request $request) {} public function getUser($credentials, UserProviderInterface $userProvider) {} public function checkCredentials($credentials, UserInterface $user) {} public function onAuthenticationFailure(Request $request, AuthenticationException $exception) {} public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) {} public function supportsRememberMe() {} }
  11. GUARD IMPLEMENTAMOS AUTHENTICATOR class FooHeaderAuthenticator extends AbstractGuardAuthenticator { [...] public

    function getCredentials(Request $request) {} public function getUser($credentials, UserProviderInterface $userProvider) {} public function checkCredentials($credentials, UserInterface $user) {} [...] }
  12. GUARD IMPLEMENTAMOS AUTHENTICATOR class FooHeaderAuthenticator extends AbstractGuardAuthenticator { [...] public

    function onAuthenticationFailure(Request $request, AuthenticationException $exception) {} public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) {} [...] }
  13. GUARD IMPLEMENTAMOS AUTHENTICATOR class FooHeaderAuthenticator extends AbstractGuardAuthenticator { public function

    start(Request $request, AuthenticationException $authException = null) {} [...] public function supportsRememberMe() {} }
  14. GUARD CONFIGURAMOS SERVICIO services: app.guard_authenticator.foo_header: class: AppBundle\Security\Guard\FooHeaderAuthenticator CONFIGURAMOS EL FIREWALL

    security: providers: [] firewalls: main: anonymous: ~ guard: authenticators: - app.guard_authenticator.foo_header
  15. GUARD DEMO TIME!! Creamos un autenticador que espera una cabecera

    “x-foo” con el nombre de usuario y contraseña separados por “::”.
  16. GUARD MÁS AUTHENTICATORS security: providers: [] firewalls: main: anonymous: ~

    guard: entry_point: app.guard_authenticator.login authenticators: - app.guard_authenticator.foo_header - app.guard_authenticator.login
  17. GUARD, EL NUEVO COMPONENTE SYMFONY DE SEGURIDAD REFERENCIAS ▸ http://librosweb.es/eventos/desymfony-2013/desglosando-el-

    componente-de-seguridad/ ▸ http://es.slideshare.net/weaverryan/symfony-guard-authentication-fun- with-api-token-social-login-jwt-and-more ▸ http://symfony.com/doc/current/components/security.html ▸ http://symfony.com/doc/current/components/security/ authentication.html GRACIAS :)