summaryrefslogtreecommitdiff
path: root/lib/plugins
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2014-02-14 13:57:50 +0100
committerAndreas Gohr <andi@splitbrain.org>2014-02-14 13:57:50 +0100
commit741b8a48682890ee68e3f650510fec9a4d47d5b0 (patch)
tree54c03dcbf2944dbc1f49fc3f2f063751f1ad2aa7 /lib/plugins
parent4f1a1db1539e819e5c40ec14453c4c709810e1bd (diff)
downloadrpg-741b8a48682890ee68e3f650510fec9a4d47d5b0.tar.gz
rpg-741b8a48682890ee68e3f650510fec9a4d47d5b0.tar.bz2
Show a domain dropdown when multiple AD domains are configured
This integrates the functionality of the now outdated addomain plugin directly into the authad plugin and makes multi-domain setups usable without SSO. See also https://github.com/cosmocode/dokuwiki-plugin-addomain
Diffstat (limited to 'lib/plugins')
-rw-r--r--lib/plugins/authad/action.php91
-rw-r--r--lib/plugins/authad/auth.php25
-rw-r--r--lib/plugins/authad/plugin.info.txt2
3 files changed, 117 insertions, 1 deletions
diff --git a/lib/plugins/authad/action.php b/lib/plugins/authad/action.php
index e69de29bb..97be9897e 100644
--- a/lib/plugins/authad/action.php
+++ b/lib/plugins/authad/action.php
@@ -0,0 +1,91 @@
+<?php
+/**
+ * DokuWiki Plugin addomain (Action Component)
+ *
+ * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
+ * @author Andreas Gohr <gohr@cosmocode.de>
+ */
+
+// must be run within Dokuwiki
+if(!defined('DOKU_INC')) die();
+
+/**
+ * Class action_plugin_addomain
+ */
+class action_plugin_authad extends DokuWiki_Action_Plugin {
+
+ /**
+ * Registers a callback function for a given event
+ */
+ public function register(Doku_Event_Handler &$controller) {
+
+ $controller->register_hook('AUTH_LOGIN_CHECK', 'BEFORE', $this, 'handle_auth_login_check');
+ $controller->register_hook('HTML_LOGINFORM_OUTPUT', 'BEFORE', $this, 'handle_html_loginform_output');
+
+ }
+
+ /**
+ * Adds the selected domain as user postfix when attempting a login
+ *
+ * @param Doku_Event $event
+ * @param array $param
+ */
+ public function handle_auth_login_check(Doku_Event &$event, $param) {
+ global $INPUT;
+
+ /** @var auth_plugin_authad $auth */
+ global $auth;
+ if(!is_a($auth, 'auth_plugin_authad')) return; // AD not even used
+
+ if($INPUT->str('dom')) {
+ $usr = $auth->cleanUser($event->data['user']);
+ $dom = $auth->_userDomain($usr);
+ if(!$dom) {
+ $usr = "$usr@".$INPUT->str('dom');
+ }
+ $INPUT->post->set('u', $usr);
+ $event->data['user'] = $usr;
+ }
+ }
+
+ /**
+ * Shows a domain selection in the login form when more than one domain is configured
+ *
+ * @param Doku_Event $event
+ * @param array $param
+ */
+ public function handle_html_loginform_output(Doku_Event &$event, $param) {
+ global $INPUT;
+ /** @var auth_plugin_authad $auth */
+ global $auth;
+ if(!is_a($auth, 'auth_plugin_authad')) return; // AD not even used
+ $domains = $auth->_getConfiguredDomains();
+ if(count($domains) <= 1) return; // no choice at all
+
+ /** @var Doku_Form $form */
+ $form =& $event->data;
+
+ // any default?
+ $dom = '';
+ if($INPUT->has('u')) {
+ $usr = $auth->cleanUser($INPUT->str('u'));
+ $dom = $auth->_userDomain($usr);
+
+ // update user field value
+ if($dom) {
+ $usr = $auth->_userName($usr);
+ $pos = $form->findElementByAttribute('name', 'u');
+ $ele =& $form->getElementAt($pos);
+ $ele['value'] = $usr;
+ }
+ }
+
+ // add select box
+ $element = form_makeListboxField('dom', $domains, $dom, $this->getLang('domain'), '', 'block');
+ $pos = $form->findElementByAttribute('name', 'p');
+ $form->insertElement($pos + 1, $element);
+ }
+
+}
+
+// vim:ts=4:sw=4:et: \ No newline at end of file
diff --git a/lib/plugins/authad/auth.php b/lib/plugins/authad/auth.php
index e1d758fb8..db9b179a6 100644
--- a/lib/plugins/authad/auth.php
+++ b/lib/plugins/authad/auth.php
@@ -512,6 +512,31 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin {
}
/**
+ * Returns a list of configured domains
+ *
+ * The default domain has an empty string as key
+ *
+ * @return array associative array(key => domain)
+ */
+ public function _getConfiguredDomains() {
+ $domains = array();
+ if(empty($this->conf['account_suffix'])) return $domains; // not configured yet
+
+ // add default domain, using the name from account suffix
+ $domains[''] = ltrim($this->conf['account_suffix'], '@');
+
+ // find additional domains
+ foreach($this->conf as $key => $val) {
+ if(is_array($val) && isset($val['account_suffix'])) {
+ $domains[$key] = ltrim($val['account_suffix'], '@');
+ }
+ }
+ ksort($domains);
+
+ return $domains;
+ }
+
+ /**
* Check provided user and userinfo for matching patterns
*
* The patterns are set up with $this->_constructPattern()
diff --git a/lib/plugins/authad/plugin.info.txt b/lib/plugins/authad/plugin.info.txt
index 3af1ddfbe..8774fcf3c 100644
--- a/lib/plugins/authad/plugin.info.txt
+++ b/lib/plugins/authad/plugin.info.txt
@@ -1,7 +1,7 @@
base authad
author Andreas Gohr
email andi@splitbrain.org
-date 2013-04-25
+date 2014-02-14
name Active Directory Auth Plugin
desc Provides user authentication against a Microsoft Active Directory
url http://www.dokuwiki.org/plugin:authad