Authentication on header,
| From: | Jos� Morelli Neto | Date: | Tue, 02 Sep 2003 18:00:57 +0000 |
| Subject: | Authentication on header, | ||
| Groups: | php.soap | ||
| Request: | Send a blank email to php-soap+get-1029@lists.php.net to get a copy of this message | ||
Hi Folks!
I'm trying to make a test web server that authenticate before execute any
method. I´m try to use one example made from Shane Caraveo
(http://talks.php.net/show/soap-phpcon-ny2003/64), but i
give an error like this:
-------------------- error ------------------------
soap_fault Object
(
[error_message_prefix] =>
[mode] => 1
[level] => 1024
[code] => SOAP-ENV:MustUnderstand
[message] => I don't understand header authenticate.
[userinfo] => Array
-------------------- error ------------------------
The source i have test is this:
-------------------- server code ------------------------
<?php
include("SOAP/Client.php");
$soapclient =& new SOAP_Client("http://localhost/server.php");
$aee = array("username"=>"foo","password"=>"bar");
$header = new SOAP_Header( "{urn:Header_Handler}authenticate", "Struct",
$aee, "1");
$soapclient->addHeader($header);
$options = array("namespace" => "urn:SOAP_Auth_Server", "trace"
=> 1);
$params = array("inputString"=>"this is a test");
$ret = $soapclient->call('echoString', $params ,$options);
echo "<pre>";
print_r($ret);
?>
-------------------- server code ------------------------
-------------------- client code ------------------------
<?php
require_once 'SOAP/Server.php';
class Header_Handler {
var $method_namespace = 'urn:Header_Handler';
var $authenticated = FALSE;
function authenticate($authinfo)
{
if ($authinfo->username == 'foo' &&
$authinfo->password == 'bar') {
$this->authenticated = TRUE;
return "Authentication OK";
}
$faultcode = 'Client';
$faultstring = 'Invalid Authentication';
$faultactor = $this->method_namespace;
$detail = NULL;
return new SOAP_Fault($faultstring,
$faultcode,
$faultactor,
$detail);
}
}
class SOAP_Auth_Server {
function echoString($inputString)
{
if (!$this->headers->authenticated) {
return "Autenticated! ... $inputString";
} else {
return "You don´t have permission to execute any operation ... ";
}
}
}
$server =& new SOAP_Server;
$soapclass =& new SOAP_Auth_Server();
$server->addObjectMap($soapclass,'urn:SOAP_Auth_Server');
$server->service($HTTP_RAW_POST_DATA);
?>
-------------------- client code ------------------------
Can anyone help me with this? i'm new with pear::soap ...
Thank's for All!!
Neto.