2016-08-21 04:51:39 +05:30
|
|
|
<?php
|
|
|
|
namespace api\modules\authserver;
|
|
|
|
|
2016-08-29 04:47:45 +05:30
|
|
|
use Yii;
|
2016-08-21 04:51:39 +05:30
|
|
|
use yii\base\BootstrapInterface;
|
|
|
|
use yii\base\InvalidConfigException;
|
2016-09-07 20:26:30 +05:30
|
|
|
use yii\web\NotFoundHttpException;
|
2016-08-21 04:51:39 +05:30
|
|
|
|
|
|
|
class Module extends \yii\base\Module implements BootstrapInterface {
|
|
|
|
|
|
|
|
public $id = 'authserver';
|
|
|
|
|
|
|
|
public $defaultRoute = 'index';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string базовый домен, запросы на который этот модуль должен обрабатывать
|
|
|
|
*/
|
2016-09-21 13:43:43 +05:30
|
|
|
public $host = 'authserver.ely.by';
|
2016-08-21 04:51:39 +05:30
|
|
|
|
|
|
|
public function init() {
|
|
|
|
parent::init();
|
2016-09-21 13:43:43 +05:30
|
|
|
if ($this->host === null) {
|
2016-08-21 04:51:39 +05:30
|
|
|
throw new InvalidConfigException('base domain must be specified');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-07 20:26:30 +05:30
|
|
|
public function beforeAction($action) {
|
|
|
|
if (!parent::beforeAction($action)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->checkHost();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-21 04:51:39 +05:30
|
|
|
/**
|
|
|
|
* @param \yii\base\Application $app the application currently running
|
|
|
|
*/
|
|
|
|
public function bootstrap($app) {
|
|
|
|
$app->getUrlManager()->addRules([
|
2016-09-21 13:43:43 +05:30
|
|
|
"http://$this->host/$this->id/auth/<action>" => "$this->id/authentication/<action>",
|
2016-08-21 04:51:39 +05:30
|
|
|
], false);
|
|
|
|
}
|
|
|
|
|
2016-08-29 04:47:45 +05:30
|
|
|
public static function info($message) {
|
|
|
|
Yii::info($message, 'legacy-authserver');
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function error($message) {
|
|
|
|
Yii::info($message, 'legacy-authserver');
|
|
|
|
}
|
|
|
|
|
2016-09-07 20:26:30 +05:30
|
|
|
/**
|
|
|
|
* Поскольку это legacy метод и документации в новой среде для него не будет,
|
|
|
|
* нет смысла выставлять на показ внутренние url, так что ограничиваем доступ
|
|
|
|
* только для заходов по старому домену
|
|
|
|
*
|
|
|
|
* @throws NotFoundHttpException
|
|
|
|
*/
|
|
|
|
protected function checkHost() {
|
2016-09-21 13:43:43 +05:30
|
|
|
if (parse_url(Yii::$app->request->getHostInfo(), PHP_URL_HOST) !== $this->host) {
|
2016-09-07 20:26:30 +05:30
|
|
|
throw new NotFoundHttpException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-21 04:51:39 +05:30
|
|
|
}
|