|
| 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