wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.AuthUserXML.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.AuthUserXML.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/security/class.AuthUser.php");
20 require_once(BASE."wcmf/lib/security/class.UserManager.php");
21 require_once(BASE."wcmf/lib/util/class.XMLUtil.php");
22 
23 /**
24  * @class AuthUserXML
25  * @ingroup Security
26  * @brief AuthUser that gets configuration from an XML file
27  * @deprecated Use AuthUser and UserXML instead
28  *
29  * @author ingo herwig <ingo@wemove.com>
30  */
31 class AuthUserXML extends AuthUser
32 {
33  /**
34  * @see AuthUser::getUserData()
35  *
36  * @note This class relies on the following dtd
37  * @verbatim
38  <!ELEMENT XmlDatabase (#PCDATA | nextID | users | roles)*>
39 
40  <!ELEMENT nextID (#PCDATA)>
41 
42  <!ELEMENT users (#PCDATA | user)*>
43  <!ELEMENT user (#PCDATA | name | firstname | login | password | config | userroles)*>
44  <!ATTLIST user id CDATA #IMPLIED>
45  <!ELEMENT firstname (#PCDATA)>
46  <!ELEMENT login (#PCDATA)>
47  <!ELEMENT password (#PCDATA)>
48  <!ELEMENT config (#PCDATA)>
49  <!ELEMENT userroles (#PCDATA | roleid)*>
50  <!ELEMENT roleid (#PCDATA)>
51 
52  <!ELEMENT roles (#PCDATA | role)*>
53  <!ELEMENT role (#PCDATA | name)*>
54  <!ATTLIST role id CDATA #IMPLIED>
55 
56  <!ELEMENT name (#PCDATA)>
57  @endverbatim
58  *
59  * @note Initialization data given in the constructor require the following keys:
60  * filename
61  */
62  function getUserData($login, $password)
63  {
64  $old_error_handler = set_error_handler("XMLUtilErrorHandler");
65  $userData = array();
66 
67  // setup xml database
68  $xml = new XMLUtil();
69 
70  // Security settings
71  $aDbPermissions = array(
72  'GetNodeData' => XMLDB_PERMISSION_ENABLE,
73  'GetChildData' => XMLDB_PERMISSION_ENABLE
74  );
75  // Pass down the security mode settings.
76  $xml->bSecureMode = TRUE;
77  foreach ($aDbPermissions as $MethodName => $Permission)
78  $xml->aPermissions[$MethodName] = $Permission;
79 
80  // query database
81  if (!$xml->Open($this->_initParams['filename'], FALSE, FALSE))
82  WCMFException::throwEx("Could not open XML input: ".$this->_initParams['filename'], __FILE__, __LINE__);
83 
84  // get user node path
85  $userQuery = "*/users/user[child::login[.='".$login."']][child::password[.='".$password."']]";
86  $userPathArray = $xml->XmlDb->evaluate($userQuery);
87  $userPath = $userPathArray[0];
88 
89  if ($userPath != '')
90  {
91  // get user values
92  $userData['id'] = $xml->XmlDb->getAttributes($userPath, 'id');
93  $userData['name'] = $xml->XmlDb->getData($userPath."/name");
94  $userData['firstname'] = $xml->XmlDb->getData($userPath."/firstname");
95  $userData['config'] = $xml->XmlDb->getData($userPath."/config");
96 
97  // get roles
98  $userData['roles'] = array();
99  $userRolesPathArray = $xml->XmlDb->evaluate($userPath.'/userroles/roleid');
100  foreach ($userRolesPathArray as $userRolePath)
101  {
102  $roleId = $xml->XmlDb->getData($userRolePath);
103  $rolePathArray = $xml->XmlDb->evaluate('*/roles/role[@id="'.$roleId.'"]/name');
104  array_push($userData['roles'], $xml->XmlDb->getData($rolePathArray[0]));
105  }
106  }
107  $xml->Close();
108  set_error_handler($old_error_handler);
109  return $userData;
110  }
111 }
112 ?>
AuthUser provides a storage and methods for user data used for authentication/authorization purposes...
throwEx($message, $file='', $line='')
XMLUtil helps in using XML files as storage. XMLUtil is a subclass of CXmlDb that is customized for u...
getUserData($login, $password)
AuthUser that gets configuration from an XML file.