Skip to content

Commit d65d1f2

Browse files
committed
docs/guide-ja/security-authorization.md - WIP [ci skip]
1 parent a1ec14f commit d65d1f2

File tree

1 file changed

+60
-55
lines changed

1 file changed

+60
-55
lines changed

docs/guide-ja/security-authorization.md

+60-55
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
Authorization
2-
=============
1+
権限付与
2+
========
33

4-
> Note: This section is under development.
4+
> Note|注意: この節はまだ執筆中です。
55
6-
Authorization is the process of verifying that a user has enough permission to do something. Yii provides two authorization
7-
methods: Access Control Filter (ACF) and Role-Based Access Control (RBAC).
6+
権限付与は、ユーザが何かをするのに十分な許可を得ているか否かを確認するプロセスです。
7+
Yii は二つの権限付与の方法を提供しています。すなわち、アクセスコントロールフィルタ (ACF) と、ロールベースアクセスコントロール (RBAC) です。
88

99

10-
Access Control Filter
11-
---------------------
10+
アクセスコントロールフィルタ (ACF)
11+
----------------------------------
1212

13-
Access Control Filter (ACF) is a simple authorization method that is best used by applications that only need some
14-
simple access control. As its name indicates, ACF is an action filter that can be attached to a controller or a module
15-
as a behavior. ACF will check a set of [[yii\filters\AccessControl::rules|access rules]] to make sure the current user
16-
can access the requested action.
13+
アクセスコントロールフィルタ (ACF) は、何らかの単純なアクセス制御だけを必要とするアプリケーションで使うのに最も適した、単純な権限付与の方法です。
14+
その名前が示すように、ACF は、コントローラまたはモジュールにビヘイビアとしてアタッチすることが出来るアクションフィルタです。
15+
ACF は一連の [[yii\filters\AccessControl::rules|アクセス規則]] をチェックして、現在のユーザがリクエストしたアクションにアクセスすることが出来るかどうかを確認します。
1716

18-
The code below shows how to use ACF which is implemented as [[yii\filters\AccessControl]]:
17+
下記のコードは、[[yii\filters\AccessControl]] として実装された ACF の使い方を示すものです。
1918

2019
```php
2120
use yii\filters\AccessControl;
@@ -47,71 +46,77 @@ class SiteController extends Controller
4746
}
4847
```
4948

50-
In the code above ACF is attached to the `site` controller as a behavior. This is the typical way of using an action
51-
filter. The `only` option specifies that the ACF should only be applied to `login`, `logout` and `signup` actions.
52-
The `rules` option specifies the [[yii\filters\AccessRule|access rules]], which reads as follows:
49+
上記のコードにおいて、ACF は `site` コントローラにビヘイビアとしてアタッチされています。
50+
これはアクションフィルタを使用する典型的な方法です。
51+
`only` オプションは、ACF が `login``logout``signup` のアクションにのみ適用されるべきであることを指定しています。
52+
`rules` オプションは [[yii\filters\AccessRule|アクセス規則]] を指定するものであり、以下のように読むことが出来ます。
5353

54-
- Allow all guest (not yet authenticated) users to access 'login' and 'signup' actions. The `roles` option
55-
contains a question mark `?` which is a special token recognized as "guests".
56-
- Allow authenticated users to access 'logout' action. The `@` character is another special token recognized as
57-
authenticated users.
54+
- 全てのゲストユーザ (まだ認証されていないユーザ) に、'login' と 'singup' のアクションにアクセスすることを許可します。
55+
`roles` オプションに疑問符 `?` が含まれていますが、これは「ゲスト」として認識される特殊なトークンです。
56+
- 認証されたユーザに、'logout' アクションにアクセスすることを許可します。
57+
`@` という文字はもう一つの特殊なトークンで、認証されたユーザとして認識されるものです。
5858

59-
When ACF performs authorization check, it will examine the rules one by one from top to bottom until it finds
60-
a match. The `allow` value of the matching rule will then be used to judge if the user is authorized. If none
61-
of the rules matches, it means the user is NOT authorized and ACF will stop further action execution.
59+
ACF が権限のチェックを実行するときには、規則を一つずつ上から下へ、適用されるものを見つけるまで調べます。
60+
そして、適用される規則の `allow` の値が、ユーザが権限を有するか否かを判断するのに使われます。
61+
適用される規則が一つもなかった場合は、ユーザが権限をもたないことを意味し、ACF はアクションの継続を中止します。
6262

63-
By default, ACF does only of the followings when it determines a user is not authorized to access the current action:
63+
デフォルトでは、ユーザが現在のアクションにアクセスする権限を持っていないと判定した場合は、ACF は以下のことだけを行います。
6464

65-
* If the user is a guest, it will call [[yii\web\User::loginRequired()]], which may redirect the browser to the login page.
66-
* If the user is already authenticated, it will throw a [[yii\web\ForbiddenHttpException]].
65+
* ユーザがゲストである場合は、[[yii\web\User::loginRequired()]] を呼び出します。
66+
このメソッドで、ブラウザをログインページにリダイレクトすることが出来ます。
67+
* ユーザが既に認証されている場合は、[[yii\web\ForbiddenHttpException]] を投げます。
6768

68-
You may customize this behavior by configuring the [[yii\filters\AccessControl::denyCallback]] property:
69+
この動作は、[[yii\filters\AccessControl::denyCallback]] プロパティを構成することによって、カスタマイズすることが出来ます。
6970

7071
```php
7172
[
7273
'class' => AccessControl::className(),
7374
'denyCallback' => function ($rule, $action) {
74-
throw new \Exception('You are not allowed to access this page');
75+
throw new \Exception('このページにアクセスする権限がありません。');
7576
}
7677
]
7778
```
7879

79-
[[yii\filters\AccessRule|Access rules]] support many options. Below is a summary of the supported options.
80-
You may also extend [[yii\filters\AccessRule]] to create your own customized access rule classes.
80+
[[yii\filters\AccessRule|アクセス規則]] は多くのオプションをサポートしています。
81+
以下はサポートされているオプションの要約です。
82+
[[yii\filters\AccessRule]] を拡張して、あなた自身のカスタマイズしたアクセス規則のクラスを作ることも出来ます。
8183

82-
* [[yii\filters\AccessRule::allow|allow]]: specifies whether this is an "allow" or "deny" rule.
84+
* [[yii\filters\AccessRule::allow|allow]]: これが「許可」の規則であるか、「禁止」の規則であるかを指定します。
8385

84-
* [[yii\filters\AccessRule::actions|actions]]: specifies which actions this rule matches. This should
85-
be an array of action IDs. The comparison is case-sensitive. If this option is empty or not set,
86-
it means the rule applies to all actions.
86+
* [[yii\filters\AccessRule::actions|actions]]: どのアクションにこの規則が適用されるかを指定します。
87+
これはアクション ID の配列でなければなりません。
88+
比較は大文字と小文字を区別します。
89+
このオプションが空であるか指定されていない場合は、規則が全てのアクションに適用されることを意味します。
8790

88-
* [[yii\filters\AccessRule::controllers|controllers]]: specifies which controllers this rule
89-
matches. This should be an array of controller IDs. The comparison is case-sensitive. If this option is
90-
empty or not set, it means the rule applies to all controllers.
91+
* [[yii\filters\AccessRule::controllers|controllers]]: どのコントローラにこの規則が適用されるかを指定します。
92+
これはコントローラ ID の配列でなければなりません。
93+
比較は大文字と小文字を区別します。
94+
このオプションが空であるか指定されていない場合は、規則が全てのコントローラに適用されることを意味します。
9195

92-
* [[yii\filters\AccessRule::roles|roles]]: specifies which user roles that this rule matches.
93-
Two special roles are recognized, and they are checked via [[yii\web\User::isGuest]]:
94-
- `?`: matches a guest user (not authenticated yet)
95-
- `@`: matches an authenticated user
96-
Using other role names requires RBAC (to be described in the next section), and [[yii\web\User::can()]] will be called.
97-
If this option is empty or not set, it means this rule applies to all roles.
96+
* [[yii\filters\AccessRule::roles|roles]]: どのユーザロールにこの規則が適用されるかを指定します。
97+
二つの特別なロールが認識されます。
98+
これらは、[[yii\web\User::isGuest]] によって判断されます。
9899

99-
* [[yii\filters\AccessRule::ips|ips]]: specifies which [[yii\web\Request::userIP|client IP addresses]] this rule matches.
100-
An IP address can contain the wildcard `*` at the end so that it matches IP addresses with the same prefix.
101-
For example, '192.168.*' matches all IP addresses in the segment '192.168.'. If this option is empty or not set,
102-
it means this rule applies to all IP addresses.
100+
- `?`: ゲストユーザ (まだ認証されていないユーザ) を意味します。
101+
- `@`: 認証されたユーザを意味します。
103102

104-
* [[yii\filters\AccessRule::verbs|verbs]]: specifies which request method (e.g. `GET`, `POST`) this rule matches.
105-
The comparison is case-insensitive.
103+
その他のロール名を使う場合には、RBAC (次の節で説明します) が必要とされ、判断のために [[yii\web\User::can()]] が呼び出されます。
104+
このオプションが空であるか指定されていない場合は、規則が全てのロールに適用されることを意味します。
106105

107-
* [[yii\filters\AccessRule::matchCallback|matchCallback]]: specifies a PHP callable that should be called to determine
108-
if this rule should be applied.
106+
* [[yii\filters\AccessRule::ips|ips]]: どの [[yii\web\Request::userIP|クライアントの IP アドレス]] にこの規則が適用されるかを指定します。
107+
IP アドレスは、最後にワイルドカード `*` を含むことが出来て、同じプレフィクスを持つ IP アドレスに合致させることが出来ます。
108+
例えば、'192.168.*' は、'192.168.' のセグメントに属する全ての IP アドレスに合致します。
109+
このオプションが空であるか指定されていない場合は、規則が全ての IP アドレスに適用されることを意味します。
109110

110-
* [[yii\filters\AccessRule::denyCallback|denyCallback]]: specifies a PHP callable that should be called when this rule
111-
will deny the access.
111+
* [[yii\filters\AccessRule::verbs|verbs]]: どのリクエストメソッド (例えば、`GET``POST`) にこの規則が適用されるかを指定します。
112+
比較は大文字と小文字を区別しません。
112113

113-
Below is an example showing how to make use of the `matchCallback` option, which allows you to write arbitrary access
114-
check logic:
114+
* [[yii\filters\AccessRule::matchCallback|matchCallback]]: この規則が適用されるべきか否かを決定するために呼び出されるべき PHP コーラブルを指定します。
115+
116+
* [[yii\filters\AccessRule::denyCallback|denyCallback]]: この規則がアクセスを禁止する場合に呼び出されるべき PHP コーラブルを指定します。
117+
118+
下記は、`matchCallback` オプションを利用する方法を示す例です。
119+
このオプションによって、任意のアクセス制御ロジックを書くことが可能になります。
115120

116121
```php
117122
use yii\filters\AccessControl;
@@ -137,7 +142,7 @@ class SiteController extends Controller
137142
];
138143
}
139144

140-
// Match callback called! This page can be accessed only each October 31st
145+
// matchCallback が呼ばれる。このページは毎年10月31日だけアクセス出来ます。
141146
public function actionSpecialCallback()
142147
{
143148
return $this->render('happy-halloween');

0 commit comments

Comments
 (0)