1
1
How to Use Multiple Guard Authenticators
2
2
========================================
3
3
4
- Guard authentication component allows you to easily use many different authenticators at a time.
4
+ The Guard authentication component allows you to easily use many different
5
+ authenticators at a time.
5
6
6
- An entry point is a service id (of one of your authenticators) whose start()
7
- method should be called when an anonymous user hits a page that requires authentication.
7
+ An entry point is a service id (of one of your authenticators) whose
8
+ `` start() `` method is called to start the authentication process .
8
9
9
- Multiple authenticators with shared entry point
10
+ Multiple Authenticators with Shared Entry Point
10
11
-----------------------------------------------
11
12
12
- Let's have an example of two authenticators: one based on login form, another one on facebook login.
13
- Both authenticators entry points redirect user to the same login page.
14
- However, in your configuration you have to explicitly say which entry point you want to use.
13
+ Sometimes you want to offer your users different authentication mechanisms like
14
+ a form login and a Facebook login while both entry points redirect the user to
15
+ the same login page.
16
+ However, in your configuration you have to explicitly say which entry point
17
+ you want to use.
15
18
16
19
This is how your security configuration can look in action:
17
20
@@ -45,7 +48,7 @@ This is how your security configuration can look in action:
45
48
<!-- ... -->
46
49
<firewall name =" default" >
47
50
<anonymous />
48
- <guard entry_point =" app.form_login_authenticator" >
51
+ <guard entry-point =" app.form_login_authenticator" >
49
52
<authenticator >app.form_login_authenticator</authenticator >
50
53
<authenticator >app.facebook_connect_authenticator</authenticator >
51
54
</guard >
@@ -74,16 +77,14 @@ This is how your security configuration can look in action:
74
77
75
78
There is one limitation with this approach - you have to use exactly one entry point.
76
79
77
- Multiple authenticators with separate entry points
80
+ Multiple Authenticators with Separate Entry Points
78
81
--------------------------------------------------
79
82
80
- Let's now have an example of two different authenticators: one based on login form, another one on an API token.
81
- When user hits secured area he should be redirected to the login page.
82
- Also when user hits an API endpoint, he should get a relevant API response.
83
-
84
- Solution for this use case is to provide guard authenticators in two separate firewalls.
85
-
86
- This is an example of your configuration:
83
+ However, there are use cases where you have authenticators that protect different
84
+ parts of your application. For example, you have a login form that protects
85
+ the secured area of your application front-end and API end points that are
86
+ protected with API tokens. As you can only configure one entry point per firewall,
87
+ the solution is to split the configuration into two separate firewalls:
87
88
88
89
.. configuration-block ::
89
90
@@ -106,7 +107,7 @@ This is an example of your configuration:
106
107
access_control :
107
108
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
108
109
- { path: ^/api, roles: ROLE_API_USER }
109
- - { path: ^/, roles: ROLE_ADMIN }
110
+ - { path: ^/, roles: ROLE_USER }
110
111
111
112
.. code-block :: xml
112
113
@@ -133,7 +134,7 @@ This is an example of your configuration:
133
134
</firewall >
134
135
<rule path =" ^/login" role =" IS_AUTHENTICATED_ANONYMOUSLY" />
135
136
<rule path =" ^/api" role =" ROLE_API_USER" />
136
- <rule path =" ^/" role =" ROLE_ADMIN " />
137
+ <rule path =" ^/" role =" ROLE_USER " />
137
138
</config >
138
139
</srv : container >
139
140
@@ -163,6 +164,6 @@ This is an example of your configuration:
163
164
'access_control' => array(
164
165
array('path' => '^/login', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY'),
165
166
array('path' => '^/api', 'role' => 'ROLE_API_USER'),
166
- array('path' => '^/', 'role' => 'ROLE_ADMIN '),
167
+ array('path' => '^/', 'role' => 'ROLE_USER '),
167
168
),
168
169
));
0 commit comments