summaryrefslogtreecommitdiff
path: root/framework/Security
diff options
context:
space:
mode:
authorxue <>2005-12-15 21:31:12 +0000
committerxue <>2005-12-15 21:31:12 +0000
commitfb495d3041cacb8c305ebecaa60c1bb7afa4dddf (patch)
tree799a6d88e2c319f7950aaeb32c5f93d02d596e8c /framework/Security
parentb5f055212d394b1e4b7022ce21b386d2e5103f43 (diff)
Added support to read user/role information from an external file.
Diffstat (limited to 'framework/Security')
-rw-r--r--framework/Security/TUserManager.php55
1 files changed, 53 insertions, 2 deletions
diff --git a/framework/Security/TUserManager.php b/framework/Security/TUserManager.php
index d9210661..3c30dc19 100644
--- a/framework/Security/TUserManager.php
+++ b/framework/Security/TUserManager.php
@@ -207,6 +207,14 @@ class TUserManager extends TModule
* @var string password mode, Clear|MD5|SH1
*/
private $_passwordMode='MD5';
+ /**
+ * @var boolean whether the module has been initialized
+ */
+ private $_initialized=false;
+ /**
+ * @var string user/role information file
+ */
+ private $_userFile=null;
/**
* Initializes the module.
@@ -219,9 +227,30 @@ class TUserManager extends TModule
{
parent::init($application,$config);
- foreach($config->getElementsByTagName('user') as $node)
+ if($this->_userFile!==null)
+ {
+ if(is_file($this->_userFile))
+ {
+ $dom=new TXmlDocument;
+ $dom->loadFromFile($this->_userFile);
+ $this->loadUserData($dom);
+ }
+ else
+ throw new TInvalidConfigurationException('usermanager_userfile_invalid',$this->_userFile);
+ }
+ $this->loadUserData($config);
+ $this->_initialized=true;
+ }
+
+ /**
+ * Loads user/role information from an XML node.
+ * @param TXmlElement the XML node containing the user information
+ */
+ private function loadUserData($xmlNode)
+ {
+ foreach($xmlNode->getElementsByTagName('user') as $node)
$this->_users[strtolower($node->getAttribute('name'))]=$node->getAttribute('password');
- foreach($config->getElementsByTagName('role') as $node)
+ foreach($xmlNode->getElementsByTagName('role') as $node)
{
foreach(explode(',',$node->getAttribute('users')) as $user)
{
@@ -232,6 +261,28 @@ class TUserManager extends TModule
}
/**
+ * @return string the full path to the file storing user/role information
+ */
+ public function getUserFile()
+ {
+ return $this->_userFile;
+ }
+
+ /**
+ * @param string user/role data file path (in namespace form). The file format is XML
+ * whose content is similar to that user/role block in application configuration.
+ * @throws TInvalidOperationException if the module is already initialized
+ * @throws TConfigurationException if the file is not in proper namespace format
+ */
+ public function setUserFile($value)
+ {
+ if($this->_initialized)
+ throw new TInvalidOperationException('usermanager_userfile_unchangeable');
+ else if(($this->_userFile=Prado::getPathOfNamespace($value,self::DB_FILE_EXT))===null)
+ throw new TConfigurationException('usermanager_userfile_invalid',$value);
+ }
+
+ /**
* @return string guest name, defaults to 'Guest'
*/
public function getGuestName()