Advertisement
Guest User

Untitled

a guest
Jan 28th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. security:
  2.  
  3. # http://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
  4. providers:
  5. in_memory:
  6. memory: ~
  7. bd_provider:
  8. entity:
  9. class: AppBundle:Usuario
  10. property: email
  11.  
  12. firewalls:
  13. # disables authentication for assets and the profiler, adapt it according to your needs
  14. dev:
  15. pattern: ^/(_(profiler|wdt)|css|images|js)/
  16. security: false
  17.  
  18. main:
  19. anonymous: ~
  20.  
  21. form_login:
  22. login_path: login
  23. check_path: login
  24.  
  25. provider: bd_provider
  26.  
  27. logout:
  28. path: /logout
  29. target: /login
  30.  
  31. protected function createClientWithAuthentication()
  32. {
  33. /* @var $client Client */
  34. $client = static::createClient();
  35.  
  36. /* @var $user UserInterface */
  37. $user = $client->getContainer()->get('doctrine')->getRepository('AppBundle:Usuario')->find(5);
  38.  
  39. $firewallName = 'main';
  40. $token = new UsernamePasswordToken($user, $user->getPassword(), $firewallName, $user->getRoles());
  41. $session = $client->getContainer()->get('session');
  42. $session->set('_security_' . $firewallName, serialize($token));
  43. $session->save();
  44.  
  45. $cookie = new Cookie($session->getName(), $session->getId());
  46. $client->getCookieJar()->set($cookie);
  47.  
  48. return $client;
  49. }
  50.  
  51. security:
  52. providers:
  53. em_memoria:
  54. memory:
  55. users:
  56. email@example.com:
  57. password: senha
  58. roles: 'ROLE_SUPER_ADMIN'
  59.  
  60. encoders:
  61. AppBundleEntityUsuario: plaintext
  62.  
  63. firewalls:
  64. main:
  65. provider: em_memoria
  66.  
  67. $user = new AppBundleUsuario();
  68. $user
  69. ->setUsername('email@example.com')
  70. ->setPassword('admin')
  71. ->setRole('ROLE_USER_ADMIN');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement