From 572157ce2c0640a0009eea472dfd6a6f2bdb35a9 Mon Sep 17 00:00:00 2001 From: Mitsuru Mutaguchi Date: Thu, 7 Dec 2017 05:46:01 +0000 Subject: [PATCH] =?UTF-8?q?=E5=87=A6=E7=90=86=E8=A6=8B=E7=9B=B4=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=80=81Util=E3=81=AEAuthenticatorPlugin=E3=82=92?= =?UTF-8?q?=E5=88=A9=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/AuthSettingsController.php | 76 ++++----------------------- View/Helper/SystemManagerHelper.php | 23 +------- composer.json | 1 + 3 files changed, 12 insertions(+), 88 deletions(-) diff --git a/Controller/AuthSettingsController.php b/Controller/AuthSettingsController.php index 7c12ca9..1dd614c 100644 --- a/Controller/AuthSettingsController.php +++ b/Controller/AuthSettingsController.php @@ -11,6 +11,7 @@ */ App::uses('SystemManagerAppController', 'SystemManager.Controller'); +App::uses('AuthenticatorPlugin', 'Auth.Utility'); /** * システム管理【ログイン設定】 @@ -22,11 +23,6 @@ */ class AuthSettingsController extends SystemManagerAppController { -/** - * @var array authenticators - */ - protected $_authenticators = array(); - /** * use model * @@ -43,41 +39,12 @@ class AuthSettingsController extends SystemManagerAppController { * @see SystemManagerHelper::tabs() **/ public function beforeFilter() { - // SystemManagerHelper::tabs() で、外部認証プラグイン(AuthXXXX)がないと、ログイン設定タブを表示しないため、 - // このコントローラに来てる時点で、$this->_authenticatorsには外部認証プラグインのプラグイン名が1つ以上ある - $this->_authenticators = $this->_getAuthenticators(); - //$this->set('authenticators', $authenticators); - $authTabs = $this->_getAuthTabs(); $this->set('authTabs', $authTabs); parent::beforeFilter(); } -/** - * Return available authenticators - * - * @return array authenticators - * @see AuthAppController::_getAuthenticators() からコピー - */ - protected function _getAuthenticators() { - $authenticators = array(); - $plugins = App::objects('plugins'); - foreach ($plugins as $plugin) { - // @see https://regexper.com/#%5EAuth(%5BA-Z0-9_%5D%5B%5Cw%5D%2B) - if (preg_match('/^Auth([A-Z0-9_][\w]+)/', $plugin)) { - if ($plugin === 'AuthGeneral') { - // AuthGeneralは含めない - continue; - } - //$authenticators[] = Inflector::underscore($plugin); - $authenticators[] = $plugin; - } - } - - return $authenticators; - } - /** * edit * @@ -86,11 +53,12 @@ protected function _getAuthenticators() { public function edit() { // [まだ] 外部プラグインでeditを動かしたい //$this->_prepare(); - $tagId = strtr(Inflector::underscore($this->_authenticators[0]), '_', '-'); + $authExternalPlugins = AuthenticatorPlugin::getExternals(); + // [まだ] $tagIdは、初期表示は[0], 更新したらそのAuthXXXXを指定したい + $tagId = strtr(Inflector::underscore($authExternalPlugins[0]), '_', '-'); //リクエストセット if ($this->request->is('post')) { - // [まだ] 必須チェック //$this->set('activeAuthTab', Hash::get($this->request->data['SiteSetting'], 'activeAuthTab', 'auth-general')); $this->set('activeAuthTab', Hash::get($this->request->data['SiteSetting'], 'activeAuthTab', $tagId)); @@ -111,12 +79,11 @@ public function edit() { // 値を設定 $this->request->data['SiteSetting'] = $this->SiteSetting->getSiteSettingForEdit( array('SiteSetting.key' => array( - 'App.default_timezone', //ログイン設定 // * shibbolethログイン // ** ウェブサーバに設定したShibboleth認証のロケーション 'AuthShibboleth.auth_type_shibbloth_location', - // ** IdPによる個人識別番号 + // ** IdPによる個人識別番号に利用する項目 'AuthShibboleth.idp_userid', // ** 学認 Embedded DS // *** WAYF URL @@ -129,7 +96,7 @@ public function edit() { 'AuthShibboleth.wayf_return_url', // *** ログインしたままにする にチェックを入れて操作させない 'AuthShibboleth.wayf_force_remember_for_session', - // *** 表示IdP絞り込みDiscpFeed URL + // *** DiscpFeed URL 'AuthShibboleth.wayf_discofeed_url', // *** 他のフェデレーションのIdPを追加する 'AuthShibboleth.wayf_additional_idps', @@ -139,49 +106,24 @@ public function edit() { } /** - * 前処理 - * 他の認証の設定画面を組み込みについては、後で考える + * 外部認証プラグインのタブを取得 * * @return array */ protected function _getAuthTabs() { //protected function _prepare() { $tabs = array(); + $authExternalPlugins = AuthenticatorPlugin::getExternals(); - //$plugins = App::objects('plugins'); - - //foreach ($plugins as $plugin) { - foreach ($this->_authenticators as $plugin) { - // $matches = array(); - // // @see https://regexper.com/#%5EAuth(%5BA-Z0-9_%5D%5B%5Cw%5D%2B) - // if (! preg_match('/^Auth([A-Z0-9_][\w]+)/', $plugin, $matches)) { - // continue; - // } - // if ($plugin === 'AuthGeneral') { - // // AuthGeneralは含めない - // //continue; - // } - + foreach ($authExternalPlugins as $plugin) { //elementを読み込み設定 $tagId = strtr(Inflector::underscore($plugin), '_', '-'); - - // if ($plugin === 'AuthGeneral') { - // $tabs[$tagId] = array( - // 'label' => __d('system_manager', 'Auth common setting'), - // 'element' => 'AuthSettings/auth_form' - // ); - // } - // $plugin キャメル - // var_dump($tagId, $plugin, Inflector::underscore($plugin)); - // var_dump(Inflector::humanize(Inflector::underscore($plugin)), Inflector::camelize($plugin)); - $tabs[$tagId] = array( 'label' => __d(Inflector::underscore($plugin), $plugin . '.setting.label'), 'element' => $plugin . '.setting' ); } return $tabs; - //$this->set('authTabs', $tabs); } } diff --git a/View/Helper/SystemManagerHelper.php b/View/Helper/SystemManagerHelper.php index 9aa9b76..9a83ac2 100644 --- a/View/Helper/SystemManagerHelper.php +++ b/View/Helper/SystemManagerHelper.php @@ -10,6 +10,7 @@ */ App::uses('AppHelper', 'View/Helper'); +App::uses('AuthenticatorPlugin', 'Auth.Utility'); /** * システム管理ヘルパー @@ -103,7 +104,7 @@ public function tabs($active = null) { } // 外部認証プラグイン(AuthXXX)がなければ、ログイン設定タブを除外 - if (! $this->__isAuthTab()) { + if (! AuthenticatorPlugin::getExternals()) { unset($this->_tabs['auth_settings']); } @@ -172,24 +173,4 @@ public function authTabs() { return $output; } -/** - * Authタブに表示するAuthGeneral以外の外部プラグイン(AuthXXX)があるか - * - * @return string HTML - */ - private function __isAuthTab() { - $plugins = App::objects('plugins'); - - foreach ($plugins as $plugin) { - $matches = array(); - if (! preg_match('/^Auth([A-Z0-9_][\w]+)/', $plugin, $matches)) { - continue; - } - if ($plugin === 'AuthGeneral') { - continue; - } - return true; - } - return false; - } } diff --git a/composer.json b/composer.json index 5605587..3e78a47 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ }, "require": { "cakedc/migrations": "~2.2", + "netcommons/auth": "@dev", "netcommons/control-panel": "@dev", "netcommons/net-commons": "@dev", "netcommons/plugin-manager": "@dev",