[geeklog-cvs] geeklog-2/public_html/server/A_and_A/commands AABaseCommand.class.php,NONE,1.1 authenticate.class.php,NONE,1.1 changepassword.class.php,NONE,1.1 changepasswordbyadmin.class.php,NONE,1.1 getusergroups.class.php,NONE,1.1 getuserprivileges.class.php,NONE,1.1 listappgroups.class.php,NONE,1.1 listappprivileges.class.php,NONE,1.1 resetpassword.class.php,NONE,1.1 setuserprivileges.class.php,NONE,1.1

tony at geeklog.net tony at geeklog.net
Sat Jan 11 01:01:28 EST 2003


Update of /usr/cvs/geeklog/geeklog-2/public_html/server/A_and_A/commands
In directory internal.geeklog.net:/tmp/cvs-serv32388

Added Files:
	AABaseCommand.class.php authenticate.class.php 
	changepassword.class.php changepasswordbyadmin.class.php 
	getusergroups.class.php getuserprivileges.class.php 
	listappgroups.class.php listappprivileges.class.php 
	resetpassword.class.php setuserprivileges.class.php 
Log Message:
Initial load into Geeklog


--- NEW FILE: AABaseCommand.class.php ---
<?php


/**
* PEAR XML Tree builder
*/
require_once('/usr/local/lib/php/XML/Tree.php');

/**
* A&A Constants
*/ 
//require_once(dirname(__FILE__) . '/../../common/AAConstants.php');
require_once('/home/tony/geeklog2_main/lib/A_and_A/common/AAConstants.php');

/**
* This is the base command object.  All other command will inherit from
* this class
*
* @access public
* @author Tony Bibbs <tony at tonybibbs.com>
* @package net.geeklog.enterprise.aa.server.command
*
*/
class AABaseCommand {
    /**
    * @access private
    */
    var $_paramIndex = array();

    /**
    * @access private
    */
    var $_paramVals = array();

    /**
    * Constructor.
    *
    * @access public
    * @param string $cmndName Name of this command (pass from command factory)
    *
    */
    function AABaseCommand($cmdName)
    {
        if (!empty($cmdName)) {
            $this->_cmdName = $cmdName;
        }
    }

    /**
    * Builds XML response when an error has occured executing the command
    * for the given application
    *
    * @access public
    * @param object $exception exception object 
    * @param string $appId Application ID
    * @param string $method Method that caused the error
    * @return string XML response
    *
    */
    function getExceptionResponse($exception,$appId,$method)
    {
        $tree = new XML_Tree;
        $root = &$tree->addRoot(AA_SERVICE_TAG);
        $tmpNode = &$root->addChild(RESULT_TAG, $exception->message, array('value'=>$exception->exception,'method'=>"$method",'AppId'=>"$appId"));         

        return $tree->get();
    }

    /**
    * Returns XML response for given application ID.  This is used in a non-exception
    * state.
    *
    * @access public
    * @param string $appId Application ID
    * @return string XML response
    *
    */
    function getXML($appId)
    {
        $tree = new XML_Tree;
        $root = &$tree->addRoot(AA_SERVICE_TAG);
        $tmpNode = &$root->addChild(RESULT_TAG, '', array('value'=>'0','method'=>$this->getMethod(),'AppId'=>$appId));
    
        return $tree->get();
    }

    /**
    * Returns the method this command handles.  This can be done here
    * in the base command because the command factory will know what 
    * command is being called
    *
    * @return   string  Command name
    *
    */
    function getMethod()
    {
        return $this->_cmdName;
    }

    function getParam($paramName)
    {
        $XMLKeys = array_keys($this->_paramIndex);
        if ($paramName == PRIVILEGE_LIST_TAG) {
            if (in_array(strtoupper(PRIVILEGE_TAG), array_keys($this->_paramIndex))) {
                $privIndexes = $this->_paramIndex[strtoupper(PRIVILEGE_TAG)];
                require_once(dirname(__FILE__) . '/../../common/AAPrivilege.class.php');
                $curPriv = new AAPrivilege();
                foreach ($privIndexes as $singleIndex) { 
                    $curPriv->setPrivilegeCode($this->_paramVals[$singleIndex]['attributes']['VALUE']);
                    $curPriv->setPrivilegeDesc($this->_paramVals[$singleIndex]['value']);
                    $privArray[] = $curPriv;
                }
                return $privArray;
            } else {
                trigger_error('no privileges found');
            }
        }
        return $this->_paramVals[$this->_paramIndex[strtoupper($paramName)][0]]['attributes']['VALUE'];
    }

    /**
    * Gets the parsed XML in the form of two arrays, one for indexes,
    * the other for values for those indexes
    *
    * @param    string[]    $index      Array of element names from XML and index into the
    *                                   values array
    * @param    string[]    $vals       Values of XML elements
    *
    */
    function setParameters($index, $vals)
    {
        $this->_paramIndex = $index;
        $this->_paramVals = $vals;
    }
}

?>

--- NEW FILE: authenticate.class.php ---
<?php

require_once(dirname(__FILE__) . '/../AAServiceUser.class.php');

/**
* @author Tony Bibbs <tony AT geeklog DOT net>
* @package net.geeklog.enterprise.aa.server.command
*
*/
class authenticate extends AABaseCommand {

    /**
    * Starts authenticate calling chain
    *
    * @return   string  XML response string
    *
    */
    function &processRequest()
    {
        $user = new AAServiceUser();
        $user = &$user->authenticate($this->getParam(APPLICATION_ID_TAG), $this->getParam(USER_NAME_TAG), $this->getParam(PASSWORD_TAG));
        if (get_class($user) == 'aaexception') {
            return $this->getExceptionResponse($user, $this->getParam(APPLICATION_ID_TAG), 'Authenticate');
        }
        $responseXML = $this->getXML($user);
        return $responseXML;
    }

    /**
    * Outputs the response XML
    *
    * @param    object      $user   AAServiceUser *or* AAException
    *
    */
    function getXML($user)
    {
        $tree = new XML_Tree;
        $root = &$tree->addRoot(AA_SERVICE_TAG);
        $message = '';

        $retval = 0;

        $tmpNode = &$root->addChild(RESULT_TAG, $message, array('method'=>'Authenticate','appId'=>$this->getParam('AppId'),'value'=>$retval));
        $tmpNode = &$root->addChild(EMPLOYEE_ID_TAG, $user->getEmpId());
        $tmpNode = &$root->addChild(GROUP_LIST_TAG, '', array('value'=>$this->getParam(APPLICATION_ID_TAG)));
        $groups = $user->getGroups();
        
        foreach($groups as $group) {
            $groupNode = &$tmpNode->addChild(GROUP_TAG,$group->getGroupDesc(),array('id'=>$group->getGroupId(),'logical'=>$group->getGroupLogicalName(),'display'=>htmlspecialchars($group->getGroupDisplayName())));
        }
        
        $tmpNode = &$root->addChild(PRIVILEGE_LIST_TAG, '', array('value'=>$this->getParam(APPLICATION_ID_TAG)));
        $privileges = $user->getPrivileges();
        
        // Check for errors
        if (get_class($privileges) == 'aaexception') {
            return $this->getExceptionResponse($privileges,$this->getParam('AppId'),'Authenticate');
        }
        
        // Build privilege list
        foreach($privileges as $priv) {
            $privNode = &$tmpNode->addChild(PRIVILEGE_TAG,$priv->getPrivilegeDesc(),array('code'=>$priv->getPrivilegeCode()));
        }

        return $tree->get();
    }
}

?>

--- NEW FILE: changepassword.class.php ---
<?php

require_once(dirname(__FILE__) . '/../AAServiceUser.class.php');

/**
* Change Password Command
*
* This object changes a user's password
*
* @access public
* @author Tony Bibbs <tony at tonybibbs.com>
* @package net.geeklog.enterprise.aa.server.command
*
*/
class changepassword extends AABaseCommand {

    /**
    * Changes the users's password
    *
    * This will attempt to change the users password and
    * will send an XML response back indicated success or
    * failure.
    *
    * @access public
    * @return string XML response
    *
    */
    function &processRequest()
    {
        $user = new AAServiceUser();
        $user->setAppId($this->getParam(APPLICATION_ID_TAG));
        $user->setUserName($this->getParam(USER_NAME_TAG));
        $user->setPassword($this->getParam(OLD_PASSWORD_TAG));
        $newPassword = $this->getParam(NEW_PASSWORD_TAG);

        $retval = $user->changePassword($newPassword);
        if ($retval) {
            // Some sort of error occurred
            $responseXML =  $this->getExceptionResponse($retval, $user->getAppId(), 'ChangePassword');
            trigger_error($responseXML);
        } else {
            $responseXML = $this->getXML($this->getParam(APPLICATION_ID_TAG));
        }
        return $responseXML; 
    }
}

?>

--- NEW FILE: changepasswordbyadmin.class.php ---
<?php

require_once(dirname(__FILE__) . '/../AAServiceUser.class.php');

/**
* Change Password Command
*
* This object changes a user's password
*
* @access public
* @author Tony Bibbs <tony at tonybibbs.com>
* @package net.geeklog.enterprise.aa.server.command
*
*/
class changepasswordbyadmin extends AABaseCommand {

    /**
    * Changes a users's password on behalf of an admin
    *
    * This will attempt to change the users password and
    * will send an XML response back indicated success or
    * failure.
    *
    * @access public
    * @return string XML response
    *
    */
    function &processRequest()
    {
        $user = new AAServiceUser();
        $user->setAppId($this->getParam(APPLICATION_ID_TAG));
        $user->setUserName($this->getParam(ADMIN_USER_NAME_TAG));
        $user->setPassword($this->getParam(ADMIN_PASSWORD_TAG));
        $userName = $this->getParam(USER_NAME_TAG);
        $newPassword = $this->getParam(NEW_PASSWORD_TAG);

        $retval = $user->changePasswordByAdmin($userName, $newPassword);
        if ($retval) {
            // Some sort of error occurred
            $responseXML =  $this->getExceptionResponse($retval, $user->getAppId(), 'ChangePasswordByAdmin');
        } else {
            $responseXML = $this->getXML($this->getParam(APPLICATION_ID_TAG));
        }
        return $responseXML; 
    }
}

?>

--- NEW FILE: getusergroups.class.php ---
<?php

require_once(dirname(__FILE__) . '/../AAServiceUser.class.php');

/**
* @author Tony Bibbs
* @package net.geeklog.enterprise.aa.server.command
*
*/
class getusergroups extends AABaseCommand {

    /**
    * Starts authenticate calling chain
    *
    * @return   string  XML response string
    *
    */
    function &processRequest()
    {
        $user = new AAServiceUser();
        $user->setAppId($this->getParam(APPLICATION_ID_TAG));
        $user->setUserName($this->getParam(ADMIN_USER_NAME_TAG));
        $user->setPassword($this->getParam(ADMIN_PASSWORD_TAG));
        $userName = $this->getParam(USER_NAME_TAG);
        $groupArray = $user->getUserGroups($userName);
        $responseXML = $this->getXML($groupArray, $user->getAppId());
        return $responseXML;
    }

    /**
    * Outputs the response XML
    *
    * @param    object      $user   AAServiceUser *or* AAException
    *
    */
    function getXML($groupArray, $appId)
    {
        $tree = new XML_Tree;
        $root = &$tree->addRoot(AA_SERVICE_TAG);
        $message = '';
        $retval = 0;
        $tmpNode = &$root->addChild(RESULT_TAG, $message, array('method'=>'GetUserGroups','appId'=>$appId,'value'=>$retval));
        $tmpNode = &$root->addChild(GROUP_LIST_TAG, '', array('appId'=>$this->getParam(APPLICATION_ID_TAG)));
        foreach($groupArray as $group) {
            $groupNode = &$tmpNode->addChild(GROUP_TAG,$priv->getGroupDesc(),array('id'=>$group->getGroupId(),'logical'=>$group->getGroupLogicalName(),'display'=>$group->getGroupDisplayName()));
        }

        return $tree->get();
    }
}

?>

--- NEW FILE: getuserprivileges.class.php ---
<?php

require_once(dirname(__FILE__) . '/../AAServiceUser.class.php');

/**
* @author Tony Bibbs
* @package net.geeklog.enterprise.aa.server.command
*
*/
class getuserprivileges extends AABaseCommand {

    /**
    * Starts authenticate calling chain
    *
    * @return   string  XML response string
    *
    */
    function &processRequest()
    {
        $user = new AAServiceUser();
        $user->setAppId($this->getParam(APPLICATION_ID_TAG));
        $user->setUserName($this->getParam(ADMIN_USER_NAME_TAG));
        $user->setPassword($this->getParam(ADMIN_PASSWORD_TAG));
        $userName = $this->getParam(USER_NAME_TAG);
        $privArray = $user->getUserPrivileges($userName);
        $responseXML = $this->getXML($privArray, $user->getAppId());
        return $responseXML;
    }

    /**
    * Outputs the response XML
    *
    * @param    object      $user   AAServiceUser *or* AAException
    *
    */
    function getXML($privArray, $appId)
    {
        $tree = new XML_Tree;
        $root = &$tree->addRoot(AA_SERVICE_TAG);
        $message = '';
        $retval = 0;
        $tmpNode = &$root->addChild(RESULT_TAG, $message, array('method'=>'GetUserPrivileges','appId'=>$appId,'value'=>$retval));
        $tmpNode = &$root->addChild(PRIVILEGE_LIST_TAG, '', array('appId'=>$this->getParam(APPLICATION_ID_TAG)));
        foreach($privArray as $priv) {
            $privNode = &$tmpNode->addChild(PRIVILEGE_TAG,$priv->getPrivilegeDesc(),array('code'=>$priv->getPrivilegeCode()));
        }

        return $tree->get();
    }
}

?>

--- NEW FILE: listappgroups.class.php ---
<?php

require_once(dirname(__FILE__) . '/../AAServiceUser.class.php');

/**
* @author Tony Bibbs
* @package net.geeklog.enterprise.aa.server.command
*
*/
class listappgroups extends AABaseCommand {

    /**
    * Starts listappgroups calling chain
    *
    * @return   string  XML response string
    *
    */
    function &processRequest()
    {
        $user = new AAServiceUser();
        $user->setAppId($this->getParam(APPLICATION_ID_TAG));
        $user->setUserName($this->getParam(ADMIN_USER_ID_TAG));
        $user->setPassword($this->getParam(ADMIN_PASSWORD_TAG));
        $groupArray = $user->listAppGroups();
        if (get_class($groupArray) == 'aaexception') {
            return $this->getExceptionResponse($groupArray, $this->getParam(APPLICATION_ID_TAG), 'ListAppPrivileges');
        }
        $responseXML = $this->getXML($groupArray, $user->getAppId());
        return $responseXML;
    }

    /**
    * Outputs the response XML
    *
    * @param    object      $user   AAServiceUser *or* AAException
    *
    */
    function getXML($groupArray, $appId)
    {
        $tree = new XML_Tree;
        $root = &$tree->addRoot(AA_SERVICE_TAG);
        $message = '';
        $retval = 0;
        $resultNode = &$root->addChild(RESULT_TAG, $message, array('method'=>'ListAppGroups','appId'=>$appId,'value'=>$retval));
        $groupListNode = &$root->addChild(GROUP_LIST_TAG, '', array('value'=>$this->getParam(APPLICATION_ID_TAG)));        
        foreach ($groupArray as $curGroup) {
            $groupNode = &$groupListNode->addChild(GROUP_TAG,$curGroup->getGroupDesc(),array('id'=>$curGroup->getGroupId(),'logical'=>$curGroup->getGroupLogicalName(),'display'=>htmlspecialchars($curGroup->getGroupDisplayName())));
            $groupPrivArray = $curGroup->getGroupPrivileges();
            $privListNode = &$groupNode->addChild(PRIVILEGE_LIST_TAG, '', array('value'=>$this->getParam(APPLICATION_ID_TAG)));
            foreach ($groupPrivArray as $curPriv) {
                $privNode = &$privListNode->addChild(PRIVILEGE_TAG,$curPriv->getPrivilegeDesc(),array('code'=>$curPriv->getPrivilegeCode()));
            }
        }

        return $tree->get();
    }
}

?>
--- NEW FILE: listappprivileges.class.php ---
<?php

require_once(dirname(__FILE__) . '/../AAServiceUser.class.php');

/**
* @author Tony Bibbs
* @package net.geeklog.enterprise.aa.server.command
*
*/
class listappprivileges extends AABaseCommand {

    /**
    * Starts authenticate calling chain
    *
    * @return   string  XML response string
    *
    */
    function &processRequest()
    {
        $user = new AAServiceUser();
        $user->setAppId($this->getParam(APPLICATION_ID_TAG));
        $user->setUserName($this->getParam(ADMIN_USER_NAME_TAG));
        $user->setPassword($this->getParam(ADMIN_PASSWORD_TAG));
        $privArray = $user->listAppPrivileges();
        if (get_class($privArray) == 'aaexception') {
            return $this->getExceptionResponse($privArray, $this->getParam(APPLICATION_ID_TAG), 'ListAppPrivileges');
        }
        $responseXML = $this->getXML($privArray, $user->getAppId());
        return $responseXML;
    }

    /**
    * Outputs the response XML
    *
    * @param    object      $user   AAServiceUser *or* AAException
    *
    */
    function getXML($privArray, $appId)
    {
        $tree = new XML_Tree;
        $root = &$tree->addRoot(AA_SERVICE_TAG);
        $message = '';
        $retval = 0;
        $tmpNode = &$root->addChild(RESULT_TAG, $message, array('method'=>'ListAppPrivileges','appId'=>$appId,'value'=>$retval));
        $tmpNode = &$root->addChild(PRIVILEGE_LIST_TAG, '', array('appId'=>$this->getParam(APPLICATION_ID_TAG)));
        foreach($privArray as $priv) {
            $privNode = &$tmpNode->addChild(PRIVILEGE_TAG,$priv->getPrivilegeDesc(),array('code'=>$priv->getPrivilegeCode()));
        }

        return $tree->get();
    }
}

?>

--- NEW FILE: resetpassword.class.php ---
<?php

require_once(dirname(__FILE__) . '/../AAServiceUser.class.php');

/**
* Reset Password Command
*
* This object initiates a password reset 
*
* @access public
* @author Tony Bibbs <tony at tonybibbs.com>
* @package net.geeklog.enterprise.aa.server.command
*
*/
class resetpassword extends AABaseCommand {

    /**
    * Changes the users's password
    *
    * This will attempt to change the users password and
    * will send an XML response back indicated success or
    * failure.
    *
    * @access public
    * @return string XML response
    *
    */
    function &processRequest()
    {
        $user = new AAServiceUser();
        $user->setUserName($this->getParam(ADMIN_USER_NAME_TAG));
        $user->setPassword($this->getParam(ADMIN_PASSWORD_TAG));
        $user->setAppId($this->getParam(APPLICATION_ID_TAG));
        $userName = $this->getParam(USER_NAME_TAG);

        $newPassword = $user->resetPassword($userName);
        if (get_class($newPassword) == 'aaexception') {
            // Some sort of error occurred
            $responseXML =  $this->getExceptionResponse($newPassword, $user->getAppId(), 'ResetPassword');
            trigger_error($responseXML);
        } else {
            $responseXML = $this->getXML($this->getParam(APPLICATION_ID_TAG), $newPassword);
        }
        return $responseXML; 
    }
    
    function getXML($appId, $newPassword)
    {
        $tree = new XML_Tree;
        $root = &$tree->addRoot(AA_SERVICE_TAG);
        $message = '';

        $retval = 0;

        $tmpNode = &$root->addChild(RESULT_TAG, $message, array('method'=>'ResetPassword','appId'=>$this->getParam('AppId'),'value'=>$retval));
        $tmpNode = &$root->addChild(NEW_PASSWORD_TAG, $newPassword, '');
        
        return $tree->get();
    }
}

?>

--- NEW FILE: setuserprivileges.class.php ---
<?php

require_once(dirname(__FILE__) . '/../AAServiceUser.class.php');

/**
* @author Tony Bibbs
* @package net.geeklog.enterprise.aa.server.command
*
*/
class setuserprivileges extends AABaseCommand {

    /**
    * Starts authenticate calling chain
    *
    * @return   string  XML response string
    *
    */
    function processRequest()
    {
        $user = new AAServiceUser();
        $user->setAppId($this->getParam(APPLICATION_ID_TAG));
        $user->setUserName($this->getParam(ADMIN_USER_NAME_TAG));
        $user->setPassword($this->getParam(ADMIN_PASSWORD_TAG));
        $userName = $this->getParam(USER_NAME_TAG);

        // Get all the privileges, from XML into array
        $privileges = $this->getParam(PRIVILEGE_LIST_TAG);

        $retval = $user->setUserPrivileges($userName, $privileges);

        if ($retval) {
            // error occurred
            $responseXML = $this->getExceptionResponse($retval, $user->getAppId(), $this->getMethod());
        } else {
            $responseXML = $this->getXML($appId);
        }

        return $responseXML;
    }
}

?>





More information about the geeklog-cvs mailing list