Skip to content

Commit d30e341

Browse files
authored
Merge pull request #48 from NetCommons3/auth_external
外部認証プラグイン用のComponent追加
2 parents 00cd87d + d0bfb56 commit d30e341

File tree

2 files changed

+94
-9
lines changed

2 files changed

+94
-9
lines changed

Controller/AuthAppController.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
*/
2020
class AuthAppController extends AppController {
2121

22+
/**
23+
* Other components
24+
*
25+
* @var array
26+
*/
27+
public $components = array(
28+
'Auth.AuthPlugin',
29+
);
30+
2231
/**
2332
* Return authentication adapter name
2433
*
@@ -34,15 +43,7 @@ protected static function _getAuthenticator() {
3443
* @return array authenticators
3544
*/
3645
protected function _getAuthenticators() {
37-
$authenticators = array();
38-
$plugins = App::objects('plugins');
39-
foreach ($plugins as $plugin) {
40-
if (preg_match('/^Auth([A-Z0-9_][\w]+)/', $plugin)) {
41-
$authenticators[] = Inflector::underscore($plugin);
42-
}
43-
}
44-
45-
return $authenticators;
46+
return $this->AuthPlugin->getAuthenticators();
4647
}
4748

4849
/**
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* AuthShibboleth Component
4+
*
5+
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
6+
* @link http://www.netcommons.org NetCommons Project
7+
* @license http://www.netcommons.org/license.txt NetCommons License
8+
* @copyright Copyright 2014, NetCommons Project
9+
*/
10+
11+
App::uses('Component', 'Controller');
12+
13+
/**
14+
* AuthShibboleth Component
15+
*
16+
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
17+
* @package NetCommons\AuthShibboleth\Controller\Component
18+
* @property SessionComponent $Session
19+
*/
20+
class AuthPluginComponent extends Component {
21+
22+
/**
23+
* @var Controller コントローラ
24+
*/
25+
protected $_controller = null;
26+
27+
/**
28+
* Called before the Controller::beforeFilter().
29+
*
30+
* @param Controller $controller Instantiating controller
31+
* @return void
32+
* @link http://book.cakephp.org/2.0/ja/controllers/components.html#Component::initialize
33+
*/
34+
public function initialize(Controller $controller) {
35+
// どのファンクションでも $controller にアクセスできるようにクラス内変数に保持する
36+
$this->_controller = $controller;
37+
}
38+
39+
/**
40+
* Return available authenticators (Camel)
41+
*
42+
* @return array authenticators (Camel)
43+
*/
44+
public function getPlugins() {
45+
$authenticators = array();
46+
$plugins = App::objects('plugins');
47+
foreach ($plugins as $plugin) {
48+
if (preg_match('/^Auth([A-Z0-9_][\w]+)/', $plugin)) {
49+
$authenticators[] = $plugin;
50+
}
51+
}
52+
53+
return $authenticators;
54+
}
55+
56+
/**
57+
* Return available authenticators (under_score)
58+
*
59+
* @return array authenticators
60+
*/
61+
public function getAuthenticators() {
62+
$authenticators = $this->getPlugins();
63+
foreach ($authenticators as &$plugin) {
64+
$plugin = Inflector::underscore($plugin);
65+
}
66+
67+
return $authenticators;
68+
}
69+
70+
/**
71+
* AuthGeneral以外の外部認証プラグイン(AuthXXX)を取得
72+
*
73+
* @return array external authenticators
74+
*/
75+
public function getExternals() {
76+
$authenticators = $this->getPlugins();
77+
// array_diffを利用して 配列の値AuthGeneralを削除
78+
$authenticators = array_diff($authenticators, array('AuthGeneral'));
79+
// 配列indexの再設定
80+
$authenticators = array_values($authenticators);
81+
return $authenticators;
82+
}
83+
84+
}

0 commit comments

Comments
 (0)