List Info

Thread: DefaultAccountManager.php




DefaultAccountManager.php
user name
2006-05-21 21:01:50
Update of /var/cvs/Geeklog-2.x/Geeklog-2.x/system
In directory iowaoutdoors:/tmp/cvs-serv29475/system

Modified Files:
	DefaultAccountManager.php AccountManagerInterface.php 
	AccountManagerSoap.php PluginSoapServiceBase.php 
	ListItemSoap.php 
Added Files:
	Gl2Soap.php 
Log Message:
Changed SOAP index page to use Sinorca layout and
centralized CSS file.
NOTE: This page will not observe themes but is visually
consistent with the current default theme.
Added some links to the nav header in header THTML file
Moved Gl2Soap class to system with other SOAP facades.
Moved and renamed authenticate method from
AccountManagerSoap class to AuthenticateUser method in
Gl2Soap class to create a more rational gateway for SOAP
callers. Now they don't have to "know" about
the AccountManagerSoap object to get authenticated, they do
it from the central Gl2Soap class, then send their auth data
(session ID, etc.) to subsequent method calls.
Renamed AuthData to Geeklog_AuthData for consistency.
Updated existing code in PluginSoapServiceBase and child
classes to work with the changes noted above.
Re-ran all unit tests, OK.

Index: AccountManagerInterface.php
============================================================
=======
RCS file:
/var/cvs/Geeklog-2.x/Geeklog-2.x/system/AccountManagerInterf
ace.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** AccountManagerInterface.php	1 May 2006 04:40:33
-0000	1.5
--- AccountManagerInterface.php	21 May 2006 21:01:48
-0000	1.6
***************
*** 28,34 ****
  	public function authenticate($username, $password);
  	public function changePassword($principal, $newpass);
  }
  
! require_once 'AccountManagerExceptions.php'
  
  ?>
\ No newline at end of file
--- 28,38 ----
  	public function authenticate($username, $password);
  	public function changePassword($principal, $newpass);
+     public function listUsers();
  }
  
! require_once 'AccountManagerExceptions.php';
! 
! require_once 'models/Gl2User.php';
! require_once 'models/Gl2Group.php';
  
  ?>
\ No newline at end of file

Index: AccountManagerSoap.php
============================================================
=======
RCS file:
/var/cvs/Geeklog-2.x/Geeklog-2.x/system/AccountManagerSoap.p
hp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** AccountManagerSoap.php	8 May 2006 06:15:50 -0000	1.3
--- AccountManagerSoap.php	21 May 2006 21:01:48 -0000	1.4
***************
*** 43,108 ****
  class Geeklog_AccountManagerSoap extends
Geeklog_PluginSoapServiceBase {
  
-     private static function __getManager(){
-         $acctMgr = &Geeklog_AccountManager::singleton(
-             Geeklog_Config::getValue('account_manager'),
-            
Geeklog_Config::getValue('account_manager_options'));
-         return $acctMgr;
-     }
-     
-     /**
-      * Generates a reasonably random character identifier
for use as a session serial number.
-      * This value should be used to identify an
authenticated caller for each SOAP call that is received.
-      * 
-      * return string The MD5 hash of a unique identifier
generated by the system.
-      * todo Move this method to the Gl2SoapSessionPeer when
it's available
-      */
-     private static function getSessionSerial() {
-         return md5(uniqid(rand(), true));
-     }
- 
-     /**
-      * Creates an entry in gl2_soap_session for the
specified user and remote IP address.
-      * Any existing record for the same user_id is
deleted.
-      * access private
-      * param int $user_id The database-specific identifier
for the logged-in user.
-      * param string $remote_ip The remote address from which
the caller made the request. This value is provided by the
calling script and is not determined here.
-      * return string The new session serial created for this
user.
-      */
-     private static function &startSession($user_id,
$remote_ip) {
-         $dao = &Geeklog_DAO::singleton();
-         
-         $session_ser    = self::getSessionSerial();
-         $last_called    = date('YmdHis');
- 
-         $dao->beginTransaction();
-         $dao->exec('deleteSoapSessionByUser',
array($user_id));
-         $dao->exec('startSoapSession',
array($session_ser, $remote_ip, $user_id, $last_called));
-         $dao->commit();
-         
-         return $session_ser;              
-     }
- 
-     /**
-      * Checks the credentials provided to see if they are
valid. If the function fails for any reason, an
AccountManagerException will be thrown with an explanation.
-      * param string $username The system-specific user
identifier, usually a shortname (mtutty) or e-mail address
(mtuttydomain.abc)
-      * param string $password The user's password, in the
format it should be compared to the underlying repository's
value.
-      * return Gl2UserSoap A user object as retrieved from
the database.
-      **/
-     public static function &authenticate($username,
$password){
-        
self::getLogger()->Log("AccountManagerSoap::authent
icate enter for user $username", PEAR_LOG_DEBUG);
-         $usr =
&self::__getManager()->authenticate($username,
$password);
-        
self::getLogger()->Log("AccountManagerSoap::authent
icate after AM::auth for user $username",
PEAR_LOG_DEBUG);
-         if ($usr) {
-             $soapUser =
Gl2UserSoap::fromPropelClass($usr);
-             $soapUser->password =
self::startSession($usr->getUserId(), '127.0.0.1'); 
-            
self::getLogger()->Log("AccountManagerSoap::authent
icate set soapUser password to session serial:
".$soapUser->password, PEAR_LOG_DEBUG);
-             return $soapUser;
-         } else {
-             $msg = 'The authenticate method did not
return a valid User object. No error was found.';
-             self::getLogger()->Log($msg,
PEAR_LOG_WARNING);
-             throw new Exception($msg);
-         }
-     }
- 
      /**
       * Create a new user account using the specified
information. The user_id field of the user object is
ignored. 
--- 43,46 ----
***************
*** 171,174 ****
--- 109,134 ----
          }
      }
+     
+     /**
+      * List all users in the GL2 database.
+      * Requires the caller to have the ACCT_LIST
privilege.
+      * 
+      * return Gl2UserSoap[] An array of users from the
database. 
+      */
+     public static function listUsers($auth) {
+         // TODO Come back and implement ACL checking
+         self::requireAuthentication($auth);
+         try {
+             $sourceData =
self::__getManager()->listUsers();
+             
+             foreach ($sourceData as $row) {
+                 $row['password'] = '';
+             }
+ 
+             return $sourceData;
+         } catch (AccountManagerException $amx) {
+             throw new Exception('Account Manager
Exception: ' . $amx->getMessage());
+         }
+     }
  }
  ?>
\ No newline at end of file

Index: PluginSoapServiceBase.php
============================================================
=======
RCS file:
/var/cvs/Geeklog-2.x/Geeklog-2.x/system/PluginSoapServiceBas
e.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** PluginSoapServiceBase.php	8 May 2006 06:15:50 -0000	1.3
--- PluginSoapServiceBase.php	21 May 2006 21:01:48 -0000	1.4
***************
*** 7,10 ****
--- 7,15 ----
   */
  
+ require_once 'system/Config.php';
+ 
+ require_once 'Log.php';
+  
+ 
  /**
   * Account Manager stuff is required for session_ser
checking
***************
*** 12,17 ****
  require_once 'system/AccountManager.php';
  require_once 'system/AccountManagerInterface.php';
- require_once 'system/AccountManagerSoap.php';
  require_once 'models/Gl2User.php';
  
  /**
--- 17,22 ----
  require_once 'system/AccountManager.php';
  require_once 'system/AccountManagerInterface.php';
  require_once 'models/Gl2User.php';
+ require_once 'models/soap/Gl2UserSoap.php';
  
  /**
***************
*** 67,72 ****
--- 72,143 ----
   **/
  abstract class Geeklog_PluginSoapServiceBase {
+ 
+     /**
+      * Convenience function for accessing the configured
Account Manager class.
+      */
+     public static function __getManager(){
+         $acctMgr = &Geeklog_AccountManager::singleton(
+             Geeklog_Config::getValue('account_manager'),
+            
Geeklog_Config::getValue('account_manager_options'));
+         return $acctMgr;
+     }
+     
+     /**
+      * Convenience function for child class logging.
+      * 
+      * return PEAR::Log The logging instance configured and
ready for use.
+      */    
+     public static function &getLogger() {
+         static $_log   = null;
+         if ($_log == null) {
+             $logConf = Geeklog_Config::getValue('log');
+             $_log =
&Log::singleton($logConf['handler'],
+                        
Geeklog_Config::getValue('path_logs') .'access.log',
$logConf['ident'],
+                         $logConf['conf']);
+         }
+         
+         return $_log;
+     }
+ 
   
      /**
+      * Checks the credentials provided to see if they are
valid. If the function fails for any reason, an
AccountManagerException will be thrown with an explanation.
+      * When called using SOAP, the password field will
contain the Session ID that can be used in future SOAP calls
instead of the username and password.
+      * param string $username The system-specific user
identifier, usually a shortname (mtutty) or e-mail address
(mtuttydomain.abc)
+      * param string $password The user's password, in the
format it should be compared to the underlying repository's
value.
+      * return Gl2UserSoap A user object as retrieved from
the database.
+      **/
+     public static function &authenticate($username,
$password){
+        
self::getLogger()->Log("PluginSoapServiceBase::auth
enticate enter for user $username", PEAR_LOG_DEBUG);
+         $usr =
&self::__getManager()->authenticate($username,
$password);
+        
self::getLogger()->Log("PluginSoapServiceBase::auth
enticate after AM::auth for user $username",
PEAR_LOG_DEBUG);
+         if ($usr) {
+             $soapUser =
Gl2UserSoap::fromPropelClass($usr);
+             
+             // TODO Come back and add the user's actual
IP address??
+             $soapUser->password =
self::startSession($usr->getUserId(), '127.0.0.1'); 
+            
self::getLogger()->Log("PluginSoapServiceBase::auth
enticate set soapUser password to session serial:
".$soapUser->password, PEAR_LOG_DEBUG);
+             return $soapUser;
+         } else {
+             $msg = 'The authenticate method did not
return a valid User object. No error was found.';
+             self::getLogger()->Log($msg,
PEAR_LOG_WARNING);
+             throw new Exception($msg);
+         }
+     }
+ 
+     
+     /**
+      * Generates a reasonably random character identifier
for use as a session serial number.
+      * This value should be used to identify an
authenticated caller for each SOAP call that is received.
+      * 
+      * return string The MD5 hash of a unique identifier
generated by the system.
+      * todo Move this method to the Gl2SoapSessionPeer when
it's available
+      */
+     private static function getSessionSerial() {
+         return md5(uniqid(rand(), true));
+     }
+ 
+ 
+     /**
       * Removes any soap session records that have expired.
       * This function relies on the config value
soap_session_mins, 
***************
*** 92,109 ****
  
      /**
!      * Convenience function for child class logging.
!      * 
!      * return PEAR::Log The logging instance configured and
ready for use.
!      */    
!     public static function &getLogger() {
!         static $_log   = null;
!         if ($_log == null) {
!             $logConf = Geeklog_Config::getValue('log');
!             $_log =
&Log::singleton($logConf['handler'],
!                        
Geeklog_Config::getValue('path_logs') .'access.log',
$logConf['ident'],
!                         $logConf['conf']);
!         }
          
!         return $_log;
      }
  
--- 163,185 ----
  
      /**
!      * Creates an entry in gl2_soap_session for the
specified user and remote IP address.
!      * Any existing record for the same user_id is
deleted.
!      * access private
!      * param int $user_id The database-specific identifier
for the logged-in user.
!      * param string $remote_ip The remote address from which
the caller made the request. This value is provided by the
calling script and is not determined here.
!      * return string The new session serial created for this
user.
!      */
!     private static function &startSession($user_id,
$remote_ip) {
!         $dao = &Geeklog_DAO::singleton();
          
!         $session_ser    = self::getSessionSerial();
!         $last_called    = date('YmdHis');
! 
!         $dao->beginTransaction();
!         $dao->exec('deleteSoapSessionByUser',
array($user_id));
!         $dao->exec('startSoapSession',
array($session_ser, $remote_ip, $user_id, $last_called));
!         $dao->commit();
!         
!         return $session_ser;              
      }
  
***************
*** 192,196 ****
          if (!isset($auth->session_ser) ||
strlen($auth->session_ser) == 0) {
             
self::getLogger()->log('PluginSoapServiceBase::validateA
uthData validating credential set for ' .
$auth->user_name, PEAR_LOG_DEBUG);
!             $user =
Geeklog_AccountManagerSoap::authenticate($auth->user_name
, $auth->password);
              if ($user == null) {
                  $msg = "User name
$auth->user_name could not be validated for a SOAP
transaction. No error was returned.";
--- 268,272 ----
          if (!isset($auth->session_ser) ||
strlen($auth->session_ser) == 0) {
             
self::getLogger()->log('PluginSoapServiceBase::validateA
uthData validating credential set for ' .
$auth->user_name, PEAR_LOG_DEBUG);
!             $user =
self::authenticate($auth->user_name, $auth->password);
              if ($user == null) {
                  $msg = "User name
$auth->user_name could not be validated for a SOAP
transaction. No error was returned.";

Index: DefaultAccountManager.php
============================================================
=======
RCS file:
/var/cvs/Geeklog-2.x/Geeklog-2.x/system/DefaultAccountManage
r.php,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** DefaultAccountManager.php	9 May 2006 19:10:00 -0000	1.9
--- DefaultAccountManager.php	21 May 2006 21:01:48
-0000	1.10
***************
*** 166,169 ****
--- 166,182 ----
      
      /**
+      * Lists the users in the GL2 database.
+      */
+     public function listUsers() {
+        
self::getLogger()->Log("DefaultAccountManager::list
Users enter", PEAR_LOG_DEBUG);
+         // TODO Come back and add ACL checking
+         //self::requirePrivilege($auth,
'LIST_ITEM_VIEW');
+         
+         $dao = &Geeklog_DAO::singleton();
+         $sourceArray = $dao->find('getUsers');
+         return $sourceArray;
+     }
+     
+     /**
       * Utility (assertion) method for validating user
privileges. If this method does not throw, 
       * then the provided user object points to a valid and
enabled user, and one of the 
***************
*** 201,204 ****
      }  
  }
- 
  ?>
\ No newline at end of file
--- 214,216 ----

Index: ListItemSoap.php
============================================================
=======
RCS file:
/var/cvs/Geeklog-2.x/Geeklog-2.x/system/ListItemSoap.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ListItemSoap.php	8 May 2006 06:15:50 -0000	1.1
--- ListItemSoap.php	21 May 2006 21:01:48 -0000	1.2
***************
*** 16,23 ****
   **/
  
- /**
-  * TODO Pull in list management ORM objects
-  */
- 
  require_once 'PluginSoapServiceBase.php';
  require_once 'models/Gl2ListItem.php';
--- 16,19 ----
***************
*** 42,46 ****
  
      /**
!      * Returns the current list of list item types. This
method requires the 
       * param Geeklog_AuthData $auth The authentication data
to be checked.
       * return string[] An array of list group names.
--- 38,42 ----
  
      /**
!      * Returns the current list of list item types. This
method requires the LIST_ITEM_VIEW privilege.
       * param Geeklog_AuthData $auth The authentication data
to be checked.
       * return string[] An array of list group names.
***************
*** 52,61 ****
          $dao = &Geeklog_DAO::singleton();
          $sourceArray =
$dao->find('getAllListItemGroups');
- //        $retArray = array();
- //        if (is_array($sourceArray)) {
- //            foreach ($sourceArray as $sourceItem) {
- //                $retArray[] = $sourceItem;
- //            }            
- //        }
          return $sourceArray;
      } 
--- 48,51 ----
***************
*** 111,115 ****
  
          // Not using requirePrivilege() method here,
because we
!         // need to require once privilege and check for
another.
          $session_ser = &self::validateAuthData($auth);
          $user =
&self::getUserFromSessionSerial($session_ser);
--- 101,107 ----
  
          // Not using requirePrivilege() method here,
because we
!         // need to require one privilege and check for
another.
!         // Stock requirePrivilege method does too much
automatically, so 
!         // we'd have to turn around and make some
redundant calls.
          $session_ser = &self::validateAuthData($auth);
          $user =
&self::getUserFromSessionSerial($session_ser);

--- NEW FILE: Gl2Soap.php ---
<?php
/**
 * Geeklog 2
 *
 * License details are yet to be determined.
 *
 */
 
require_once 'PluginSoapServiceBase.php';

/**
 * Information about a SOAP service that is available
through the GL SOAP interface.
 * 
 * package net.geeklog.soap
 * author RMT <michael.tuttygmail.com>
 * copyright Geeklog 2 Development Team 2005
 * version $Id: Gl2Soap.php,v 1.1 2006/05/21 21:01:48
mtutty Exp $
 * access public
 */
 class Geeklog_SoapInfo {
    
    /**
     * The plugin-defined name of the interface.
     * 
     * var string
     */
    public $name = '';

    /**
     * The user-friendly description of the interface.
     * 
     * var string
     */
    public $description = '(none)';

    /**
     * The namespace to be specified when calling this
interface.
     * 
     * Using different namespaces allows the SOAP engine to
identify which implementation class contains the called
function.
     * 
     * var string
     */
    public $namespace = '';

    /**
     * The URL to access the wsdl. 
     * 
     * This is generated based on the system's base url,
the location of the soap folder and the namespace of the
interface. 
     * 
     * var string
     */
    public $wsdl_url = '';

    /**
     * Convenience constructor for setting initial values. 
     */    
    public function __construct($new_name, $new_description,
$new_namespace, $new_wsdl_url) {
        $this->name             = $new_name;
        $this->description      = $new_description;
        $this->namespace        = $new_namespace;
        $this->wsdl_url         = $new_wsdl_url;
    }
 }

/**
 * Provides the central SOAP interface for configuring and
discovering the API at runtime.
 * 
 * package net.geeklog.soap
 * author RMT <michael.tuttygmail.com>
 * copyright Geeklog 2 Development Team 2005
 * version $Id: Gl2Soap.php,v 1.1 2006/05/21 21:01:48
mtutty Exp $
 * access public
 */
class Gl2Soap extends Geeklog_PluginSoapServiceBase {
    
    /* var array */
    private $classMap       = array();

    /**
     * Constructor for the Soap class.
     * 
     * This class requires a class map in the format
namespace => classname. This list must include all
classes that should be offered as Soap service providers.
     */
    public function __construct() {
        global $WSClasses;
        self::getLogger()->log('Gl2Soap::__construct
enter, WSClasses length is '.count($WSClasses),
PEAR_LOG_DEBUG);
        $this->classMap = $WSClasses;
    }   


    /**
     * Checks the credentials provided to see if they are
valid. If the function fails for any reason, an
AccountManagerException will be thrown with an explanation.
     * When called using SOAP, the password field will
contain the Session ID that can be used in future SOAP calls
instead of the username and password.
     * param string $username The system-specific user
identifier, usually a shortname (mtutty) or e-mail address
(mtuttydomain.abc)
     * param string $password The user's password, in the
format it should be compared to the underlying repository's
value.
     * return Gl2UserSoap A user object as retrieved from
the database.
     **/
    public function &AuthenticateUser($username,
$password){
        return self::authenticate($username, $password);
    }


    /**
     * Lists the available (enabled) SOAP interfaces that
the system will respond to.
     * 
     * return Geeklog_SoapInfo[] The list of available
interface namespaces. 
     */
     public function ListInterfaces() {
        
        self::getLogger()->log('Gl2Soap::ListInterfaces
enter, classMap length is '.count($classMap),
PEAR_LOG_DEBUG);
        
        $ret = array();

        // TODO Need to improve the metadata storage beyond
ns => class to support the data advertised by this
function.
        // I think that the plugins/Soap classes themselves
should provide the "friendly name" and
description fields.
        // Unfortunately, this means creating them all in
this loop? 
        foreach($this->classMap as $class) {
           
self::getLogger()->log("Gl2Soap::ListInterfaces
adding return element for $class",  PEAR_LOG_DEBUG);
            $info = new Geeklog_SoapInfo($class, '(no
description)', $class, $this->CreateWSDLURL($class));
            $ret[] = $info;          
        }
        
        return $ret;        
     }
     
     private function CreateWSDLURL($namespace) {
        return
$_SERVER['SCRIPT_NAME']."?class=$namespace&wsdl
";
     }
 }
?>

_______________________________________________
geeklog2-cvs mailing list
geeklog2-cvslists.geeklog.net
http://lists.geeklog.net/mailman/listinfo/geeklog2-cvs

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )