[geeklog-cvs] geeklog-2/lib/A_and_A/client AAServiceInterface.class.php,1.1,1.2
geeklog-cvs-admin at lists.geeklog.net
geeklog-cvs-admin at lists.geeklog.net
Fri May 16 17:44:25 EDT 2003
Update of /usr/cvs/geeklog/geeklog-2/lib/A_and_A/client
In directory internal.geeklog.net:/tmp/cvs-serv3538
Modified Files:
AAServiceInterface.class.php
Log Message:
Refactored this to use a stategy design pattern so we can better support alternative methods to raw XML for interacting with A&A server.
Index: AAServiceInterface.class.php
===================================================================
RCS file: /usr/cvs/geeklog/geeklog-2/lib/A_and_A/client/AAServiceInterface.class.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** AAServiceInterface.class.php 11 Jan 2003 06:07:58 -0000 1.1
--- AAServiceInterface.class.php 16 May 2003 21:44:23 -0000 1.2
***************
*** 13,42 ****
/**
- * PEAR's XML tree builder
- */
- require_once('XML/Tree.php');
-
- /**
* A&A User Class
*/
! require_once('AAUser.class.php');
/**
* Constants for the Enterprise A&A services and client
*/
! require_once(dirname(__FILE__) . '/../common/AAConstants.php');
/**
* Privilege class for the A&A Service
*/
! require_once(dirname(__FILE__) . '/../common/AAPrivilege.class.php');
/**
* Group class for the A&A Service
*/
! require_once(dirname(__FILE__) . '/../common/AAGroup.class.php');
! class AAServiceInterface {
// Public Methods
--- 13,74 ----
/**
* A&A User Class
*/
! require_once 'AAUser.class.php';
/**
* Constants for the Enterprise A&A services and client
*/
! require_once dirname(__FILE__) . '/../common/AAConstants.php';
/**
* Privilege class for the A&A Service
*/
! require_once dirname(__FILE__) . '/../common/AAPrivilege.class.php';
/**
* Group class for the A&A Service
*/
! require_once dirname(__FILE__) . '/../common/AAGroup.class.php';
! /**
! * Abstract invoker class
! */
! require_once dirname(__FILE__) . 'Invoker.class.php';
!
! define('INVOKE_LOCALHOST', 'LocalhostInvoker');
! define('INVOKE_XML', 'XMLInvoker');
! define('INVOKE_XMLRPC', 'RPCInvoker');
! define('INVOKE_SOAP', 'SoapInvoker');
+ class AAServiceInterface extends Invoker {
+ var $_invoker = null;
+
+ /**
+ * Constructor
+ *
+ * Implements a strategy pattern for interacting with the A&A server in
+ * one of three ways:
+ * 1) XML strings - This strategy uses raw XML via HTTP to call methods on
+ * A&A server
+ * 2) XMLRPC - This strategy uses PEAR's XMLRPC package to talk to A&A
+ * 3) SOAP - This strategy uses SOAP/WSDL to talk to A&A server.
+ *
+ * @author Tony Bibbs <tony at geeklog.net>
+ * @access public
+ * @param $invokeMethod string Constant representing class of strategy to use
+ * @param $aaServer string hostname of A&A server
+ * @param $aaPort integer port to use when connecting to A&A server
+ * @param $aaPath string Relative path to send A&A requests to
+ * @return object User object
+ *
+ */
+ function AAServiceInterface($invokeMethod = INVOKE_LOCALHOST, $aaServer = '', $aaPort = '', $aaPath = '')
+ {
+ require_once dirname(__FILE__) . $invokeMethod . '.class.php';
+
+ $this->_invoker = new $invokeMethod($aaServer, $aaPort, $aaPath);
+ }
+
// Public Methods
***************
*** 44,81 ****
* Authenticates a user to an application
*
! * This moethod authenticates the userId and password for the specified
! * application. It returns an AAUser object which holds authorization
! * privieges for that user and any exeptions that may have occured
! * during authentication
*
* @author Tony Bibbs <tony AT geeklog DOT net>
- * @param string $aaServer A&A Server to connect to
* @param string $appId Application to authenticate to
* @param string $userId User to authenticate
* @param string $password Password to authenticate with
! * @param integer $aaPort Port on A&A server to connect ot
! * @return AAUser Object containinga list of authorization levels
*
*/
! function &authenticate($aaServer, $aaPath, $appId, $userName, $password, $aaPort=80)
{
! // Build and send XML request
! $requestXML = AAServiceInterface::_buildAuthenticateRequest($appId, $userName, $password);
! $responseXML = AAServiceInterface::_request($aaServer,'POST',$aaPath,$requestXML,$aaPort);
! $user = &AAServiceInterface::_handleAuthenticateResponse($responseXML, $aaServer, $aaPort);
!
! if (get_class($user) == 'aaexception') {
! // Doing this just to make it obvious that we got an exception, not a valid user object
! $exception = &$user;
!
! // Need to log this problem at some point, until then just return false
! return false;
! }
!
! $user->setAppId($appId);
! $user->setUserName($userName);
! $user->setPassword($password);
!
! return $user;
}
--- 76,92 ----
* Authenticates a user to an application
*
! * This is a pass through method that sends the authentication request on
! * to the invoker.
*
* @author Tony Bibbs <tony AT geeklog DOT net>
* @param string $appId Application to authenticate to
* @param string $userId User to authenticate
* @param string $password Password to authenticate with
! * @return AAUser Object containing a list of authorization levels
*
*/
! function &authenticate($appId, $userName, $password)
{
! return $this->_invoker->authenticate($appId, $userName, $password);
}
***************
*** 83,108 ****
* Changes a password for a user
*
! * This method changes the password for the given userId, password and
! * application ID combination.
*
! * @author Tony Bibbs <tony AT geeklog DOT net>
! * @param string $aaServer A&A Server to execute against
* @param string $appId Application to change password for
* @param string $userId User to change password for
* @param string $password Current password
* @param string $newPassword New password
- * @param string $aaPort Port on A&A server to execute against
* @return boolean True if change worked, otherwise false
*
*/
! function changePassword($aaServer, $appId, $userName, $password, $newPassword, $aaPort=80)
{
! $requestXML = AAServiceInterface::_buildChangePasswordRequest($appId, $userName, $password, $newPassword);
! $responseXML = AAServiceInterface::_request($aaServer,'POST','/~tony/server/A_and_A/',$requestXML,$aaPort);
! $error = AAServiceInterface::_handleResponse($responseXML);
! if ($error) {
! return false;
! }
! return true;
}
--- 94,112 ----
* Changes a password for a user
*
! * This is a pass through method that sends the change password request
! * on to the invoker.
*
! * @author Tony Bibbs <tony at geeklog.net>
! * @access public
* @param string $appId Application to change password for
* @param string $userId User to change password for
* @param string $password Current password
* @param string $newPassword New password
* @return boolean True if change worked, otherwise false
*
*/
! function changePassword($appId, $userName, $password, $newPassword)
{
! return $this->_invoker->changePassword($appId, $userName, $password, $newPassword);
}
***************
*** 110,145 ****
* Allows admin to change a user's password
*
! * This method allows an admin user ot change the password of a user to a
! * particular value.
*
! * @param string $aaServer A&A Server to execute against
* @param string $appId Application to change password for
! * @param string $adminUserId User to change password for
! * @param string $adminPassword Current password
* @param string $userId User to change password for
* @param string $newPassword New password
- * @param string $aaPort Port on A&A server to execute against
*
*/
! function changePasswordByAdmin($aaServer, $appId, $adminUserName, $adminPassword, $userName, $newPassword, $aaPort=80)
{
! $requestXML = AAServiceInterface::_buildChangePasswordByAdminRequest($appId, $adminUserName, $adminPassword, $userName, $newPassword);
! $responseXML = AAServiceInterface::_request($aaServer,'POST','/~tony/server/A_and_A/',$requestXML,$aaPort);
! $error = AAServiceInterface::_handleResponse($responseXML);
! if ($error) {
! return false;
! }
! return true;
}
! function resetPassword($aaServer, $appId, $adminUserName, $adminPassword, $userName, $aaPort=80)
{
! $requestXML = AAServiceInterface::_buildResetPasswordRequest($appId, $adminUserName, $adminPassword, $userName);
! $responseXML = AAServiceInterface::_request($aaServer, 'POST', '/~tony/server/A_and_A/', $requestXML, $aaPort);
! $newPassword = AAServiceInterface::_handleResetPasswordResponse($responseXML);
! if (get_class($newPassword) == 'aaexception') {
! return false;
! }
! return $newPassword;
}
--- 114,147 ----
* Allows admin to change a user's password
*
! * Pass through method to the invoker's changePasswordByAdmin function
*
! * @author Tony Bibbs <tony at geeklog.net>
! * @access public
* @param string $appId Application to change password for
! * @param string $adminUserId Admin's username
! * @param string $adminPassword Admin's current password
* @param string $userId User to change password for
* @param string $newPassword New password
*
*/
! function changePasswordByAdmin($appId, $adminUserName, $adminPassword, $userName, $newPassword)
{
! return $this->_invoker->changePasswordByAdmin($appId, $adminUserName, $adminPassword, $userName, $newPassword);
}
! /**
! * Resets a user's password
! *
! * @author Tony BIbbs <tony at geeklog.net>
! * @access public
! * @param string $appId Application to perform action on
! * @param string $adminUserName Admin's username
! * @param string $adminPassword Admin's password
! * @return string New password
! *
! */
! function resetPassword($appId, $adminUserName, $adminPassword, $userName)
{
! return $this->_invoker->resetPassword($appId, $adminUserName, $adminPassword, $userName);
}
***************
*** 156,168 ****
*
*/
! function getUserPrivileges($aaServer, $appId, $adminUserId, $adminPassword, $userId, $aaPort=80)
{
! $requestXML = AAServiceInterface::_buildGetUserPrivilegesRequest($appId, $adminUserId, $adminPassword, $userId);
! $responseXML = AAServiceInterface::_request($aaServer, 'POST', '/entaaa/', $requestXML, $aaPort);
! $privArray= AAServiceInterface::_handleGetUserPrivilegesResponse($responseXML);
! if (get_class($privArray) == 'aaexception') {
! return false;
! }
! return $privArray;
}
--- 158,164 ----
*
*/
! function getUserPrivileges($appId, $adminUserId, $adminPassword, $userId)
{
! return $this->_invoker->getUserPrivileges($appId, $adminUserId, $adminPassword);
}
***************
*** 177,189 ****
*
*/
! function setUserPrivileges($aaServer, $appId, $adminUserId, $adminPassword, $userId, $privArray, $aaPort=80)
{
! $requestXML = AAServiceInterface::_buildSetUserPrivilegesRequest($appId, $adminUserId, $adminPassword, $userId, $privArray);
! $responseXML = AAServiceInterface::_request($aaServer, 'POST', '/~tony/server/A_and_A/', $requestXML, $aaPort);
! $error = AAServiceInterface::_handleResponse($responseXML);
! if ($error) {
! return false;
! }
! return true;
}
--- 173,179 ----
*
*/
! function setUserPrivileges($appId, $adminUserId, $adminPassword, $userId, $privArray)
{
! return $this->_invoker->setUserPrivileges($appId, $adminUserId, $adminPassword, $userId, $privArray);
}
***************
*** 197,752 ****
*
*/
! function listAppPrivileges($aaServer, $appId, $adminUserName, $adminPassword, $aaPort=80)
{
! $requestXML = AAServiceInterface::_buildListAppPrivilegesRequest($appId, $adminUserName, $adminPassword);
! $responseXML = AAServiceInterface::_request($aaServer, 'POST', '/~tony/server/A_and_A/', $requestXML, $aaPort);
! $privArray = AAServiceInterface::_handleListAppPrivilegesResponse($responseXML);
!
! if (get_class($privArray) == 'aaexception') {
! return false;
! }
! return $privArray;
}
! function listAppGroups($aaServer, $appId, $adminUserName, $adminPassword, $aaPort=80)
! {
! $requestXML = AAServiceInterface::_buildListAppGroupsRequest($appId, $adminUserName, $adminPassword);
! $responseXML = AAServiceInterface::_request($aaServer, 'POST', '/~tony/server/A_and_A/', $requestXML, $aaPort);
! $groupArray = AAServiceInterface::_handleListAppGroupsResponse($responseXML);
!
! if (get_class($groupArray) == 'aaexception') {
! return false;
! }
! return $groupArray;
! }
!
! // Private Methods
!
! /**
! * Makes HTTP resquests and returns the results. Code take from
! * http://dodds.net/~cardinal/sentohost.txt
! *
! * Examples: $this->_request('localhost','post','/search','q=php_imlib');
! *
! * @access private
! * @param string $host Host to make request to
! * @param string $method Method of request (POST or GET)
! * @param string $data
! * @param integer $port Port to connect to
! * @param string $useragent
! * @return string Response from the request
! *
! */
! function _request($host, $method, $path, $data, $port=80, $useragent=0)
! {
! // The following two lines are for testing only. This will test all methods against
! // a mock server. The mock server makes no attempts to validate the incoming
! // XML nor use any real provider. It simply prints a valid response for the
! // method called. It is meant for regressing testing the client separate from
! // the server.
! //$host = 'localhost';
! //$path = '/A_and_A/client/testscripts/mockserver.php';
!
! //print "host: $host, method = $method, path = $path, port = $port";
! //exit;
!
! // We are doing a form post and this variable is always expected
! $data = 'xmlInParam=' . $data;
!
! // Xerces can't seem to handle any sort of whitespace
! $data = str_replace("|",'',$data);
! $data = str_replace("\n",'',$data);
! $data = str_replace(' ','',$data);
! $data = str_replace('> <','><',$data);
!
! $data = stripslashes($data);
!
! // Supply a default method of GET if the one passed was empty
! if (empty($method)) {
! $method = 'GET';
! }
!
! // Open the socket
! $method = strtoupper($method);
!
! $fp = fsockopen($host,$port);
! if (!$fp) {
! print 'error connect to A&A server in _request';
! exit;
! }
!
! if ($method == 'GET') {
! $path .= '?' . $data;
! }
!
! // Post the request
! fputs($fp, "$method $path HTTP/1.1\n");
! fputs($fp, "Host: $host\n");
! fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
! fputs($fp, "Content-length: " . strlen($data) . "\n");
!
! if ($useragent) {
! fputs($fp, "User-Agent: MSIE\n");
! }
!
! fputs($fp, "Connection: close\n\n");
! if ($method == 'POST') {
! fputs($fp, $data);
! }
!
! $response = '';
!
! // Get the response
! while (!feof($fp)) {
! $response .= fgets($fp,128);
! }
!
! fclose($fp);
!
! // Since we are reading from the socket let's get rid of any header
! // info
! $startPos = strpos($response,'<');
! $endPos = strrpos($response,'>') + 1;
! $length = ($endPos - $startPos) + 1;
! $response = substr($response, $startPos, $length);
!
! // Now we have just the XML
! return $response;
! }
!
! /**
! * Builds an XML request string for the A&A service
! *
! * @access private
! * @param string $host Hostname or IP for A&A Server
! * @param string $appId ID of application making the request
! * @param string $userID ID of user to authenticate
! * @param string $password Password to use
! * @return string XML request is outputed.
! *
! */
! function _buildAuthenticateRequest($appId, $userId, $password)
! {
! $tree = new XML_Tree;
! $root = &$tree->addRoot(AA_SERVICE_TAG);
! $authNode = &$root->addChild('Authenticate');
! $appIDNode = &$authNode->addChild(APPLICATION_ID_TAG,'',array('value'=>"$appId"));
! $userIDNode = &$authNode->addChild(USER_NAME_TAG,'',array('value'=>"$userId"));
! $passwordNode = &$authNode->addChild(PASSWORD_TAG,'',array('value'=>"$password"));
! return $tree->get();
! }
!
! /**
! * Parses a XML response from the authenticate service method* and builds
! * a user object
! *
! * @param string $responseXML XML returned from authenticate()
! * @return AAUser User object
! *
! */
! function &_handleAuthenticateResponse($responseXML, $aaServer, $aaPort='80')
! {
! $p = xml_parser_create();
! xml_parse_into_struct($p,$responseXML,$vals,$index) or die(xml_error_string(xml_get_error_code($p)));
! xml_parser_free($p);
! $error = AAServiceInterface::_exceptionCheck($index, $vals);
! if ($error) {
! return $error;
! }
!
! $user = new AAUser($aaServer, $aaPort);
! $user->setEmpId($vals[$index['EMPID'][0]]);
! $groupIndexes = $index['GROUP'];
! $privIndexes = $index['PRIVILEGE'];
!
! // Get all the groups
! foreach ($groupIndexes as $curIndex) {
! $curGroup = $vals[$curIndex];
! $user->_groups[] = &AAServiceInterface::_buildGroup($curGroup);
! }
!
! // Get all the privileges
! foreach ($privIndexes as $curIndex) {
! $curPriv = $vals[$curIndex];
! $user->_privileges[] = &AAServiceInterface::_buildPrivilege($curPriv);
! }
!
! return $user;
! }
!
! /**
! * Generic response handler.
! *
! * This handles all responses from A&A server. This is called by all commands
! * except for authenticate and privilege-related calls.
! *
! * @access private
! * @param string $responseXML XML returned from changePasswordByAdmin()
! *
! */
! function _handleResponse($responseXML)
! {
! $p = xml_parser_create();
! xml_parse_into_struct($p,$responseXML,$vals,$index) or die(xml_error_string(xml_get_error_code($p)));
! xml_parser_free($p);
! $error = AAServiceInterface::_exceptionCheck($index, $vals);
! if ($error) {
! return $error;
! }
! return false;
! }
!
! /**
! * Builds XML request string for A&A Service to change a user's password
! *
! * @access private
! * @param string $appId Applicatoin ID
! * @param string $userId User ID
! * @param string $oldPassword Old password
! * @param string $newPassword NewPassword
! * @return string XML request
! *
! */
! function _buildChangePasswordRequest($appId, $userId, $oldPassword, $newPassword)
! {
! $tree = new XML_Tree;
! $root = &$tree->addRoot(AA_SERVICE_TAG);
! $changePasswordNode = &$root->addChild('ChangePassword');
! $tmpNode = &$changePasswordNode->addChild(APPLICATION_ID_TAG, '', array('value'=>$appId));
! $tmpNode = &$changePasswordNode->addChild(USER_NAME_TAG, '', array('value'=>$userId));
! $tmpNode = &$changePasswordNode->addChild(OLD_PASSWORD_TAG, '', array('value'=>"$oldPassword"));
! $tmpNode = &$changePasswordNode->addChild(NEW_PASSWORD_TAG, '', array('value'=>"$newPassword"));
!
! return $tree->get();
! }
!
!
! /**
! * Builds an XML request for A&A Service to call changePasswordByAdmin on server
! *
! * @access private
! * @param string $appId Application ID
! * @param string $userId User ID
! * @param string $password Old password
! * @param string $newPassword New Password
! * @return string XML request
! *
! */
! function _buildChangePasswordByAdminRequest($appId, $adminUserId, $adminPassword, $userId, $newPassword)
! {
! $tree = new XML_Tree;
! $root = &$tree->addRoot(AA_SERVICE_TAG);
! $changePassNode = &$root->addChild('ChangePasswordByAdmin');
! $tmpNode = &$changePassNode->addChild(APPLICATION_ID_TAG, '', array('value'=>"$appId"));
! $tmpNode = &$changePassNode->addChild(ADMIN_USER_NAME_TAG, '', array('value'=>"$adminUserId"));
! $tmpNode = &$changePassNode->addChild(ADMIN_PASSWORD_TAG, '', array('value'=>"$adminPassword"));
! $tmpNode = &$changePassNode->addChild(USER_NAME_TAG, '', array('value'=>"$userId"));
! $tmpNode = &$changePassNode->addChild(NEW_PASSWORD_TAG, '', array('value'=>"$newPassword"));
!
! return $tree->get();
! }
!
! /**
! * Handles the response from the A&A server to our request to changePasswordByAdmin
! *
! * @access private
! * @param string $responseXML XML returned from changePasswordByAdmin
! *
! */
! function _handleChangePasswordByAdminResponse($responseXML)
! {
! $p = xml_parser_create();
! xml_parse_into_struct($p,$responseXML,$vals,$index) or die(xml_error_string(xml_get_error_code($p)));
! xml_parser_free($p);
! $error = AAServiceInterface::_exceptionCheck($index, $vals);
! if ($error) {
! return true;
! }
! return false;
! }
!
! /**
! * Builds an XML request for A&A Service to call resetPassword on server
! *
! * @access private
! * @param string $appId Application ID
! * @param string $adminUserName Admin's username
! * @param string $adminPassword Admin's password
! * @param string $userName username of user to reset password for
! * return string XML request
! *
! */
! function _buildResetPasswordRequest($appId, $adminUserName, $adminPassword, $userName)
! {
! $tree = new XML_Tree;
! $root = &$tree->addRoot(AA_SERVICE_TAG);
! $resetPassNode = &$root->addChild('ResetPassword');
! $tmpNode = &$resetPassNode->addChild(APPLICATION_ID_TAG, '', array('value'=>"$appId"));
! $tmpNode = &$resetPassNode->addChild(ADMIN_USER_NAME_TAG, '', array('value'=>"$adminUserName"));
! $tmpNode = &$resetPassNode->addChild(ADMIN_PASSWORD_TAG, '', array('value'=>"$adminPassword"));
! $tmpNode = &$resetPassNode->addChild(USER_NAME_TAG, '', array('value'=>"$userName"));
!
! return $tree->get();
! }
!
!
! function _handleResetPasswordResponse($responseXML)
! {
! $p = xml_parser_create();
! xml_parse_into_struct($p,$responseXML,$vals,$index) or die(xml_error_string(xml_get_error_code($p)));
! xml_parser_free($p);
! $error = AAServiceInterface::_exceptionCheck($index, $vals);
! if ($error) {
! return $error;
! }
!
! return $vals[$index['NEWPASSWORD'][0]];
! }
! /**
! * Builds an XML request for A&A Service to call getUserPrivilges on server
! *
! * @access private
! * @param string $appId Application ID
! * @param string $adminUserId Admin's user ID
! * @param string $adminPassword Admin's password
! * @param string $userId User to get privileges for
! * @return string XML request
! *
! */
! function _buildGetUserPrivilegesRequest($appId, $adminUserName, $adminPassword, $userName)
! {
! $tree = new XML_Tree;
! $root = &$tree->addRoot(AA_SERVICE_TAG);
! $getUserPrivilegesNode = &$root->addChild('GetUserPrivileges');
! $tmpNode = &$getUserPrivilegesNode->addChild(APPLICATION_ID_TAG, '', array('value'=>"$appId"));
! $tmpNode = &$getUserPrivilegesNode->addChild(ADMIN_USER_NAME_TAG, '', array('value'=>"$adminUserName"));
! $tmpNode = &$getUserPrivilegesNode->addChild(ADMIN_PASSWORD_TAG, '', array('value'=>"$adminPassword"));
! $tmpNode = &$getUserPrivilegesNode->addChild(USER_NAME_TAG, '', array('value'=>"$userName"));
!
! return $tree->get();
! }
!
! function _handleGetUserPrivilegesResponse($responseXML)
! {
! $p = xml_parser_create();
! xml_parse_into_struct($p,$responseXML,$vals,$index) or die(xml_error_string(xml_get_error_code($p)));
! xml_parser_free($p);
! $error = AAServiceInterface::_exceptionCheck($index, $vals);
! if ($error) {
! return $error;
! }
!
! $privIndexes = $index['PRIVILEGE'];
! $privArray = array();
!
! // Get all the privileges
! foreach ($privIndexes as $curIndex) {
! $curPriv = $vals[$curIndex];
! $privArray[] = &AAServiceInterface::_buildPrivilege($curPriv);
! }
!
! return $privArray;
! }
!
! /**
! * Builds an XML request for A&A Service to call setUserPrivileges on server
! *
! * @access private
! * @param string $appId Application ID
! * @param string $adminUserId Admin's user ID
! * @param string $adminPassword Admin's password
! * @param string $userId User to set privileges for
! * @param AAPrivilege[] $privileges Array of privileges to give user
! * @return string XML request
! *
! */
! function _buildSetUserPrivilegesRequest($appId, $adminUserId, $adminPassword, $userId, $privileges)
! {
! $tree = new XML_Tree;
! $root = &$tree->addRoot(AA_SERVICE_TAG);
! $setUserPrivilegesNode = &$root->addChild('SetUserPrivileges');
! $tmpNode = &$setUserPrivilegesNode->addChild(APPLICATION_ID_TAG, '', array('value'=>$appId));
! $tmpNode = &$setUserPrivilegesNode->addChild(ADMIN_USER_ID_TAG, '', array('value'=>$adminUserId));
! $tmpNode = &$setUserPrivilegesNode->addChild(ADMIN_PASSWORD_TAG, '', array('value'=>$adminPassword));
! $tmpNode = &$setUserPrivilegesNode->addChild(USER_ID_TAG, '', array('value'=>$userId));
! $privilegeListNode = &$setUserPrivilegesNode->addChild(PRIVILEGE_LIST_TAG);
! foreach ($privileges as $curPriv) {
! $tmpNode = &$privilegeListNode->addChild(PRIVILEGE_TAG, $curPriv->getPrivilegeDesc(), array('value'=>$curPriv->getPrivilegeCode()));
! }
!
! return $tree->get();
! }
!
! function _handleSetUserPrivilegesResponse($responseXML)
! {
! }
!
! /**
! * Builds an XML request for A&A Service to call listAllPrivileges on server
! *
! * @access private
! * @param string $appId Application ID
! * @param string $adminUserId Admin's user ID
! * @param string $adminPassword Admin's password
! * @return AAPrivilege[] Array of privileges
! *
! */
! function _buildListAppPrivilegesRequest($appId, $adminUserName, $adminPassword)
! {
! $tree = new XML_Tree;
! $root = &$tree->addRoot(AA_SERVICE_TAG);
! $listAppPrivilegesNode = &$root->addChild('ListAppPrivileges');
! $tmpNode = &$listAppPrivilegesNode->addChild(APPLICATION_ID_TAG, '', array('value'=>"$appId"));
! $tmpNode = &$listAppPrivilegesNode->addChild(ADMIN_USER_NAME_TAG, '', array('value'=>"$adminUserName"));
! $tmpNode = &$listAppPrivilegesNode->addChild(ADMIN_PASSWORD_TAG, '', array('value'=>"$adminPassword"));
!
! return $tree->get();
! }
!
! function _handleListAppPrivilegesResponse($responseXML)
! {
! $p = xml_parser_create();
! xml_parse_into_struct($p,$responseXML,$vals,$index) or die(xml_error_string(xml_get_error_code($p)));
! xml_parser_free($p);
! $error = AAServiceInterface::_exceptionCheck($index, $vals);
! if ($error) {
! return $error;
! }
!
! $privIndexes = $index['PRIVILEGE'];
! $privArray = array();
!
! // Get all the privileges
! foreach ($privIndexes as $curIndex) {
! $curPriv = $vals[$curIndex];
! $privArray[] = &AAServiceInterface::_buildPrivilege($curPriv);
! }
!
! return $privArray;
! }
!
! /**
! * Builds an XML request for A&A Service to call listAllPrivileges on server
! *
! * @access private
! * @param string $appId Application ID
! * @param string $adminUserId Admin's user ID
! * @param string $adminPassword Admin's password
! * @return AAPrivilege[] Array of privileges
! *
! */
! function _buildListAppGroupsRequest($appId, $adminUserName, $adminPassword)
{
! $tree = new XML_Tree;
! $root = &$tree->addRoot(AA_SERVICE_TAG);
! $listAppGroupNode = &$root->addChild('ListAppGroups');
! $tmpNode = &$listAppGroupNode->addChild(APPLICATION_ID_TAG, '', array('value'=>"$appId"));
! $tmpNode = &$listAppGroupNode->addChild(ADMIN_USER_NAME_TAG, '', array('value'=>"$adminUserName"));
! $tmpNode = &$listAppGroupNode->addChild(ADMIN_PASSWORD_TAG, '', array('value'=>"$adminPassword"));
!
! return $tree->get();
}
- function _handleListAppGroupsResponse($responseXML)
- {
- $p = xml_parser_create();
- xml_parse_into_struct($p,$responseXML,$vals,$index) or die(xml_error_string(xml_get_error_code($p)));
- xml_parser_free($p);
- $error = AAServiceInterface::_exceptionCheck($index, $vals);
- if ($error) {
- return $error;
- }
-
- $groupArray = array();
- $groupIndexes = $index['GROUP'];
-
- // Get all the groups
- foreach ($groupIndexes as $curIndex) {
- $curGroupVals = $vals[$curIndex];
- $curGroup = &AAServiceInterface::_buildGroup($curGroupVals);
-
- $privIndexes = $index['PRIVILEGE'];
- // Get all the privileges
- foreach ($privIndexes as $curIndex) {
- $curPriv = $vals[$curIndex];
- $curGroup->_privileges[] = &AAServiceInterface::_buildPrivilege($curPriv);
- }
- $groupArray[] = $curGroup;
- }
-
- return $groupArray;
- }
- /**
- * Return a group object built from a string array
- *
- * @access private
- * @param string[] String array to create group from
- * @return AAGroup Group object
- *
- */
- function &_buildGroup($groupArray)
- {
- // Make sure we got a good array
- is_array($groupArray) or die ('_buildGroup did not get a valid array sent to it');
-
- $curGroup = new AAGroup();
- $curGroup->setGroupId($groupArray['attributes']['ID']);
- $curGroup->setGroupLogicalName($groupArray['attributes']['LOGICAL']);
- $curGroup->setGroupId($groupArray['attributes']['DISPLAY']);
- $curGroup->setGroupDesc($groupArray['value']);
-
- /*$privIndexes = $index['PRIVILEGE'];
-
- // Get all the privileges
- foreach ($privIndexes as $curIndex) {
- $curPriv = $vals[$curIndex];
- $user->_privileges[] = &AAServiceInterface::_buildPrivilege($curPriv);
- }*/
-
- return $curGroup;
- }
-
- /**
- * Return a privilige object built from a string array
- *
- * @access private
- * @param string[] String array to create privilege from
- * @return AAPrivilege Privilege object
- *
- */
- function &_buildPrivilege($privilegeArray)
- {
- // Make sure we got a good array
- is_array($privilegeArray) or die ('_buildPrivilege did not get a valid array sent to it');
-
- $privilege = new AAPrivilege();
- $privilege->setPrivilegeCode($privilegeArray['attributes']['CODE']);
- $privilege->setPrivilegeDesc($privilegeArray['value']);
-
- return $privilege;
- }
-
- /**
- * Checks to see if we received some sort of exception
- *
- * @access private
- * @param string $responseXML
- * @return object|boolean returns an exception object, otherwise false
- *
- */
- function _exceptionCheck($index, $vals)
- {
- $retval = $vals[$index['RESULT'][0]]['attributes']['VALUE'];
-
- if ($retval == 0) {
- return false;
- }
-
- $exception = new AAException($retval);
- $exception->message = $vals[$index['RESULT'][0]]['value'];
-
- return $exception;
- }
}
--- 187,201 ----
*
*/
! function listAppPrivileges($appId, $adminUserName, $adminPassword)
{
! return $this->_invoker->listAppPrivileges($appId, $adminUserName, $adminPassword);
}
! function listAppGroups($appId, $adminUserName, $adminPassword)
{
! return $this->_invoker->listAppGroups($appId, $adminUserName, $adminPassword);
}
}
More information about the geeklog-cvs
mailing list