From 8eb6a595c0093f25070519e58bc4a55274257596 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 7 Sep 2016 17:56:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=80=D0=BE=D1=83=D1=82=D1=8B=20=D0=B2=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D1=81=D1=82=D0=B2=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=81=20=D1=82=D0=B5=D0=BC,=20=D0=BA=D0=B0=D0=BA=20?= =?UTF-8?q?=D0=BE=D0=BD=D0=B8=20=D0=B2=20=D0=B8=D1=82=D0=BE=D0=B3=D0=B5=20?= =?UTF-8?q?=D0=B1=D1=83=D0=B4=D1=83=D1=82=20=D0=BF=D1=80=D0=BE=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=D1=8B=20=D0=B2=20=D0=B4=D0=BE=D0=BA=D1=83?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=86=D0=B8=D0=B8=20=D0=92=20ngi?= =?UTF-8?q?nx=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F,=20=D0=BE=D1=82=D0=B2=D0=B5=D1=87=D0=B0=D1=8E?= =?UTF-8?q?=D1=89=D0=B0=D1=8F=20=D0=B7=D0=B0=20=D0=BF=D1=80=D0=BE=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=81?= =?UTF-8?q?=D0=B5=D1=81=D1=81=D0=B8=D0=BE=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=BE=D0=B2=20=D1=81=D0=BE=20?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D1=80=D0=BE=D0=B3=D0=BE=20=D0=B4=D0=BE=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=92=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20ngi?= =?UTF-8?q?nx=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=81=201.9=20=D0=B4=D0=BE=201.11=20=D0=92=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D1=85=20=D1=81=D0=B5=D1=81=D1=81=D0=B8=D0=BE?= =?UTF-8?q?=D0=BD=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/config/main.php | 4 ++-- api/config/routes.php | 5 ++++ api/modules/authserver/Module.php | 24 +++++++++++++++++++ api/modules/session/Module.php | 13 +--------- docker/nginx/Dockerfile | 2 +- docker/nginx/account.ely.by.conf.template | 15 +++++++----- .../api/_pages/SessionServerRoute.php | 8 +++---- 7 files changed, 46 insertions(+), 25 deletions(-) diff --git a/api/config/main.php b/api/config/main.php index 1bd152b..96d093f 100644 --- a/api/config/main.php +++ b/api/config/main.php @@ -9,7 +9,7 @@ $params = array_merge( return [ 'id' => 'accounts-site-api', 'basePath' => dirname(__DIR__), - 'bootstrap' => ['log', 'authserver', 'sessionserver'], + 'bootstrap' => ['log', 'authserver'], 'controllerNamespace' => 'api\controllers', 'params' => $params, 'components' => [ @@ -56,7 +56,7 @@ return [ 'class' => \api\modules\authserver\Module::class, 'baseDomain' => $params['authserverDomain'], ], - 'sessionserver' => [ + 'session' => [ 'class' => \api\modules\session\Module::class, ], ], diff --git a/api/config/routes.php b/api/config/routes.php index 31cc2e3..2a0f5a0 100644 --- a/api/config/routes.php +++ b/api/config/routes.php @@ -7,4 +7,9 @@ return [ '/oauth2/v1/' => 'oauth/', '/account/v1/info' => 'identity-info/index', + + '/minecraft/session/join' => 'session/session/join', + '/minecraft/session/legacy/join' => 'session/session/join-legacy', + '/minecraft/session/hasJoined' => 'session/session/has-joined', + '/minecraft/session/legacy/hasJoined' => 'session/session/has-joined-legacy', ]; diff --git a/api/modules/authserver/Module.php b/api/modules/authserver/Module.php index 2e1e041..d8bcc11 100644 --- a/api/modules/authserver/Module.php +++ b/api/modules/authserver/Module.php @@ -4,6 +4,7 @@ namespace api\modules\authserver; use Yii; use yii\base\BootstrapInterface; use yii\base\InvalidConfigException; +use yii\web\NotFoundHttpException; class Module extends \yii\base\Module implements BootstrapInterface { @@ -23,6 +24,16 @@ class Module extends \yii\base\Module implements BootstrapInterface { } } + public function beforeAction($action) { + if (!parent::beforeAction($action)) { + return false; + } + + $this->checkHost(); + + return true; + } + /** * @param \yii\base\Application $app the application currently running */ @@ -40,4 +51,17 @@ class Module extends \yii\base\Module implements BootstrapInterface { Yii::info($message, 'legacy-authserver'); } + /** + * Поскольку это legacy метод и документации в новой среде для него не будет, + * нет смысла выставлять на показ внутренние url, так что ограничиваем доступ + * только для заходов по старому домену + * + * @throws NotFoundHttpException + */ + protected function checkHost() { + if (Yii::$app->request->getHostInfo() !== $this->baseDomain) { + throw new NotFoundHttpException(); + } + } + } diff --git a/api/modules/session/Module.php b/api/modules/session/Module.php index 365ffb0..63f1cad 100644 --- a/api/modules/session/Module.php +++ b/api/modules/session/Module.php @@ -2,24 +2,13 @@ namespace api\modules\session; use Yii; -use yii\base\BootstrapInterface; -class Module extends \yii\base\Module implements BootstrapInterface { +class Module extends \yii\base\Module { public $id = 'session'; public $defaultRoute = 'session'; - /** - * @param \yii\base\Application $app the application currently running - */ - public function bootstrap($app) { - $app->getUrlManager()->addRules([ - // TODO: define normal routes - //$this->baseDomain . '/' . $this->id . '/auth/' => $this->id . '/authentication/', - ], false); - } - public static function info($message) { Yii::info($message, 'session'); } diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile index e7f976e..ed15437 100644 --- a/docker/nginx/Dockerfile +++ b/docker/nginx/Dockerfile @@ -1,4 +1,4 @@ -FROM nginx:1.9 +FROM nginx:1.11 COPY nginx.conf /etc/nginx/nginx.conf COPY account.ely.by.conf.template /etc/nginx/conf.d/account.ely.by.conf.template diff --git a/docker/nginx/account.ely.by.conf.template b/docker/nginx/account.ely.by.conf.template index 7430d72..67410fd 100644 --- a/docker/nginx/account.ely.by.conf.template +++ b/docker/nginx/account.ely.by.conf.template @@ -4,7 +4,6 @@ server { set $root_path '/var/www/html'; set $api_path '${root_path}/api/web'; set $frontend_path '${root_path}/frontend/dist'; - set $authserver_host '${AUTHSERVER_HOST}'; root $root_path; charset utf-8; @@ -12,15 +11,19 @@ server { etag on; set $request_url $request_uri; - if ($host = $authserver_host) { + set $host_with_uri '${host}${request_uri}'; + + if ($host_with_uri ~* '^${AUTHSERVER_HOST}/auth') { set $request_url '/api/authserver${request_uri}'; + rewrite ^/auth /api/authserver$uri last; + } + + if ($host_with_uri ~* '^${AUTHSERVER_HOST}/session') { + set $request_url '/api/minecraft${request_uri}'; + rewrite ^/session /api/minecraft$uri last; } location / { - if ($host = $authserver_host) { - rewrite ^ /api/authserver$uri last; - } - alias $frontend_path; index index.html; try_files $uri /index.html =404; diff --git a/tests/codeception/api/_pages/SessionServerRoute.php b/tests/codeception/api/_pages/SessionServerRoute.php index d136aac..7e102ff 100644 --- a/tests/codeception/api/_pages/SessionServerRoute.php +++ b/tests/codeception/api/_pages/SessionServerRoute.php @@ -9,22 +9,22 @@ use yii\codeception\BasePage; class SessionServerRoute extends BasePage { public function join($params) { - $this->route = ['sessionserver/session/join']; + $this->route = '/minecraft/session/join'; $this->actor->sendPOST($this->getUrl(), $params); } public function joinLegacy(array $params) { - $this->route = ['sessionserver/session/join-legacy']; + $this->route = '/minecraft/session/legacy/join'; $this->actor->sendGET($this->getUrl(), $params); } public function hasJoined(array $params) { - $this->route = ['sessionserver/session/has-joined']; + $this->route = '/minecraft/session/hasJoined'; $this->actor->sendGET($this->getUrl(), $params); } public function hasJoinedLegacy(array $params) { - $this->route = ['sessionserver/session/has-joined-legacy']; + $this->route = '/minecraft/session/legacy/hasJoined'; $this->actor->sendGET($this->getUrl(), $params); }