【问题标题】:How do i set username and password in a soap server?如何在肥皂服务器中设置用户名和密码?
【发布时间】:2021-05-18 13:52:35
【问题描述】:

我需要为我的肥皂服务器添加凭据,但我在这方面没有太多经验。我必须使用什么来添加用户和密码?

<?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',
    'complexType',
    'struct',
    'all',
    '',
    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并需要验证信息,但不知道。

【问题讨论】:

    标签: php soap nusoap soapserver


    【解决方案1】:

    对于基于头的简单身份验证,您可以执行以下操作:

    在您的主要方法(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>
    

    【讨论】:

      猜你喜欢
      • 2021-11-29
      • 1970-01-01
      • 1970-01-01
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 2015-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多