Skip to content

Commit 4e5ca54

Browse files
committed
[best practice] security.rst をひと通り和訳
1 parent 952a956 commit 4e5ca54

File tree

1 file changed

+111
-1
lines changed

1 file changed

+111
-1
lines changed

best_practices/security.rst

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
セキュリティ
12
Security
23
========
34

5+
認証とファイアウォール (i.e. Getting thw User's Credentials)
46
Authentication and Firewalls (i.e. Getting the User's Credentials)
57
------------------------------------------------------------------
68

9+
10+
思いのままの手段と様々なデータソースからユーザ情報をロードしユーザの認証を Symfony に
11+
設定することができます。
12+
とても難解なテーマですが、`Security Cookbook Section`_ には
13+
これについてのたくさんの情報が記載されています。
14+
15+
``security.yml`` の初期設定の ``firewalls`` キーの下に認証を設定します。
16+
17+
718
You can configure Symfony to authenticate your users using any method you
819
want and to load user information from any source. This is a complex topic,
920
but the `Security Cookbook Section`_ has a lot of information about this.
@@ -13,30 +24,52 @@ primarily under the ``firewalls`` key.
1324

1425
.. best-practice::
1526

27+
正規に許可された2つのことなる認証システムとユーザが無い限り
28+
(e.g. メインとなるサイトと API のためだけのトークンシステムのためのログイン)、
29+
``anonymous`` のキーを有効にしたたったひとつのファイヤーウォールを設けることを推奨します。
30+
1631
Unless you have two legitimately different authentication systems and
1732
users (e.g. form login for the main site and a token system for your
1833
API only), we recommend having only *one* firewall entry with the ``anonymous``
1934
key enabled.
2035

36+
37+
ほとんどのアプリケーションで認証システムとユーザのセットはひとつしかありません。
38+
このため、ひとつのファイヤーウォールの設定だけで事足ります。
39+
もちろん サイトの API と WEB を分けたいときなどの例外もありますが、
40+
シンプルに考えていくことが重要です。
41+
2142
Most applications only have one authentication system and one set of users.
2243
For this reason, you only need *one* firewall entry. There are exceptions
2344
of course, especially if you have separated web and API sections on your
2445
site. But the point is to keep things simple.
2546

47+
なお、ファイヤーウォールの下では ``anonymous`` キーを利用するべきです。
48+
サイトの異なるセクション (または 全てのセクションのようなもの) にユーザが
49+
ログインすることが必要となった場合は ``access_control`` エリアを利用します。
50+
2651
Additionally, you should use the ``anonymous`` key under your firewall. If
2752
you need to require users to be logged in for different sections of your
2853
site (or maybe nearly *all* sections), use the ``access_control`` area.
2954

3055
.. best-practice::
3156

32-
Use the ``bcrypt`` encoder for encoding your users' passwords.
57+
ユーザのパスワードのエンコーディングには ``bcrypt`` エンコーダーを利用する。
58+
59+
ユーザがパスワードを持つ場合、SHA-512 の代わりに ``bcrypt`` エンコーダーを利用することを推奨します。
60+
``bcrypt`` のアドバンテージは、**ソルト** の値がレインボーテーブルアタックから守り
61+
ブルートフォースアタックを遅延することができることです。
3362

3463
If your users have a password, then we recommend encoding it using the ``bcrypt``
3564
encoder, instead of the traditional SHA-512 hashing encoder. The main advantages
3665
of ``bcrypt`` are the inclusion of a *salt* value to protect against rainbow
3766
table attacks, and its adaptive nature, which allows to make it slower to
3867
remain resistant to brute-force search attacks.
3968

69+
この方針で、
70+
データベースからユーザをロードするログインフォームを利用する認証を
71+
アプリケーションにセットアップする設定は以下となります。
72+
4073
With this in mind, here is the authentication setup from our application,
4174
which uses a login form to load users from the database:
4275

@@ -66,41 +99,66 @@ which uses a login form to load users from the database:
6699
67100
.. tip::
68101

102+
プロジェクトのソースコードにそれぞれの部位を説明するコメントをもつ。
69103
The source code for our project contains comments that explain each part.
70104

105+
106+
認証 (i.e アクセスの拒否)
71107
Authorization (i.e. Denying Access)
72108
-----------------------------------
73109

110+
Symfony は認証を実装するために、 `security.yml`_ に ``access_control`` を設定する、
111+
``security.context`` のサービスディレクトリに `@Security annotation <best-practices-security-annotation>` と
112+
`isGranted <best-practices-directy-isGranted>` を使うなどのいくつかの手段を提供しています。
113+
74114
Symfony gives you several ways to enforce authorization, including the ``access_control``
75115
configuration in `security.yml`_, the :ref:`@Security annotation <best-practices-security-annotation>`
76116
and using :ref:`isGranted <best-practices-directy-isGranted>` on the ``security.context``
77117
service directly.
78118

79119
.. best-practice::
80120

121+
* 広範囲の URL パターンをプロテクトするためには ``access_control`` を利用する。
122+
* いつでも可能なときは ``@Security`` アノテーションを利用する。
123+
* より複雑な状況の場合はいつでも、
124+
``security.context`` サービスででセキュアなディレクトリをチェックする。
125+
81126
* For protecting broad URL patterns, use ``access_control``;
82127
* Whenever possible, use the ``@Security`` annotation;
83128
* Check security directly on the ``security.context`` service whenever
84129
you have a more complex situation.
85130

131+
認証ロジックを一箇所に集中させる様々な方法があります。
132+
例えば、カスタムセキュリティボーターや ACL を利用したものです。
86133
There are also different ways to centralize your authorization logic, like
87134
with a custom security voter or with ACL.
88135

89136
.. best-practice::
90137

138+
* Fine-grained 制限のために、カスタムセキュリティボーターを定義する。
139+
* 管理者インターフェースを経由したあらゆるユーザの
140+
あらゆるのオブジェクトへのアクセスを制限するために Symfony ACL を利用する。
141+
91142
* For fine-grained restrictions, define a custom security voter;
92143
* For restricting access to *any* object by *any* user via an admin
93144
interface, use the Symfony ACL.
94145

95146
.. _best-practices-security-annotation:
96147

148+
@Security アノテーション
97149
The @Security Annotation
98150
------------------------
99151

152+
controller-by-controller の原則にしたがってアクセスをコントロールするために、
153+
``@Secury`` アノテーションを可能な限り利用します。
154+
この方法は、可読性が高く、矛盾なくそれぞれのアクションに付与することができます。
100155
For controlling access on a controller-by-controller basis, use the ``@Security``
101156
annotation whenever possible. It's easy to read and is placed consistently
102157
above each action.
103158

159+
このアプリケーションにおいて、新しいポストを作成するための ``ROLE_ADMIN`` が必要です。
160+
``@Security`` を利用して、このように実装できます。
161+
104162
In our application, you need the ``ROLE_ADMIN`` in order to create a new post.
105163
Using ``@Security``, this looks like:
106164

@@ -121,9 +179,16 @@ Using ``@Security``, this looks like:
121179
// ...
122180
}
123181
182+
Expression で複雑なセキュリティの制限の記述する
124183
Using Expressions for Complex Security Restrictions
125184
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
126185

186+
セキュリティロジックがかなり複雑な場合は、
187+
``@Security`` の内部で `expression`_ を利用できます。
188+
例えば、
189+
``Post`` オブジェクトの ``getAuthorEmail`` メソッドの返り値とメールアドレスが一致したときのみ
190+
コントローラーへのアクセスを許可したい場合は以下のように実装できます。
191+
127192
If your security logic is a little bit more complex, you can use an `expression`_
128193
inside ``@Security``. In the following example, a user can only access the
129194
controller if their email matches the value returned by the ``getAuthorEmail``
@@ -144,10 +209,18 @@ method on the ``Post`` object:
144209
// ...
145210
}
146211
212+
``Post`` オブジェクトとそれに与えられる ``$post`` という引数のための
213+
自動的なクエリ`PramConverter`_ の利用が必須であることに注意してください。
214+
147215
Notice that this requires the use of the `ParamConverter`_, which automatically
148216
queries for the ``Post`` object and puts it on the ``$post`` argument. This
149217
is what makes it possible to use the ``post`` variable in the expression.
150218

219+
この方法は有名な決定を持っています。
220+
アノテーションによる expression は他のアプリケーションでは容易に再利用できません。
221+
著者のみが閲覧できるテンプレートのリンクを追加したい場合を想像してください。
222+
Twig を利用して expression を再び記述することがすぐ思い浮かぶでしょう。
223+
151224
This has one major drawback: an expression in an annotation cannot easily
152225
be reused in other parts of the application. Imagine that you want to add
153226
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:
159232
<a href=""> ... </a>
160233
{% endif %}
161234

235+
十分にシンプルなロジックの場合、最も簡単な解決手段は
236+
与えられたユーザがその投稿の著者であるかをチェックする新しい関数を
237+
``Post`` エンティティに追加することです。
238+
162239
The easiest solution - if your logic is simple enough - is to add a new method
163240
to the ``Post`` entity that checks if a given user is its author:
164241

@@ -182,6 +259,8 @@ to the ``Post`` entity that checks if a given user is its author:
182259
}
183260
}
184261
262+
これで、この関数をテンプレートとセキュリティの記述のどちらでも再利用できます。
263+
185264
Now you can reuse this method both in the template and in the security expression:
186265

187266
.. code-block:: php
@@ -206,9 +285,15 @@ Now you can reuse this method both in the template and in the security expressio
206285

207286
.. _best-practices-directy-isGranted:
208287

288+
@Security なしに権限をチェックする
209289
Checking Permissions without @Security
210290
--------------------------------------
211291

292+
これまでの例は、
293+
``post`` という変数にアクセスできる記述を提供してくれる :ref:`ParamConverter <best-practices-paramconverter>` を
294+
利用する場合のみ動作します。
295+
これを利用しない場合やより進んだユースケースの場合は、PHP で同様のセキュリティチェックができます。
296+
212297
The above example with ``@Security`` only works because we're using the
213298
:ref:`ParamConverter <best-practices-paramconverter>`, which gives the expression
214299
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:
235320
// ...
236321
}
237322
323+
セキュリティボーター
238324
Security Voters
239325
---------------
240326

327+
セキュリティロジックが複雑で ``isAuthor()`` のようなメソッドに局所化できない場合、
328+
カスタムボーターを利用することができます。
329+
これらは `ACL's`_ よりもかなり簡単な方法かつほぼ全てのケースに柔軟に対応できます。
330+
241331
If your security logic is complex and can't be centralized into a method
242332
like ``isAuthor()``, you should leverage custom voters. These are an order
243333
of magnitude easier than `ACL's`_ and will give you the flexibility you need
244334
in almost all cases.
245335

336+
337+
まずはじめに、voter クラスを作成します。以下の例では、これまでと同じ ``getAuthorEmail`` ロジックを
338+
実装した voter について示します。
339+
246340
First, create a voter class. The following example shows a voter that implements
247341
the same ``getAuthorEmail`` logic you used above:
248342

@@ -287,6 +381,7 @@ the same ``getAuthorEmail`` logic you used above:
287381
}
288382
}
289383
384+
アプリケーションでセキュリティボータを有効にするために新しいサービスを定義します。
290385
To enable the security voter in the application, define a new service:
291386

292387
.. code-block:: yaml
@@ -300,6 +395,7 @@ To enable the security voter in the application, define a new service:
300395
tags:
301396
- { name: security.voter }
302397
398+
ここで ``@Security`` アノテーションと共に voter を利用してみます。
303399
Now, you can use the voter with the ``@Security`` annotation:
304400

305401
.. code-block:: php
@@ -313,6 +409,9 @@ Now, you can use the voter with the ``@Security`` annotation:
313409
// ...
314410
}
315411
412+
このディレクトリを ``security.context`` と共に使うことも可能です。
413+
また、コントローラーでより簡潔なショートカットを経由することも可能です。
414+
316415
You can also use this directly with the ``security.context`` service, or
317416
via the even easier shortcut in a controller:
318417

@@ -330,20 +429,31 @@ via the even easier shortcut in a controller:
330429
}
331430
}
332431
432+
さらに学ぶためには
333433
Learn More
334434
----------
335435

436+
Symfony のコミュニティによって開発された `FOSUserBundle`_ は Symfony2 における
437+
データベースによるユーザシステムのサポートを追加しました。
438+
これはユーザの登録やパスワードを忘れた時の機能などの共通のタスクも取り扱っています。
439+
336440
The `FOSUserBundle`_, developed by the Symfony community, adds support for a
337441
database-backed user system in Symfony2. It also handles common tasks like
338442
user registration and forgotten password functionality.
339443

444+
`Remember Me feature`_ を有効にすることによってユーザを長期期間ログインさせておくことも可能です。
340445
Enable the `Remember Me feature`_ to allow your users to stay logged in for
341446
a long period of time.
342447

448+
カスタマーサポートを提供したとき、問題を再現するために異なるユーザでアプリケーションにアクセス
449+
することがたびたび必要になります。
450+
Symfony は `impersonate users`_ の機能を提供しています。
343451
When providing customer support, sometimes it's necessary to access the application
344452
as some *other* user so that you can reproduce the problem. Symfony provides
345453
the ability to `impersonate users`_.
346454

455+
Symfony でサポートしていないユーザのログインメソッドを利用する場合、
456+
`your own user provider`_ と `your own authentication provider`_ で開発することができます。
347457
If your company uses a user login method not supported by Symfony, you can
348458
develop `your own user provider`_ and `your own authentication provider`_.
349459

0 commit comments

Comments
 (0)