Skip to content

Commit

Permalink
処理見直して、UtilのAuthenticatorPluginを利用
Browse files Browse the repository at this point in the history
  • Loading branch information
akagane99 committed Dec 7, 2017
1 parent 55c1a70 commit 572157c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 88 deletions.
76 changes: 9 additions & 67 deletions Controller/AuthSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

App::uses('SystemManagerAppController', 'SystemManager.Controller');
App::uses('AuthenticatorPlugin', 'Auth.Utility');

/**
* システム管理【ログイン設定】
Expand All @@ -22,11 +23,6 @@
*/
class AuthSettingsController extends SystemManagerAppController {

/**
* @var array authenticators
*/
protected $_authenticators = array();

/**
* use model
*
Expand All @@ -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
*
Expand All @@ -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));
Expand All @@ -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
Expand All @@ -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',
Expand All @@ -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);
}

}
23 changes: 2 additions & 21 deletions View/Helper/SystemManagerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

App::uses('AppHelper', 'View/Helper');
App::uses('AuthenticatorPlugin', 'Auth.Utility');

/**
* システム管理ヘルパー
Expand Down Expand Up @@ -103,7 +104,7 @@ public function tabs($active = null) {
}

// 外部認証プラグイン(AuthXXX)がなければ、ログイン設定タブを除外
if (! $this->__isAuthTab()) {
if (! AuthenticatorPlugin::getExternals()) {
unset($this->_tabs['auth_settings']);
}

Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"require": {
"cakedc/migrations": "~2.2",
"netcommons/auth": "@dev",
"netcommons/control-panel": "@dev",
"netcommons/net-commons": "@dev",
"netcommons/plugin-manager": "@dev",
Expand Down

0 comments on commit 572157c

Please sign in to comment.