Commit 7e47c0bdd3ddd17d6587a4f42c48a0b1211c540d

Authored by Neil Blakey-Milner
1 parent 337c35c2

Add login interceptors and a more dynamic login process.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5873 c91229c3-7414-0410-bfa2-8a42b809f60b
docs/VERSION.txt
1   -3.1
  1 +3.1.6
... ...
lib/authentication/authenticationsource.inc.php
... ... @@ -94,6 +94,14 @@ class KTAuthenticationSource extends KTEntity {
94 94 }
95 95 return KTAuthenticationSource::get($iAuthenticationSourceId);
96 96 }
  97 +
  98 + function &getByAuthenticationProvider($sProvider) {
  99 + return KTEntityUtil::getBy('KTAuthenticationSource', 'authentication_provider', $sProvider);
  100 + }
  101 +
  102 + function &getSources() {
  103 + return KTEntityUtil::getList2('KTAuthenticationSource');
  104 + }
97 105 }
98 106  
99 107 ?>
... ...
lib/authentication/authenticationutil.inc.php
... ... @@ -68,4 +68,16 @@ class KTAuthenticationUtil {
68 68 $oAuthenticator = KTAuthenticationUtil::getAuthenticatorForSource($iSourceId);
69 69 return $oAuthenticator->synchroniseGroup($oGroup);
70 70 }
  71 +
  72 + function autoSignup($sUsername, $aExtra) {
  73 + $aSources = KTAuthenticationSource::getSources();
  74 + foreach ($aSources as $oSource) {
  75 + $oProvider = KTAuthenticationUtil::getAuthenticationProviderForSource($oSource);
  76 + $res = $oProvider->autoSignup($sUsername, $aExtra, $oSource);
  77 + if ($res) {
  78 + return $res;
  79 + }
  80 + }
  81 + return false;
  82 + }
71 83 }
... ...
lib/authentication/interceptor.inc.php 0 → 100644
  1 +<?php
  2 +
  3 +/**
  4 + * $Id$
  5 + *
  6 + * The contents of this file are subject to the KnowledgeTree Public
  7 + * License Version 1.1 ("License"); You may not use this file except in
  8 + * compliance with the License. You may obtain a copy of the License at
  9 + * http://www.ktdms.com/KPL
  10 + *
  11 + * Software distributed under the License is distributed on an "AS IS"
  12 + * basis,
  13 + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14 + * for the specific language governing rights and limitations under the
  15 + * License.
  16 + *
  17 + * The Original Code is: KnowledgeTree Open Source
  18 + *
  19 + * The Initial Developer of the Original Code is The Jam Warehouse Software
  20 + * (Pty) Ltd, trading as KnowledgeTree.
  21 + * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
  22 + * (C) 2006 The Jam Warehouse Software (Pty) Ltd;
  23 + * All Rights Reserved.
  24 + *
  25 + */
  26 +
  27 +require_once(KT_LIB_DIR . "/dispatcher.inc.php");
  28 +
  29 +class KTInterceptor extends KTStandardDispatcher {
  30 + var $sName;
  31 + var $sNamespace;
  32 +
  33 + // Whether we can have multiple instances or not. Default to yes.
  34 + var $bSingleton = false;
  35 +
  36 + function KTInterceptor() {
  37 + return parent::KTStandardDispatcher();
  38 + }
  39 +
  40 + function configure($aInfo) {
  41 + $this->aInfo = $aInfo;
  42 + }
  43 +
  44 + function getName() {
  45 + return $this->sName;
  46 + }
  47 +
  48 + function getNamespace() {
  49 + return $this->sNamespace;
  50 + }
  51 +
  52 + /**
  53 + * Return a user object if the authentication succeeds
  54 + */
  55 + function authenticated() {
  56 + return null;
  57 + }
  58 +
  59 + /**
  60 + * Get an opportunity to take over the request.
  61 + * Remember to exit if you take over.
  62 + */
  63 + function takeOver() {
  64 + return null;
  65 + }
  66 +
  67 + function loginWidgets() {
  68 + return null;
  69 + }
  70 +
  71 + function alternateLogin() {
  72 + return null;
  73 + }
  74 +}
  75 +
  76 +class KTNoLocalUser extends PEAR_Error {
  77 + function KTNoLocalUser($aExtra = null) {
  78 + parent::PEAR_Error(_kt('No local user with that username'));
  79 + $this->aExtra = $aExtra;
  80 + }
  81 +}
... ...
lib/authentication/interceptorinstances.inc.php 0 → 100644
  1 +<?php
  2 +
  3 +/**
  4 + * $Id: authenticationsource.inc.php 5758 2006-07-27 10:17:43Z bshuttle $
  5 + *
  6 + * The contents of this file are subject to the KnowledgeTree Public
  7 + * License Version 1.1 ("License"); You may not use this file except in
  8 + * compliance with the License. You may obtain a copy of the License at
  9 + * http://www.ktdms.com/KPL
  10 + *
  11 + * Software distributed under the License is distributed on an "AS IS"
  12 + * basis,
  13 + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14 + * for the specific language governing rights and limitations under the
  15 + * License.
  16 + *
  17 + * The Original Code is: KnowledgeTree Open Source
  18 + *
  19 + * The Initial Developer of the Original Code is The Jam Warehouse Software
  20 + * (Pty) Ltd, trading as KnowledgeTree.
  21 + * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
  22 + * (C) 2006 The Jam Warehouse Software (Pty) Ltd;
  23 + * All Rights Reserved.
  24 + *
  25 + */
  26 +
  27 +require_once(KT_LIB_DIR . "/users/User.inc");
  28 +require_once(KT_LIB_DIR . "/ktentity.inc");
  29 +
  30 +class KTInterceptorInstance extends KTEntity {
  31 + var $sName;
  32 + var $sInterceptorNamespace;
  33 + var $sAuthenticationProvider;
  34 + var $sConfig = "";
  35 +
  36 + var $_aFieldToSelect = array(
  37 + "iId" => "id",
  38 + "sName" => "name",
  39 + "sInterceptorNamespace" => "interceptor_namespace",
  40 + "sConfig" => "config",
  41 + );
  42 +
  43 + var $_bUsePearError = true;
  44 +
  45 + function getName() { return $this->sName; }
  46 + function getInterceptorNamespace() { return $this->sInterceptorNamespace; }
  47 + function getConfig() { return $this->sConfig; }
  48 + function setName($sName) { $this->sName = $sName; }
  49 + function setInterceptorNamespace($mValue) { $this->sInterceptorNamespace = $mValue; }
  50 + function setConfig($sConfig) { $this->sConfig = $sConfig; }
  51 +
  52 + function _table () {
  53 + return KTUtil::getTableName('interceptor_instances');
  54 + }
  55 +
  56 + // STATIC
  57 + function &get($iId) {
  58 + return KTEntityUtil::get('KTInterceptorInstance', $iId);
  59 + }
  60 +
  61 + // STATIC
  62 + function &createFromArray($aOptions) {
  63 + return KTEntityUtil::createFromArray('KTInterceptorInstance', $aOptions);
  64 + }
  65 +
  66 + // STATIC
  67 + function &getList($sWhereClause = null) {
  68 + return KTEntityUtil::getList2('KTInterceptorInstance', $sWhereClause);
  69 + }
  70 +
  71 + // STATIC
  72 + function &getByInterceptorNamespace($sNamespace) {
  73 + return KTEntityUtil::getBy('KTInterceptorInstance', 'namespace', $sNamespace);
  74 + }
  75 +
  76 + function &getInterceptorInstances() {
  77 + return KTEntityUtil::getList2('KTInterceptorInstance', $sWhereClause);
  78 + }
  79 +}
  80 +
  81 +?>
... ...
lib/authentication/interceptorregistry.inc.php 0 → 100644
  1 +<?php
  2 +
  3 +/**
  4 + * $Id$
  5 + *
  6 + * The contents of this file are subject to the KnowledgeTree Public
  7 + * License Version 1.1 ("License"); You may not use this file except in
  8 + * compliance with the License. You may obtain a copy of the License at
  9 + * http://www.ktdms.com/KPL
  10 + *
  11 + * Software distributed under the License is distributed on an "AS IS"
  12 + * basis,
  13 + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14 + * for the specific language governing rights and limitations under the
  15 + * License.
  16 + *
  17 + * The Original Code is: KnowledgeTree Open Source
  18 + *
  19 + * The Initial Developer of the Original Code is The Jam Warehouse Software
  20 + * (Pty) Ltd, trading as KnowledgeTree.
  21 + * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
  22 + * (C) 2006 The Jam Warehouse Software (Pty) Ltd;
  23 + * All Rights Reserved.
  24 + *
  25 + */
  26 +
  27 +require_once(KT_LIB_DIR . '/authentication/interceptorinstances.inc.php');
  28 +
  29 +/**
  30 + * This is where all login interceptors register themselves as available
  31 + * to the system.
  32 + *
  33 + * Login interceptors allow for the login process to be more dynamic -
  34 + * to call external programs to perform authentication, to redirect to
  35 + * external authentication web sites, and so forth.
  36 + */
  37 +class KTInterceptorRegistry {
  38 + var $_aInterceptorsInfo = array();
  39 +
  40 + // {{{ getSingleton
  41 + function &getSingleton () {
  42 + if (!KTUtil::arrayGet($GLOBALS['_KT_PLUGIN'], 'oKTInterceptorRegistry')) {
  43 + $GLOBALS['_KT_PLUGIN']['oKTInterceptorRegistry'] = new KTInterceptorRegistry;
  44 + }
  45 + return $GLOBALS['_KT_PLUGIN']['oKTInterceptorRegistry'];
  46 + }
  47 + // }}}
  48 +
  49 + function registerInterceptor($class, $nsname, $path = "", $sPlugin = null) {
  50 + $this->_aInterceptorsInfo[$nsname] = array($class, $nsname, $path, $sPlugin);
  51 + }
  52 +
  53 + function getInterceptorInfo($nsname) {
  54 + return $this->_aInterceptorsInfo[$nsname];
  55 + }
  56 +
  57 + function &getInterceptor($nsname, $config = null) {
  58 + $aInfo = $this->_aInterceptorsInfo[$nsname];
  59 + $sClass = $aInfo[0];
  60 + $sPath = $aInfo[2];
  61 + if ($sPath) {
  62 + if (file_exists($sPath)) {
  63 + require_once($sPath);
  64 + }
  65 + }
  66 + if (!class_exists($sClass)) {
  67 + return PEAR::raiseError(sprintf(_kt("Can't find interceptor: %s"), $nsname));
  68 + }
  69 + $oInterceptor =& new $sClass;
  70 + if ($config) {
  71 + $oInterceptor->configure($config);
  72 + }
  73 + return $oInterceptor;
  74 + }
  75 +
  76 + function &getInterceptorFromInstance($oInstance) {
  77 + return $this->getInterceptor($oInstance->getInterceptorNamespace(), $oInstance->getConfig());
  78 + }
  79 +
  80 + function &getConfiguredInstances() {
  81 + $aInterceptorInstances = $this->_getInterceptorInstances();
  82 + $aReturn = array();
  83 + foreach ($aInterceptorInstances as $oInstance) {
  84 + $oInterceptor = $this->getInterceptorFromInstance($oInstance);
  85 + if (PEAR::isError($oInterceptor)) {
  86 + continue;
  87 + }
  88 + $aReturn[] = $oInterceptor;
  89 + }
  90 + return $aReturn;
  91 + }
  92 +
  93 + function checkInterceptorsForAuthenticated() {
  94 + $oRegistry =& KTInterceptorRegistry::getSingleton();
  95 + $aInterceptors = $oRegistry->getConfiguredInstances();
  96 + $aErrors = array();
  97 + foreach ($aInterceptors as $oInterceptor) {
  98 + $oUser = $oInterceptor->authenticated();
  99 + if (PEAR::isError($oUser)) {
  100 + $aErrors[] = $oUser;
  101 + continue;
  102 + }
  103 + if ($oUser) {
  104 + return $oUser;
  105 + }
  106 + }
  107 + if (count($aErrors)) {
  108 + return $aErrors;
  109 + }
  110 + return false;
  111 + }
  112 +
  113 + function _getInterceptorInstances() {
  114 + return KTInterceptorInstance::getInterceptorInstances();
  115 + }
  116 +
  117 + function checkInterceptorsForTakeOver() {
  118 + $oRegistry =& KTInterceptorRegistry::getSingleton();
  119 + $aInterceptors = $oRegistry->getConfiguredInstances();
  120 + foreach ($aInterceptors as $oInterceptor) {
  121 + $oInterceptor->takeover();
  122 + }
  123 + return false;
  124 + }
  125 +}
  126 +
  127 +?>
... ...
lib/plugins/plugin.inc.php
... ... @@ -57,7 +57,7 @@ class KTPlugin {
57 57 var $_aWidgets = array();
58 58 var $_aValidators = array();
59 59 var $_aCriteria = array();
60   -
  60 + var $_aInterceptors = array();
61 61  
62 62 function KTPlugin($sFilename = null) {
63 63 $this->sFilename = $sFilename;
... ... @@ -183,6 +183,10 @@ class KTPlugin {
183 183 $this->_aCriteria[$sNamespace] = array($sClassName, $sNamespace, $sFilename, $aInitialize);
184 184 }
185 185  
  186 + function registerInterceptor($sClassname, $sNamespace, $sPath = null) {
  187 + $sPath = $this->_fixFilename($sPath);
  188 + $this->_aInterceptors[$sNamespace] = array($sClassname, $sNamespace, $sPath);
  189 + }
186 190  
187 191 function _fixFilename($sFilename) {
188 192 if (empty($sFilename)) {
... ... @@ -245,6 +249,7 @@ class KTPlugin {
245 249 require_once(KT_LIB_DIR . "/validation/validatorfactory.inc.php");
246 250 require_once(KT_LIB_DIR . "/browse/columnregistry.inc.php");
247 251 require_once(KT_LIB_DIR . "/browse/criteriaregistry.php");
  252 + require_once(KT_LIB_DIR . "/authentication/interceptorregistry.inc.php");
248 253  
249 254 $oPRegistry =& KTPortletRegistry::getSingleton();
250 255 $oTRegistry =& KTTriggerRegistry::getSingleton();
... ... @@ -262,6 +267,7 @@ class KTPlugin {
262 267 $oWidgetFactory =& KTWidgetFactory::getSingleton();
263 268 $oValidatorFactory =& KTValidatorFactory::getSingleton();
264 269 $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
  270 + $oInterceptorRegistry =& KTInterceptorRegistry::getSingleton();
265 271  
266 272 foreach ($this->_aPortlets as $k => $v) {
267 273 call_user_func_array(array(&$oPRegistry, 'registerPortlet'), $v);
... ... @@ -342,6 +348,10 @@ class KTPlugin {
342 348 foreach ($this->_aValidators as $k => $v) {
343 349 call_user_func_array(array(&$oValidatorFactory, 'registerValidator'), $v);
344 350 }
  351 +
  352 + foreach ($this->_aInterceptors as $k => $v) {
  353 + call_user_func_array(array(&$oInterceptorRegistry, 'registerInterceptor'), $v);
  354 + }
345 355 }
346 356  
347 357 function setup() {
... ...
sql/mysql/install/data.sql
... ... @@ -3,7 +3,7 @@
3 3 -- http://www.phpmyadmin.net
4 4 --
5 5 -- Host: localhost
6   --- Generation Time: Jul 31, 2006 at 10:43 AM
  6 +-- Generation Time: Aug 22, 2006 at 10:19 AM
7 7 -- Server version: 5.0.22
8 8 -- PHP Version: 4.4.2-1build1
9 9  
... ... @@ -391,6 +391,11 @@ INSERT INTO `help` VALUES (100, &#39;pageDisclaimer&#39;, &#39;pageDisclaimer.html&#39;);
391 391  
392 392  
393 393 --
  394 +-- Dumping data for table `interceptor_instances`
  395 +--
  396 +
  397 +
  398 +--
394 399 -- Dumping data for table `links`
395 400 --
396 401  
... ... @@ -732,7 +737,7 @@ INSERT INTO `status_lookup` VALUES (5, &#39;Incomplete&#39;);
732 737 --
733 738  
734 739 INSERT INTO `system_settings` VALUES (1, 'lastIndexUpdate', '0');
735   -INSERT INTO `system_settings` VALUES (2, 'knowledgeTreeVersion', '3.1');
  740 +INSERT INTO `system_settings` VALUES (2, 'knowledgeTreeVersion', '3.1.6');
736 741 INSERT INTO `system_settings` VALUES (3, 'databaseVersion', '2.99.5');
737 742  
738 743 --
... ... @@ -885,6 +890,10 @@ INSERT INTO `upgrades` VALUES (110, &#39;sql*3.0.3.6*0*3.0.3.6/document-restore.sql&#39;
885 890 INSERT INTO `upgrades` VALUES (111, 'func*3.0.3.7*0*rebuildAllPermissions', 'Rebuild all permissions to ensure correct functioning of permission-definitions.', '2006-07-26 11:48:28', 1, 'upgrade*3.0.3.7*99*upgrade3.0.3.7');
886 891 INSERT INTO `upgrades` VALUES (112, 'upgrade*3.0.3.7*99*upgrade3.0.3.7', 'Upgrade from version 3.0.3.5 to 3.0.3.7', '2006-07-26 11:48:28', 1, 'upgrade*3.0.3.7*99*upgrade3.0.3.7');
887 892 INSERT INTO `upgrades` VALUES (113, 'upgrade*3.1*99*upgrade3.1', 'Upgrade from version 3.0.3.7 to 3.1', '2006-07-31 10:41:12', 1, 'upgrade*3.1*99*upgrade3.1');
  893 +INSERT INTO `upgrades` VALUES (114, 'sql*3.1.1*0*3.1.1/parentless-documents.sql', 'Database upgrade to version 3.1.1: Parentless-documents', '2006-08-22 10:13:57', 1, 'upgrade*3.1.6*99*upgrade3.1.6');
  894 +INSERT INTO `upgrades` VALUES (115, 'func*3.1.5*0*upgradeSavedSearches', 'Upgrade saved searches to use namespaces instead of integer ids', '2006-08-22 10:13:57', 1, 'upgrade*3.1.6*99*upgrade3.1.6');
  895 +INSERT INTO `upgrades` VALUES (116, 'sql*3.1.6*0*3.1.6/interceptor_instances.sql', 'Database upgrade to version 3.1.6: Interceptor instances', '2006-08-22 10:13:57', 1, 'upgrade*3.1.6*99*upgrade3.1.6');
  896 +INSERT INTO `upgrades` VALUES (117, 'upgrade*3.1.6*99*upgrade3.1.6', 'Upgrade from version 3.1 to 3.1.6', '2006-08-22 10:13:57', 1, 'upgrade*3.1.6*99*upgrade3.1.6');
888 897  
889 898 --
890 899 -- Dumping data for table `user_history`
... ... @@ -1188,6 +1197,11 @@ INSERT INTO `zseq_help` VALUES (98);
1188 1197 INSERT INTO `zseq_help_replacement` VALUES (1);
1189 1198  
1190 1199 --
  1200 +-- Dumping data for table `zseq_interceptor_instances`
  1201 +--
  1202 +
  1203 +
  1204 +--
1191 1205 -- Dumping data for table `zseq_links`
1192 1206 --
1193 1207  
... ... @@ -1335,7 +1349,7 @@ INSERT INTO `zseq_units_organisations_link` VALUES (1);
1335 1349 -- Dumping data for table `zseq_upgrades`
1336 1350 --
1337 1351  
1338   -INSERT INTO `zseq_upgrades` VALUES (113);
  1352 +INSERT INTO `zseq_upgrades` VALUES (117);
1339 1353  
1340 1354 --
1341 1355 -- Dumping data for table `zseq_user_history`
... ...
sql/mysql/install/structure.sql
... ... @@ -3,7 +3,7 @@
3 3 -- http://www.phpmyadmin.net
4 4 --
5 5 -- Host: localhost
6   --- Generation Time: Jul 31, 2006 at 10:42 AM
  6 +-- Generation Time: Aug 22, 2006 at 10:18 AM
7 7 -- Server version: 5.0.22
8 8 -- PHP Version: 4.4.2-1build1
9 9  
... ... @@ -483,7 +483,7 @@ CREATE TABLE `documents` (
483 483 `id` int(11) NOT NULL default '0',
484 484 `creator_id` int(11) NOT NULL default '0',
485 485 `modified` datetime NOT NULL default '0000-00-00 00:00:00',
486   - `folder_id` int(11) default '0',
  486 + `folder_id` int(11) default NULL,
487 487 `is_checked_out` tinyint(1) NOT NULL default '0',
488 488 `parent_folder_ids` mediumtext,
489 489 `full_path` mediumtext,
... ... @@ -785,6 +785,21 @@ CREATE TABLE `help_replacement` (
785 785 -- --------------------------------------------------------
786 786  
787 787 --
  788 +-- Table structure for table `interceptor_instances`
  789 +--
  790 +
  791 +CREATE TABLE `interceptor_instances` (
  792 + `id` int(11) NOT NULL,
  793 + `name` varchar(255) NOT NULL,
  794 + `interceptor_namespace` varchar(255) NOT NULL,
  795 + `config` text,
  796 + PRIMARY KEY (`id`),
  797 + KEY `interceptor_namespace` (`interceptor_namespace`)
  798 +) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  799 +
  800 +-- --------------------------------------------------------
  801 +
  802 +--
788 803 -- Table structure for table `links`
789 804 --
790 805  
... ... @@ -1924,6 +1939,17 @@ CREATE TABLE `zseq_help_replacement` (
1924 1939 -- --------------------------------------------------------
1925 1940  
1926 1941 --
  1942 +-- Table structure for table `zseq_interceptor_instances`
  1943 +--
  1944 +
  1945 +CREATE TABLE `zseq_interceptor_instances` (
  1946 + `id` int(10) unsigned NOT NULL auto_increment,
  1947 + PRIMARY KEY (`id`)
  1948 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  1949 +
  1950 +-- --------------------------------------------------------
  1951 +
  1952 +--
1927 1953 -- Table structure for table `zseq_links`
1928 1954 --
1929 1955  
... ... @@ -2194,7 +2220,7 @@ CREATE TABLE `zseq_units_organisations_link` (
2194 2220 CREATE TABLE `zseq_upgrades` (
2195 2221 `id` int(10) unsigned NOT NULL auto_increment,
2196 2222 PRIMARY KEY (`id`)
2197   -) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=114 ;
  2223 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=118 ;
2198 2224  
2199 2225 -- --------------------------------------------------------
2200 2226  
... ...