1
+ セキュリティ
1
2
Security
2
3
========
3
4
5
+ 認証とファイアウォール (i.e. Getting thw User's Credentials)
4
6
Authentication and Firewalls (i.e. Getting the User's Credentials)
5
7
------------------------------------------------------------------
6
8
9
+
10
+ 思いのままの手段と様々なデータソースからユーザ情報をロードしユーザの認証を Symfony に
11
+ 設定することができます。
12
+ とても難解なテーマですが、`Security Cookbook Section `_ には
13
+ これについてのたくさんの情報が記載されています。
14
+
15
+ ``security.yml `` の初期設定の ``firewalls `` キーの下に認証を設定します。
16
+
17
+
7
18
You can configure Symfony to authenticate your users using any method you
8
19
want and to load user information from any source. This is a complex topic,
9
20
but the `Security Cookbook Section `_ has a lot of information about this.
@@ -13,30 +24,52 @@ primarily under the ``firewalls`` key.
13
24
14
25
.. best-practice ::
15
26
27
+ 正規に許可された2つのことなる認証システムとユーザが無い限り
28
+ (e.g. メインとなるサイトと API のためだけのトークンシステムのためのログイン)、
29
+ ``anonymous `` のキーを有効にしたたったひとつのファイヤーウォールを設けることを推奨します。
30
+
16
31
Unless you have two legitimately different authentication systems and
17
32
users (e.g. form login for the main site and a token system for your
18
33
API only), we recommend having only *one * firewall entry with the ``anonymous ``
19
34
key enabled.
20
35
36
+
37
+ ほとんどのアプリケーションで認証システムとユーザのセットはひとつしかありません。
38
+ このため、ひとつのファイヤーウォールの設定だけで事足ります。
39
+ もちろん サイトの API と WEB を分けたいときなどの例外もありますが、
40
+ シンプルに考えていくことが重要です。
41
+
21
42
Most applications only have one authentication system and one set of users.
22
43
For this reason, you only need *one * firewall entry. There are exceptions
23
44
of course, especially if you have separated web and API sections on your
24
45
site. But the point is to keep things simple.
25
46
47
+ なお、ファイヤーウォールの下では ``anonymous `` キーを利用するべきです。
48
+ サイトの異なるセクション (または 全てのセクションのようなもの) にユーザが
49
+ ログインすることが必要となった場合は ``access_control `` エリアを利用します。
50
+
26
51
Additionally, you should use the ``anonymous `` key under your firewall. If
27
52
you need to require users to be logged in for different sections of your
28
53
site (or maybe nearly *all * sections), use the ``access_control `` area.
29
54
30
55
.. best-practice ::
31
56
32
- Use the ``bcrypt `` encoder for encoding your users' passwords.
57
+ ユーザのパスワードのエンコーディングには ``bcrypt `` エンコーダーを利用する。
58
+
59
+ ユーザがパスワードを持つ場合、SHA-512 の代わりに ``bcrypt `` エンコーダーを利用することを推奨します。
60
+ ``bcrypt `` のアドバンテージは、**ソルト ** の値がレインボーテーブルアタックから守り
61
+ ブルートフォースアタックを遅延することができることです。
33
62
34
63
If your users have a password, then we recommend encoding it using the ``bcrypt ``
35
64
encoder, instead of the traditional SHA-512 hashing encoder. The main advantages
36
65
of ``bcrypt `` are the inclusion of a *salt * value to protect against rainbow
37
66
table attacks, and its adaptive nature, which allows to make it slower to
38
67
remain resistant to brute-force search attacks.
39
68
69
+ この方針で、
70
+ データベースからユーザをロードするログインフォームを利用する認証を
71
+ アプリケーションにセットアップする設定は以下となります。
72
+
40
73
With this in mind, here is the authentication setup from our application,
41
74
which uses a login form to load users from the database:
42
75
@@ -66,41 +99,66 @@ which uses a login form to load users from the database:
66
99
67
100
.. tip ::
68
101
102
+ プロジェクトのソースコードにそれぞれの部位を説明するコメントをもつ。
69
103
The source code for our project contains comments that explain each part.
70
104
105
+
106
+ 認証 (i.e アクセスの拒否)
71
107
Authorization (i.e. Denying Access)
72
108
-----------------------------------
73
109
110
+ Symfony は認証を実装するために、 `security.yml `_ に ``access_control `` を設定する、
111
+ ``security.context `` のサービスディレクトリに `@Security annotation <best-practices-security-annotation> ` と
112
+ `isGranted <best-practices-directy-isGranted> ` を使うなどのいくつかの手段を提供しています。
113
+
74
114
Symfony gives you several ways to enforce authorization, including the ``access_control ``
75
115
configuration in `security.yml `_, the :ref: `@Security annotation <best-practices-security-annotation >`
76
116
and using :ref: `isGranted <best-practices-directy-isGranted >` on the ``security.context ``
77
117
service directly.
78
118
79
119
.. best-practice ::
80
120
121
+ * 広範囲の URL パターンをプロテクトするためには ``access_control `` を利用する。
122
+ * いつでも可能なときは ``@Security `` アノテーションを利用する。
123
+ * より複雑な状況の場合はいつでも、
124
+ ``security.context `` サービスででセキュアなディレクトリをチェックする。
125
+
81
126
* For protecting broad URL patterns, use ``access_control ``;
82
127
* Whenever possible, use the ``@Security `` annotation;
83
128
* Check security directly on the ``security.context `` service whenever
84
129
you have a more complex situation.
85
130
131
+ 認証ロジックを一箇所に集中させる様々な方法があります。
132
+ 例えば、カスタムセキュリティボーターや ACL を利用したものです。
86
133
There are also different ways to centralize your authorization logic, like
87
134
with a custom security voter or with ACL.
88
135
89
136
.. best-practice ::
90
137
138
+ * Fine-grained 制限のために、カスタムセキュリティボーターを定義する。
139
+ * 管理者インターフェースを経由したあらゆるユーザの
140
+ あらゆるのオブジェクトへのアクセスを制限するために Symfony ACL を利用する。
141
+
91
142
* For fine-grained restrictions, define a custom security voter;
92
143
* For restricting access to *any * object by *any * user via an admin
93
144
interface, use the Symfony ACL.
94
145
95
146
.. _best-practices-security-annotation :
96
147
148
+ @Security アノテーション
97
149
The @Security Annotation
98
150
------------------------
99
151
152
+ controller-by-controller の原則にしたがってアクセスをコントロールするために、
153
+ ``@Secury `` アノテーションを可能な限り利用します。
154
+ この方法は、可読性が高く、矛盾なくそれぞれのアクションに付与することができます。
100
155
For controlling access on a controller-by-controller basis, use the ``@Security ``
101
156
annotation whenever possible. It's easy to read and is placed consistently
102
157
above each action.
103
158
159
+ このアプリケーションにおいて、新しいポストを作成するための ``ROLE_ADMIN `` が必要です。
160
+ ``@Security `` を利用して、このように実装できます。
161
+
104
162
In our application, you need the ``ROLE_ADMIN `` in order to create a new post.
105
163
Using ``@Security ``, this looks like:
106
164
@@ -121,9 +179,16 @@ Using ``@Security``, this looks like:
121
179
// ...
122
180
}
123
181
182
+ Expression で複雑なセキュリティの制限の記述する
124
183
Using Expressions for Complex Security Restrictions
125
184
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
126
185
186
+ セキュリティロジックがかなり複雑な場合は、
187
+ ``@Security `` の内部で `expression `_ を利用できます。
188
+ 例えば、
189
+ ``Post `` オブジェクトの ``getAuthorEmail `` メソッドの返り値とメールアドレスが一致したときのみ
190
+ コントローラーへのアクセスを許可したい場合は以下のように実装できます。
191
+
127
192
If your security logic is a little bit more complex, you can use an `expression `_
128
193
inside ``@Security ``. In the following example, a user can only access the
129
194
controller if their email matches the value returned by the ``getAuthorEmail ``
@@ -144,10 +209,18 @@ method on the ``Post`` object:
144
209
// ...
145
210
}
146
211
212
+ ``Post `` オブジェクトとそれに与えられる ``$post `` という引数のための
213
+ 自動的なクエリ`PramConverter`_ の利用が必須であることに注意してください。
214
+
147
215
Notice that this requires the use of the `ParamConverter `_, which automatically
148
216
queries for the ``Post `` object and puts it on the ``$post `` argument. This
149
217
is what makes it possible to use the ``post `` variable in the expression.
150
218
219
+ この方法は有名な決定を持っています。
220
+ アノテーションによる expression は他のアプリケーションでは容易に再利用できません。
221
+ 著者のみが閲覧できるテンプレートのリンクを追加したい場合を想像してください。
222
+ Twig を利用して expression を再び記述することがすぐ思い浮かぶでしょう。
223
+
151
224
This has one major drawback: an expression in an annotation cannot easily
152
225
be reused in other parts of the application. Imagine that you want to add
153
226
a link in a template that will only be seen by authors. Right now you'll
@@ -159,6 +232,10 @@ need to repeat the expression code using Twig syntax:
159
232
<a href=""> ... </a>
160
233
{% endif %}
161
234
235
+ 十分にシンプルなロジックの場合、最も簡単な解決手段は
236
+ 与えられたユーザがその投稿の著者であるかをチェックする新しい関数を
237
+ ``Post `` エンティティに追加することです。
238
+
162
239
The easiest solution - if your logic is simple enough - is to add a new method
163
240
to the ``Post `` entity that checks if a given user is its author:
164
241
@@ -182,6 +259,8 @@ to the ``Post`` entity that checks if a given user is its author:
182
259
}
183
260
}
184
261
262
+ これで、この関数をテンプレートとセキュリティの記述のどちらでも再利用できます。
263
+
185
264
Now you can reuse this method both in the template and in the security expression:
186
265
187
266
.. code-block :: php
@@ -206,9 +285,15 @@ Now you can reuse this method both in the template and in the security expressio
206
285
207
286
.. _best-practices-directy-isGranted :
208
287
288
+ @Security なしに権限をチェックする
209
289
Checking Permissions without @Security
210
290
--------------------------------------
211
291
292
+ これまでの例は、
293
+ ``post `` という変数にアクセスできる記述を提供してくれる :ref: `ParamConverter <best-practices-paramconverter >` を
294
+ 利用する場合のみ動作します。
295
+ これを利用しない場合やより進んだユースケースの場合は、PHP で同様のセキュリティチェックができます。
296
+
212
297
The above example with ``@Security `` only works because we're using the
213
298
:ref: `ParamConverter <best-practices-paramconverter >`, which gives the expression
214
299
access to the a ``post `` variable. If you don't use this, or have some other
@@ -235,14 +320,23 @@ more advanced use-case, you can always do the same security check in PHP:
235
320
// ...
236
321
}
237
322
323
+ セキュリティボーター
238
324
Security Voters
239
325
---------------
240
326
327
+ セキュリティロジックが複雑で ``isAuthor() `` のようなメソッドに局所化できない場合、
328
+ カスタムボーターを利用することができます。
329
+ これらは `ACL's `_ よりもかなり簡単な方法かつほぼ全てのケースに柔軟に対応できます。
330
+
241
331
If your security logic is complex and can't be centralized into a method
242
332
like ``isAuthor() ``, you should leverage custom voters. These are an order
243
333
of magnitude easier than `ACL's `_ and will give you the flexibility you need
244
334
in almost all cases.
245
335
336
+
337
+ まずはじめに、voter クラスを作成します。以下の例では、これまでと同じ ``getAuthorEmail `` ロジックを
338
+ 実装した voter について示します。
339
+
246
340
First, create a voter class. The following example shows a voter that implements
247
341
the same ``getAuthorEmail `` logic you used above:
248
342
@@ -287,6 +381,7 @@ the same ``getAuthorEmail`` logic you used above:
287
381
}
288
382
}
289
383
384
+ アプリケーションでセキュリティボータを有効にするために新しいサービスを定義します。
290
385
To enable the security voter in the application, define a new service:
291
386
292
387
.. code-block :: yaml
@@ -300,6 +395,7 @@ To enable the security voter in the application, define a new service:
300
395
tags :
301
396
- { name: security.voter }
302
397
398
+ ここで ``@Security `` アノテーションと共に voter を利用してみます。
303
399
Now, you can use the voter with the ``@Security `` annotation:
304
400
305
401
.. code-block :: php
@@ -313,6 +409,9 @@ Now, you can use the voter with the ``@Security`` annotation:
313
409
// ...
314
410
}
315
411
412
+ このディレクトリを ``security.context `` と共に使うことも可能です。
413
+ また、コントローラーでより簡潔なショートカットを経由することも可能です。
414
+
316
415
You can also use this directly with the ``security.context `` service, or
317
416
via the even easier shortcut in a controller:
318
417
@@ -330,20 +429,31 @@ via the even easier shortcut in a controller:
330
429
}
331
430
}
332
431
432
+ さらに学ぶためには
333
433
Learn More
334
434
----------
335
435
436
+ Symfony のコミュニティによって開発された `FOSUserBundle `_ は Symfony2 における
437
+ データベースによるユーザシステムのサポートを追加しました。
438
+ これはユーザの登録やパスワードを忘れた時の機能などの共通のタスクも取り扱っています。
439
+
336
440
The `FOSUserBundle `_, developed by the Symfony community, adds support for a
337
441
database-backed user system in Symfony2. It also handles common tasks like
338
442
user registration and forgotten password functionality.
339
443
444
+ `Remember Me feature `_ を有効にすることによってユーザを長期期間ログインさせておくことも可能です。
340
445
Enable the `Remember Me feature `_ to allow your users to stay logged in for
341
446
a long period of time.
342
447
448
+ カスタマーサポートを提供したとき、問題を再現するために異なるユーザでアプリケーションにアクセス
449
+ することがたびたび必要になります。
450
+ Symfony は `impersonate users `_ の機能を提供しています。
343
451
When providing customer support, sometimes it's necessary to access the application
344
452
as some *other * user so that you can reproduce the problem. Symfony provides
345
453
the ability to `impersonate users `_.
346
454
455
+ Symfony でサポートしていないユーザのログインメソッドを利用する場合、
456
+ `your own user provider `_ と `your own authentication provider `_ で開発することができます。
347
457
If your company uses a user login method not supported by Symfony, you can
348
458
develop `your own user provider `_ and `your own authentication provider `_.
349
459
0 commit comments