12
12
declare (strict_types=1 );
13
13
14
14
use ApiPlatform \Core \Bridge \Symfony \Bundle \ApiPlatformBundle ;
15
+ use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \User ;
15
16
use ApiPlatform \Core \Tests \Fixtures \TestBundle \TestBundle ;
16
17
use Doctrine \Bundle \DoctrineBundle \DoctrineBundle ;
17
18
use FOS \UserBundle \FOSUserBundle ;
18
19
use Nelmio \ApiDocBundle \NelmioApiDocBundle ;
19
20
use Sensio \Bundle \FrameworkExtraBundle \SensioFrameworkExtraBundle ;
20
21
use Symfony \Bundle \FrameworkBundle \FrameworkBundle ;
22
+ use Symfony \Bundle \FrameworkBundle \Kernel \MicroKernelTrait ;
21
23
use Symfony \Bundle \SecurityBundle \SecurityBundle ;
22
24
use Symfony \Bundle \TwigBundle \TwigBundle ;
23
25
use Symfony \Component \Config \Loader \LoaderInterface ;
26
+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
24
27
use Symfony \Component \HttpKernel \Kernel ;
28
+ use Symfony \Component \Routing \RouteCollectionBuilder ;
29
+ use Symfony \Component \Security \Core \User \UserInterface ;
30
+ use Symfony \Component \Security \Http \Firewall \ContextListener ;
25
31
26
32
/**
27
33
* AppKernel for tests.
30
36
*/
31
37
class AppKernel extends Kernel
32
38
{
33
- public function registerBundles ()
39
+ use MicroKernelTrait;
40
+
41
+ public function registerBundles (): array
34
42
{
35
43
return [
36
44
new FrameworkBundle (),
@@ -45,7 +53,12 @@ public function registerBundles()
45
53
];
46
54
}
47
55
48
- public function registerContainerConfiguration (LoaderInterface $ loader )
56
+ protected function configureRoutes (RouteCollectionBuilder $ routes )
57
+ {
58
+ $ routes ->import ('config/routing.yml ' );
59
+ }
60
+
61
+ protected function configureContainer (ContainerBuilder $ c , LoaderInterface $ loader )
49
62
{
50
63
$ environment = $ this ->getEnvironment ();
51
64
@@ -55,5 +68,49 @@ public function registerContainerConfiguration(LoaderInterface $loader)
55
68
}
56
69
57
70
$ loader ->load ("{$ this ->getRootDir ()}/config/config_ {$ environment }.yml " );
71
+
72
+ $ securityConfig = [
73
+ 'encoders ' => [
74
+ User::class => 'bcrypt ' ,
75
+ // Don't use plaintext in production!
76
+ UserInterface::class => 'plaintext ' ,
77
+ ],
78
+ 'providers ' => [
79
+ 'chain_provider ' => [
80
+ 'chain ' => [
81
+ 'providers ' => ['in_memory ' , 'fos_userbundle ' ],
82
+ ],
83
+ ],
84
+ 'in_memory ' => [
85
+ 'memory ' => [
86
+ 'users ' => [
87
+ 'dunglas ' => ['password ' => 'kevin ' , 'roles ' => 'ROLE_USER ' ],
88
+ 'admin ' => ['password ' => 'kitten ' , 'roles ' => 'ROLE_ADMIN ' ],
89
+ ],
90
+ ],
91
+ ],
92
+ 'fos_userbundle ' => ['id ' => 'fos_user.user_provider.username_email ' ],
93
+ ],
94
+ 'firewalls ' => [
95
+ 'dev ' => [
96
+ 'pattern ' => '^/(_(profiler|wdt|error)|css|images|js)/ ' ,
97
+ 'security ' => false ,
98
+ ],
99
+ 'default ' => [
100
+ 'provider ' => 'chain_provider ' ,
101
+ 'http_basic ' => null ,
102
+ 'anonymous ' => null ,
103
+ ],
104
+ ],
105
+ 'access_control ' => [
106
+ ['path ' => '^/ ' , 'role ' => 'IS_AUTHENTICATED_ANONYMOUSLY ' ],
107
+ ],
108
+ ];
109
+
110
+ if (method_exists (ContextListener::class, 'setLogoutOnUserChange ' )) {
111
+ $ securityConfig ['firewalls ' ]['default ' ]['logout_on_user_change ' ] = true ;
112
+ }
113
+
114
+ $ c ->loadFromExtension ('security ' , $ securityConfig );
58
115
}
59
116
}
0 commit comments