[geeklog-cvs] Auth_Enterprise/Enterprise/Client SOAP.php,NONE,1.1
tony at iowaoutdoors.org
tony at iowaoutdoors.org
Thu Jul 22 14:07:18 EDT 2004
Update of /var/cvs/Auth_Enterprise/Enterprise/Client
In directory www:/tmp/cvs-serv5698
Added Files:
SOAP.php
Log Message:
not really working yet but ready to be tracked in CVS
--- NEW FILE: SOAP.php ---
<?php
/**
* Auth_Enterprise
*
* This source file is subject to version 2.02 of the PHP license, that is bundled with this package
* in the file LICENSE, and is available at through the world-wide-web at
* http://www.php.net/license/2_02.txt. If you did not receive a copy of the PHP license and are
* unable to obtain it through the world-wide-web, please send a note to license at php.net so we can
* mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright 2004
* @version $Id: SOAP.php,v 1.1 2004/07/22 18:07:12 tony Exp $
*
*/
/**
* Auth_Enterprise abstract client provider
*/
require_once 'Auth/Enterprise/Client.php';
/**
* Auth_Enterprise constants
*/
require_once 'Auth/Enterprise/Constants.php';
/**
* Auth_Enterprise exceptions
*/
require_once 'Auth/Enterprise/Exceptions.php';
/**
* PEAR's XML RPC Client
*/
require_once 'XML/RPC.php';
/**
* Auth_Enteprise XML RPC Implementation
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.auth_enterprise.client
* @todo Need to implement SSL soon
*
*/
class Auth_Enterprise_Client_SOAP extends Auth_Enterprise_Client {
/**
* Instance of PEAR XML RPC Client
* @access private
* @var object
*/
private $SOAPClient = null;
/**
* Constructor
*
* Get handle to an instance of XML RPC Client. This client provider has the following options:
* - appId string Auth_Enterprise ID given to an application, REQUIRED
* - debug int 1=on, 0=off, OPTIONAL
* - wsdl string WSDL File for Auth_Enterprise SOAP Service, REQUIRED but can be null
* - php_soap_options Array of client options to built in PHP SOAP Server (See
* http://www.php.net/manual/en/function.soapclient-soapclient.php for details
*
*
* @author Tony Bibbs <tony at geeklog.net>
* @access public
* @param string $options Array of options for the XML RPC Client
* @todo refactor to support PHP's native XMLRPC methods as an alternative to using PEAR's
* implementation. This can be done without breaking client compatibility so I'm not in any rush yet.
*
*/
public function __construct($options)
{
// Build SOAP client
$this->SOAPClient = new SoapClient($options['wsdl'], $options['php_soap_options']);
parent::__construct($options);
}
/**
* Authenticates a user to an application
*
* @author Tony Bibbs <tony at geeklog.net>
* @access public
* @param string $userName Username to authenticate with
* @param string $password Password to authenticate with
* @return object AEServiceUser object
*
*/
public function authenticate($userName, $password)
{
//print_r($this->SOAPClient->__getFunctions()); exit;
$result = $this->SOAPClient->doAuthenticate($this->getAppId(), $username, $password);
if (is_soap_fault($result)) {
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faulstring})", E_ERROR);
}
// If we got a fault, throw an exception back to the calling
// application
if ($response->faultCode()) {
try {
$e = $this->faultToException($result->faultcode, $result->faultstring);
throw $e;
} catch (AEBaseException $e) {
throw $e;
}
}
/*$user = new Auth_Enterprise_User;
$user->setUserName($retval['userName']);
$user->setPassword($retval['password']);
$user->setClientProvider($this);
$user->setPrivileges($this->arrayToPrivileges($retval['privileges']));
$user->setGroups($this->arrayToGroups($retval['groups']));
return $user;
*/
return $result;
}
protected function parseOptions($options = array())
{
if (!isset($options['appId'])) {
throw new AEInsufficientClientOptions('XML-RPC Client requires the appId option to be set.');
}
if (!isset($options['wsdl'])) {
$options['wsdl'] = null;
}
if (!isset($options['php_soap_options'])) {
$options['php_soap_options'] = array();
}
// Enable debugging if requested.
/*if ($options['debug'] == 1) {
$this->XMLRPCClient->setDebug(true);
}*/
parent::parseOptions($options);
}
/**
* Copies the group arrays returned from the XML_RPC call
* into Group objects
*
* @author Tony Bibbs <tony at geeklog.net>
* @access private
* @param array $groupArray Array of group arrays
* @return array Array of AEGroup objects
*
*/
private function moveGroupsToObjects($groups)
{
$groupArray = array();
$tmpGroup = new Auth_Enterprise_Group();
foreach ($groups as $curGroup) {
$tmpGroup->setGroupId($curGroup[_groupId]);
$tmpGroup->setGroupLogicalName($curGroup['groupLogicalName']);
$tmpGroup->setGroupDisplayName($curGroup['groupDisplayName']);
$tmpGroup->setGroupDesc($curGroup[_groupDesc]);
$groupArray[] = $tmpGroup;
}
return $groupArray;
}
/**
* Converts an array from an XMLRPC response to an array of privileges objects
*
* @author Tony Bibbs <tony at geeklog.net>
* @access private
* @param array $privArray Array representing privilege objects
* @return array Array of actual AEPrivileges objects
*
*/
private function arrayToPrivileges($privArray)
{
$retval = array();
if (is_array($privArray)) {
foreach ($privArray as $curPriv) {
$newPriv = new Auth_Enterprise_Privilege();
$newPriv->setPrivilegeCode($curPriv['privilegeCode']);
$newPriv->setPrivilegeDesc($curPriv['privilegeDesc']);
$retval[] = $newPriv;
}
}
return $retval;
}
/**
* Converts AEPrivilege objects to arrays.
*
* @author Tony Bibbs <tony at geeklog.net>
* @access private
* @param array $privArray Array of AEPrivilege objects
* @return array Array representing AEPrivielge objects
*
*/
private function privilegesToArray($privArray)
{
$retval = array();
foreach ($privArray as $curPriv) {
$tmpArray['privilegeCode'] = $curPriv->getPrivilegeCode();
$tmpArray['privilegeDesc'] = $curPriv->getPrivilegeDesc();
$retval[] = $tmpArray;
}
return $retval;
}
/**
* Converts an array from an XMLRPC response to an array of group objects
*
* @author Tony Bibbs <tony at geeklog.net>
* @access private
* @param array $groupArray Array representing group objects
* @return array Array of actual AEGroup objects
*
*/
private function arrayToGroups($groupArray)
{
$retval = array();
if (is_array($groupArray)) {
foreach ($groupArray as $curGroup) {
$tmpGroup = new Auth_Enterprise_Group();
$tmpGroup->setGroupId($curGroup['groupId']);
$tmpGroup->setGroupLogicalName($curGroup['groupLogicalName']);
$tmpGroup->setGroupDisplayName($curGroup['groupDisplayName']);
$tmpGroup->setGroupDesc($curGroup['groupDesc']);
$tmpGroup->setGroupPrivileges($curGroup['privileges']);
$retval[] = $tmpGroup;
}
}
return $retval;
}
/**
* Converts AEPrivilege objects to arrays.
*
* @author Tony Bibbs <tony at geeklog.net>
* @access private
* @param array $privArray Array of AEPrivilege objects
* @return array Array representing AEPrivielge objects
*
*/
private function groupsToArray($groupArray)
{
$retval = array();
foreach ($groupArray as $curGroup) {
$tmpArray['groupId'] = $curGroup->getGroupId();
$tmpArray['groupLogicalName'] = $curGroup->getGroupLogicalName();
$tmpArray['groupDisplayName'] = $curGroup->getGroupDisplayName();
$tmpArray['groupDesc'] = $curGroup->getGroupDesc();
$retval[] = $tmpArray;
}
return $retval;
}
/**
* Converts SOAP faults into exceptions
*
* @author Tony Bibbs <tony at geeklog.net>
* @access private
* @param int $faultCode XMLRPC fault code
* @param string $faultMessage XMLRPC fault message
* @return object PHP5 exception
* @todo Move this code to Auth_Enterprise_Client as it is duplicated here and in xmlrpc client
*/
private function faultToException($faultCode, $faultMessage)
{
switch ($faultCode) {
case AESQLExceptionResp:
throw new AESQLException($faultMessage);
break;
case AEInvalidUserCredentialsResp:
throw new AEInvalidUserCredentials($faultMessage);
break;
case AEAccountLockedResp:
throw new AEAccountLocked($faultMessage);
break;
case AEPasswordExpiredResp:
throw new AEPasswordExpired($faultMessage);
break;
case AEPasswordInHistoryResp:
throw new AEPasswordInHistory($faultMessage);
break;
case AEPasswordInvalidResp:
throw new AEPasswordInvalid($faultMessage);
break;
case AEUnableToConnectResp:
throw new AEUnableToConnect($faultMessage);
break;
case AEUserNotAuthorizedResp:
throw new AEUserNotAuthorized($faultMessage);
break;
case AEInvalidPrivilegeResp:
throw new AEInvalidPrivilege($faultMessage);
break;
case AEInsufficientClientOptionsResp:
throw new AEInsufficientClientOptions($faultMessage);
break;
case AENoProviderResp:
throw new AENoProvider($faultMessage);
break;
case AELDAPBindErrorResp:
throw new AELDAPBindError($faultMessage);
break;
case AENoAppIdResp:
throw new AENoAppId($faultMessage);
break;
default:
throw new Exception($faultMessage);
}
}
}
?>
More information about the geeklog-cvs
mailing list