diff --git a/docs/guide-ja/README.md b/docs/guide-ja/README.md index 7d95d10a2b..2514aab687 100644 --- a/docs/guide-ja/README.md +++ b/docs/guide-ja/README.md @@ -108,11 +108,11 @@ All Rights Reserved. セキュリティ ------------ -* **翻訳未着手** [認証](security-authentication.md) -* **翻訳未着手** [権限](security-authorization.md) -* **翻訳未着手** [パスワードを扱う](security-passwords.md) +* [認証](security-authentication.md) +* **翻訳中** [権限付与](security-authorization.md) +* **翻訳中** [パスワードを扱う](security-passwords.md) * **TBD** [Auth クライアント](security-auth-clients.md) -* **翻訳未着手** [ベストプラクティス](security-best-practices.md) +* **翻訳中** [ベストプラクティス](security-best-practices.md) キャッシュ diff --git a/docs/guide-ja/db-elasticsearch.md b/docs/guide-ja/db-elasticsearch.md new file mode 100644 index 0000000000..411d83d1ab --- /dev/null +++ b/docs/guide-ja/db-elasticsearch.md @@ -0,0 +1,6 @@ +Elasticsearch +============= + +> Note|注意: この節はまだ執筆中です。 +> +> まだ内容がありません。 diff --git a/docs/guide-ja/db-mongodb.md b/docs/guide-ja/db-mongodb.md new file mode 100644 index 0000000000..14302535aa --- /dev/null +++ b/docs/guide-ja/db-mongodb.md @@ -0,0 +1,6 @@ +Mongo DB +======== + +> Note|注意: この節はまだ執筆中です。 +> +> まだ内容がありません。 diff --git a/docs/guide-ja/db-redis.md b/docs/guide-ja/db-redis.md new file mode 100644 index 0000000000..ad8fbe938f --- /dev/null +++ b/docs/guide-ja/db-redis.md @@ -0,0 +1,6 @@ +Redis +===== + +> Note|注意: この節はまだ執筆中です。 +> +> まだ内容がありません。 diff --git a/docs/guide-ja/db-sphinx.md b/docs/guide-ja/db-sphinx.md new file mode 100644 index 0000000000..9a8f486bf6 --- /dev/null +++ b/docs/guide-ja/db-sphinx.md @@ -0,0 +1,6 @@ +Sphinx Search +============= + +> Note|注意: この節はまだ執筆中です。 +> +> まだ内容がありません。 diff --git a/docs/guide-ja/input-multiple-models.md b/docs/guide-ja/input-multiple-models.md new file mode 100644 index 0000000000..bb0df62fc2 --- /dev/null +++ b/docs/guide-ja/input-multiple-models.md @@ -0,0 +1,6 @@ +複数のモデルを扱う複雑なフォーム +================================ + +> Note|注意: この節はまだ執筆中です。 +> +> まだ内容がありません。 diff --git a/docs/guide-ja/output-pagination.md b/docs/guide-ja/output-pagination.md new file mode 100644 index 0000000000..a2019588c4 --- /dev/null +++ b/docs/guide-ja/output-pagination.md @@ -0,0 +1,6 @@ +ページネーション +================ + +> Note|注意: この節はまだ執筆中です。 +> +> まだ内容がありません。 diff --git a/docs/guide-ja/output-sorting.md b/docs/guide-ja/output-sorting.md new file mode 100644 index 0000000000..8f3c0479ab --- /dev/null +++ b/docs/guide-ja/output-sorting.md @@ -0,0 +1,6 @@ +並べ替え +======== + +> Note|注意: この節はまだ執筆中です。 +> +> まだ内容がありません。 diff --git a/docs/guide-ja/security-auth-clients.md b/docs/guide-ja/security-auth-clients.md new file mode 100644 index 0000000000..9f1073cc97 --- /dev/null +++ b/docs/guide-ja/security-auth-clients.md @@ -0,0 +1,6 @@ +Auth クライアント +================= + +> Note|注意: この節はまだ執筆中です。 +> +> まだ内容がありません。 diff --git a/docs/guide-ja/security-authentication.md b/docs/guide-ja/security-authentication.md new file mode 100644 index 0000000000..3247f3a300 --- /dev/null +++ b/docs/guide-ja/security-authentication.md @@ -0,0 +1,92 @@ +認証 +==== + +> Note|注意: この節はまだ執筆中です。 + +認証はユーザが誰であるかを確認する行為であり、ログインプロセスの基礎となるものです。 +典型的には、認証は、識別子 (ユーザ名またはメールアドレス) とパスワードの組み合わせを使用します。 +ユーザはこれらの値をフォームを通じて送信し、アプリケーションは送信された情報を以前に (例えば、ユーザ登録時に) 保存された情報と比較します。 + +Yii では、このプロセス全体が半自動的に実行されます。 +開発者に残されているのは、認証システムにおいて最も重要なクラスである [[yii\web\IdentityInterface]] を実装することだけです。 +典型的には、`IdentityInterface` の実装は `User` モデルを使って達成されます。 + +十分な機能を有する認証の実例を [アドバンストアプリケーションテンプレート](tutorial-advanced-app.md) の中に見出すことが出来ます。 +下記にインターフェイスのメソッドだけをリストします。 + +```php +class User extends ActiveRecord implements IdentityInterface +{ + // ... + + /** + * 与えられた ID によって識別子を探す + * + * @param string|integer $id 探すための ID + * @return IdentityInterface|null 与えられた ID に合致する識別子オブジェクト + */ + public static function findIdentity($id) + { + return static::findOne($id); + } + + /** + * 与えられたトークンによって識別子を探す + * + * @param string $token 探すためのトークン + * @return IdentityInterface|null 与えられたトークンに合致する識別子オブジェクト + */ + public static function findIdentityByAccessToken($token, $type = null) + { + return static::findOne(['access_token' => $token]); + } + + /** + * @return int|string 現在のユーザの ID + */ + public function getId() + { + return $this->id; + } + + /** + * @return string 現在のユーザの認証キー + */ + public function getAuthKey() + { + return $this->auth_key; + } + + /** + * @param string $authKey + * @return boolean 認証キーが現在のユーザに対して有効か否か + */ + public function validateAuthKey($authKey) + { + return $this->getAuthKey() === $authKey; + } +} +``` + +概要を述べたメソッドのうち、二つは単純なものです。 +`findIdentity` は ID の値を受け取って、その ID と関連付けられたモデルのインスタンスを返します。 +`getId` メソッドは ID そのものを返します。 +その他のメソッドのうち、二つのもの - `getAuthKey` と `validateAuthKey` - は、「次回から自動ログイン ("remember me")」のクッキーに対して追加のセキュリティを提供するために使われます。 +`getAuthKey` メソッドは全てのユーザに対してユニークな文字列を返さなければなりません。 +`Yii::$app->getSecurity()->generateRandomString()` を使うと、信頼性の高い方法でユニークな文字列を生成することが出来ます。 +これをユーザのレコードの一部として保存しておくのが良いアイデアです。 + +```php +public function beforeSave($insert) +{ + if (parent::beforeSave($insert)) { + if ($this->isNewRecord) { + $this->auth_key = Yii::$app->getSecurity()->generateRandomString(); + } + return true; + } + return false; +} +``` + +`validateAuthKey` メソッドでは、パラメータとして渡された `$authKey` 変数 (これ自体はクッキーから読み出されます) をデータベースから読み出された値と比較する必要があるだけです。