问题描述
我需要为我的肥皂服务器添加凭据,但我在这方面没有太多经验。我必须使用什么来添加用户和密码?
<?PHP
require_once "vendor/econea/nusoap/src/nusoap.PHP";
$namespace = "testeSoap";
$server = new soap_server();
$server->configureWSDL("PinchesSOAP",$namespace);
$server->wsdl->schemaTargetNamespace = $namespace;
$server->wsdl->addComplexType(
'Cliente','complexType','struct','all','',array(
'name' => array('name' => 'name','type'=>'xsd:string'),)
);
$server->wsdl->addComplexType(
'response',array(
'status' => array('name'=>'status','type'=>'xsd:string')
)
);
$server->register(
'notifyCustomerCreationRequest',array('name' => 'tns:Cliente'),array('name' => 'tns:response'),$namespace,false,'rpc','encoded',''
);
function notifyCustomerCreationRequest(){
return array(
"status" => "PEN"
);
}
$POST_DATA = file_get_contents("PHP://input");
$server->service($POST_DATA);
exit();
我将使用soapUI并需要验证信息,但不知道。
解决方法
对于基于 head 的简单身份验证,您可以执行以下操作:
在您的主要方法 (notifyCustomerCreationRequest) 中:
function notifyCustomerCreationRequest(){
global $server;
$requestHeaders = $server->requestHeader;
if(ValidateUser($requestHeaders)){
//your business logic here
}
}
function ValidateUser($headers){
if(empty($requestHeaders)){
//$log->info("Envelope without headers");
return false;
}
if(array_key_exists("Security",$requestHeaders)){
if(array_key_exists("UsernameToken",$requestHeaders["Security"])){
if(!array_key_exists("Username",$requestHeaders["Security"]["UsernameToken"])){
//$log->info("Empty Username -> Headers");
return false;
}
if(!array_key_exists("Password",$requestHeaders["Security"]["UsernameToken"])){
//$log->info("Empty Password -> Headers");
return false;
}
$user = $requestHeaders["Security"]["UsernameToken"]["Username"];
$pass = $requestHeaders["Security"]["UsernameToken"]["Password"];
//$log->info("User:".$usuario);
//$log->info("Pass:".PRINT_R($pass));
if(($user== "blabla") && ($pass == "blabla")){
return true;
}
return false;
}else{
//$log->info("Empty UsernameToken -> Headers");
return false;
}
}else{
$log->info("Empty Security -> Headers");
return false;
}
return false;
}
SOAP 信封:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<wsse:Security soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0">
<wsse:Username soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next">USER</wsse:Username>
<wsse:Password soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next">PASSWORD</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
</soapenv:Body>
</soapenv:Envelope>