Skip to content

Commit

Permalink
動的にログイン設定タブを読み込む
Browse files Browse the repository at this point in the history
  • Loading branch information
akagane99 committed Dec 8, 2017
1 parent 572157c commit 6f770c9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 68 deletions.
117 changes: 52 additions & 65 deletions Controller/AuthSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/

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

/**
* システム管理【ログイン設定】
Expand All @@ -32,88 +31,36 @@ class AuthSettingsController extends SystemManagerAppController {
'SiteManager.SiteSetting',
);

/**
* Other components
*
* @var array
*/
public $components = array(
'Auth.AuthPlugin',
);

/**
* beforeFilter
*
* @return void
* @see SystemManagerHelper::tabs()
**/
public function beforeFilter() {
$authTabs = $this->_getAuthTabs();
$this->set('authTabs', $authTabs);
$this->set('authTabs', $this->_getAuthTabs());
$this->set('activeAuthTab', $this->_getActiveAuthTab());

parent::beforeFilter();
}

/**
* edit
*
* @return void
*/
public function edit() {
// [まだ] 外部プラグインでeditを動かしたい
//$this->_prepare();
$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));

// * 自動ログアウトする時間(gc_maxlifetime)
//$this->request->data['SiteSetting']['Session.ini.session.gc_maxlifetime']['0']['value'] =
// $this->request->data['SiteSetting']['Session.ini.session.cookie_lifetime']['0']['value'];

// [まだ] 保存すると空の1行が余計に登録される
//登録処理
$this->SiteManager->saveData();

} else {
//var_dump($this->request->query);
//$this->set('activeAuthTab', Hash::get($this->request->query, 'activeAuthTab', 'auth-general'));
$this->set('activeAuthTab', Hash::get($this->request->query, 'activeAuthTab', $tagId));

// 値を設定
$this->request->data['SiteSetting'] = $this->SiteSetting->getSiteSettingForEdit(
array('SiteSetting.key' => array(
//ログイン設定
// * shibbolethログイン
// ** ウェブサーバに設定したShibboleth認証のロケーション
'AuthShibboleth.auth_type_shibbloth_location',
// ** IdPによる個人識別番号に利用する項目
'AuthShibboleth.idp_userid',
// ** 学認 Embedded DS
// *** WAYF URL
'AuthShibboleth.wayf_URL',
// *** エンティティID
'AuthShibboleth.wayf_sp_entityID',
// *** Shibboleth SPのハンドラURL
'AuthShibboleth.wayf_sp_handlerURL',
// *** 認証後に開くURL
'AuthShibboleth.wayf_return_url',
// *** ログインしたままにする にチェックを入れて操作させない
'AuthShibboleth.wayf_force_remember_for_session',
// *** DiscpFeed URL
'AuthShibboleth.wayf_discofeed_url',
// *** 他のフェデレーションのIdPを追加する
'AuthShibboleth.wayf_additional_idps',
)
));
}
}

/**
* 外部認証プラグインのタブを取得
*
* @return array
*/
protected function _getAuthTabs() {
//protected function _prepare() {
$tabs = array();
$authExternalPlugins = AuthenticatorPlugin::getExternals();
$authExternalPlugins = $this->AuthPlugin->getExternals();

foreach ($authExternalPlugins as $plugin) {
//elementを読み込み設定
Expand All @@ -126,4 +73,44 @@ protected function _getAuthTabs() {
return $tabs;
}

/**
* get active auth tab
*
* @return string
*/
protected function _getActiveAuthTab() {
$authExternalPlugins = $this->AuthPlugin->getExternals();
$initTagId = strtr(Inflector::underscore($authExternalPlugins[0]), '_', '-');

if ($this->request->is('post')) {
$activeAuthTab = Hash::get($this->request->data['SiteSetting'], 'activeAuthTab', $initTagId);
} else {
$activeAuthTab = Hash::get($this->request->query, 'activeAuthTab', $initTagId);
}
return $activeAuthTab;
}

/**
* edit
*
* @return void
*/
public function edit() {
$plugin = $this->_getActiveAuthTab();
// プラグイン名(キャメル)に変更
$plugin = strtr($plugin, '-', '_');
$plugin = Inflector::camelize($plugin);
// AuthXXXX.AuthXXXXSetting
$pluginComponent = $plugin . '.' . $plugin . 'Setting';

// コンポーネントの動的ロード
$this->$pluginComponent = $this->Components->load($pluginComponent);
// @see https://book.cakephp.org/2.0/ja/controllers/components.html#id4
// > コンポーネントを動的にロードした場合、初期化メソッドが実行されないことを覚えておいて下さい。 このメソッドで読込んだ場合、ロード後に手動で実行する必要があります。
$this->$pluginComponent->initialize($this);

// $this->AuthXXXXSetting->edit()
$this->$pluginComponent->edit();
}

}
20 changes: 19 additions & 1 deletion Controller/SystemManagerAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ class SystemManagerAppController extends AppController {
* @var array
*/
public $components = array(
'Auth.AuthPlugin',
'ControlPanel.ControlPanelLayout',
'M17n.SwitchLanguage',
'NetCommons.Permission' => array(
'type' => PermissionComponent::CHECK_TYEP_SYSTEM_PLUGIN,
'type' => PermissionComponent::CHECK_TYPE_SYSTEM_PLUGIN,
'allow' => array()
),
'Security',
Expand All @@ -43,4 +44,21 @@ class SystemManagerAppController extends AppController {
public $helpers = array(
'SystemManager.SystemManager',
);

/**
* beforeFilter
*
* @return void
* @see SystemManagerHelper::tabs()
**/
public function beforeFilter() {
// 外部認証プラグイン(AuthXXX)があれば、ログイン設定タブを表示
if ($this->AuthPlugin->getExternals()) {
$this->set('useAuthSettingTab', true);
} else {
$this->set('useAuthSettingTab', false);
}

parent::beforeFilter();
}
}
3 changes: 1 addition & 2 deletions View/Helper/SystemManagerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

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

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

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

Expand Down

0 comments on commit 6f770c9

Please sign in to comment.