mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-23 01:57:50 +08:00
Merge pull request #6606 from softark/docs-guide-ja-security-authentication
Docs guide ja security authentication
This commit is contained in:
@@ -108,11 +108,11 @@ All Rights Reserved.
|
|||||||
セキュリティ
|
セキュリティ
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* **翻訳未着手** [認証](security-authentication.md)
|
* [認証](security-authentication.md)
|
||||||
* **翻訳未着手** [権限](security-authorization.md)
|
* **翻訳中** [権限付与](security-authorization.md)
|
||||||
* **翻訳未着手** [パスワードを扱う](security-passwords.md)
|
* **翻訳中** [パスワードを扱う](security-passwords.md)
|
||||||
* **TBD** [Auth クライアント](security-auth-clients.md)
|
* **TBD** [Auth クライアント](security-auth-clients.md)
|
||||||
* **翻訳未着手** [ベストプラクティス](security-best-practices.md)
|
* **翻訳中** [ベストプラクティス](security-best-practices.md)
|
||||||
|
|
||||||
|
|
||||||
キャッシュ
|
キャッシュ
|
||||||
|
|||||||
6
docs/guide-ja/db-elasticsearch.md
Normal file
6
docs/guide-ja/db-elasticsearch.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Elasticsearch
|
||||||
|
=============
|
||||||
|
|
||||||
|
> Note|注意: この節はまだ執筆中です。
|
||||||
|
>
|
||||||
|
> まだ内容がありません。
|
||||||
6
docs/guide-ja/db-mongodb.md
Normal file
6
docs/guide-ja/db-mongodb.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Mongo DB
|
||||||
|
========
|
||||||
|
|
||||||
|
> Note|注意: この節はまだ執筆中です。
|
||||||
|
>
|
||||||
|
> まだ内容がありません。
|
||||||
6
docs/guide-ja/db-redis.md
Normal file
6
docs/guide-ja/db-redis.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Redis
|
||||||
|
=====
|
||||||
|
|
||||||
|
> Note|注意: この節はまだ執筆中です。
|
||||||
|
>
|
||||||
|
> まだ内容がありません。
|
||||||
6
docs/guide-ja/db-sphinx.md
Normal file
6
docs/guide-ja/db-sphinx.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Sphinx Search
|
||||||
|
=============
|
||||||
|
|
||||||
|
> Note|注意: この節はまだ執筆中です。
|
||||||
|
>
|
||||||
|
> まだ内容がありません。
|
||||||
6
docs/guide-ja/input-multiple-models.md
Normal file
6
docs/guide-ja/input-multiple-models.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
複数のモデルを扱う複雑なフォーム
|
||||||
|
================================
|
||||||
|
|
||||||
|
> Note|注意: この節はまだ執筆中です。
|
||||||
|
>
|
||||||
|
> まだ内容がありません。
|
||||||
6
docs/guide-ja/output-pagination.md
Normal file
6
docs/guide-ja/output-pagination.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
ページネーション
|
||||||
|
================
|
||||||
|
|
||||||
|
> Note|注意: この節はまだ執筆中です。
|
||||||
|
>
|
||||||
|
> まだ内容がありません。
|
||||||
6
docs/guide-ja/output-sorting.md
Normal file
6
docs/guide-ja/output-sorting.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
並べ替え
|
||||||
|
========
|
||||||
|
|
||||||
|
> Note|注意: この節はまだ執筆中です。
|
||||||
|
>
|
||||||
|
> まだ内容がありません。
|
||||||
6
docs/guide-ja/security-auth-clients.md
Normal file
6
docs/guide-ja/security-auth-clients.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Auth クライアント
|
||||||
|
=================
|
||||||
|
|
||||||
|
> Note|注意: この節はまだ執筆中です。
|
||||||
|
>
|
||||||
|
> まだ内容がありません。
|
||||||
92
docs/guide-ja/security-authentication.md
Normal file
92
docs/guide-ja/security-authentication.md
Normal file
@@ -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` 変数 (これ自体はクッキーから読み出されます) をデータベースから読み出された値と比較する必要があるだけです。
|
||||||
Reference in New Issue
Block a user