Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/08/2013, 03:05
arhalien
 
Fecha de Ingreso: julio-2013
Mensajes: 4
Antigüedad: 10 años, 10 meses
Puntos: 0
¿Como validar los usuarios de un web service en PHP?

Hola a todos,

He implementado un web service mediante PHP que funciona correctamente. Mi problema es que debo validar que la persona que lo va a consumir tiene acceso. Algo así como un usuario y contraseña, yo me conecto a otros web services que han sido implementados con Java a través de un usernametoken, se que algo así se puede hacer con heades en php. ¿Existe algo parecido en php o algún otro método más sencillo? he encontrado poca información sobre este tema y la que he encontrado es bastante compleja y no me ha salido, si alguien pudiera ponerme algún ejemplo se lo agradecería.

Os dejo el código de mi servicio Web, del cliente que he implementado para comprobar que funciona y del wsdl que se genera por si sirve de ayuda. Muchas gracias.

Servidor:

<?php

// Pull in the NuSOAP code

require_once('lib/nusoap.php');

// Create the server instance

$server = new soap_server();

// Initialize WSDL support

$server->configureWSDL('entregaswsdl','urn:entregaswsdl' );

// Register the method to expose

$server->register('actualizarEstadoCooperacion',array('est adoCoop'=>'xsd:string','idEntrega'=>'xsd:string'), array('return'=>'xsd:string'),'urn:entregaswsdl',' urn:entregaswsdl#actualizarEstadoCooperacion');
$server->register('actualizarEstadoAsistencia',array('esta doAsist'=>'xsd:string','idEntrega'=>'xsd:string'), array('return'=>'xsd:string'),'urn:entregaswsdl',' urn:entregaswsdl#actualizarEstadoAsistencia');
$server->register('actualizarFechaCooperacion',array('fech aCoop'=>'xsd:string','idEntrega'=>'xsd:string'),ar ray('return'=>'xsd:string'),'urn:entregaswsdl','ur n:entregaswsdl#actualizarFechaCooperacion');
$server->register('actualizarFechaAsistencia',array('fecha Asist'=>'xsd:string','idEntrega'=>'xsd:string'),ar ray('return'=>'xsd:string'),'urn:entregaswsdl','ur n:entregaswsdl#actualizarFechaAsistencia');

// Define the method as a PHP function

function actualizarEstadoCooperacion($estadoCoop,$idEntrega )
{
include 'includes/dbconfig.php';
$q = "UPDATE entregas SET estado_coop ='".$estadoCoop."' WHERE CAST(identrega AS text) ='".$idEntrega."'";
pg_query($dbconn_config, $q) or die("Error in query: $q. " . pg_last_error($conexion));
return "estado coop actualizado";
//return $q;
}

function actualizarEstadoAsistencia($estadoAsist,$idEntrega )
{
include 'includes/dbconfig.php';
$q = "UPDATE entregas SET estado_asist ='".$estadoAsist."' WHERE CAST(identrega AS text) ='".$idEntrega."'";
pg_query($dbconn_config, $q) or die("Error in query: $q. " . pg_last_error($conexion));
return "estado asist actualizado";
}

function actualizarFechaCooperacion($fechaCoop,$idEntrega)
{
include 'includes/dbconfig.php';
$q = "UPDATE entregas SET fecha_coop ='".$fechaCoop."' WHERE CAST(identrega AS text) ='".$idEntrega."'";
pg_query($dbconn_config, $q) or die("Error in query: $q. " . pg_last_error($conexion));
return "fecha coop actualizada";
}

function actualizarFechaAsistencia($fechaAsist,$idEntrega)
{
include 'includes/dbconfig.php';
$q = "UPDATE entregas SET fecha_asist ='".$fechaAsist."' WHERE CAST(identrega AS text) ='".$idEntrega."'";
pg_query($dbconn_config, $q) or die("Error in query: $q. " . pg_last_error($conexion));
return "fecha asist actualizado";
}

// Use the request to (try to) invoke the service

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);

?>


Cliente:

<?php

require_once('lib/nusoap.php');
$idEntrega = "21";
$estadoCoop = "P";
$estadoAsist = "P";
$fechaCoop = "20130821100000";
$fechaAsist = "20130821100100";
$wsu = 'http://schemas.xmlsoap.org/ws/2002/07/utility';
$url = 'http://127.0.0.1/eiel/trunk/webservice_entregas.php?wsdl';
$objClient = new SoapClient($url, array('trace' => 1, 'connection_timeout' => 10,'exceptions' => 1,'encoding' => 'UTF-8'));
$xmlRespuesta1 = $objClient->actualizarEstadoCooperacion($estadoCoop,$idEntreg a);
$xmlRespuesta2 = $objClient->actualizarEstadoAsistencia($estadoAsist,$idEntreg a);
$xmlRespuesta3 = $objClient->actualizarFechaCooperacion($fechaCoop,$idEntrega) ;
$xmlRespuesta4 = $objClient->actualizarFechaAsistencia($fechaAsist,$idEntrega) ;
echo $xmlRespuesta1."<br>";
echo $xmlRespuesta2."<br>";
echo $xmlRespuesta3."<br>";
echo $xmlRespuesta4."<br>";
?>

wsdl:

<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:entregaswsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:entregaswsdl">
<types>
<xsd:schema targetNamespace="urn:entregaswsdl">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
</xsd:schema>
</types>
<message name="actualizarEstadoCooperacionRequest">
<part name="estadoCoop" type="xsd:string"/>
<part name="idEntrega" type="xsd:string"/>
</message>
<message name="actualizarEstadoCooperacionResponse">
<part name="return" type="xsd:string"/>
</message>
<message name="actualizarEstadoAsistenciaRequest">
<part name="estadoAsist" type="xsd:string"/>
<part name="idEntrega" type="xsd:string"/>
</message>
<message name="actualizarEstadoAsistenciaResponse">
<part name="return" type="xsd:string"/>
</message>
<message name="actualizarFechaCooperacionRequest">
<part name="fechaCoop" type="xsd:string"/>
<part name="idEntrega" type="xsd:string"/>
</message>
<message name="actualizarFechaCooperacionResponse">
<part name="return" type="xsd:string"/>
</message>
<message name="actualizarFechaAsistenciaRequest">
<part name="fechaAsist" type="xsd:string"/>
<part name="idEntrega" type="xsd:string"/>
</message>
<message name="actualizarFechaAsistenciaResponse">
<part name="return" type="xsd:string"/>
</message>
<portType name="entregaswsdlPortType">
<operation name="actualizarEstadoCooperacion">
<input message="tns:actualizarEstadoCooperacionRequest"/>
<output message="tns:actualizarEstadoCooperacionResponse"/>
</operation>
<operation name="actualizarEstadoAsistencia">
<input message="tns:actualizarEstadoAsistenciaRequest"/>
<output message="tns:actualizarEstadoAsistenciaResponse"/>
</operation>
<operation name="actualizarFechaCooperacion">
<input message="tns:actualizarFechaCooperacionRequest"/>
<output message="tns:actualizarFechaCooperacionResponse"/>
</operation>
<operation name="actualizarFechaAsistencia">
<input message="tns:actualizarFechaAsistenciaRequest"/>
<output message="tns:actualizarFechaAsistenciaResponse"/>
</operation>
</portType>
<binding name="entregaswsdlBinding" type="tns:entregaswsdlPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="actualizarEstadoCooperacion">
<soap:operation soapAction="urn:entregaswsdl#actualizarEstadoCoope racion" style="rpc"/>
<input>
<soap:body use="encoded" namespace="urn:entregaswsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:entregaswsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="actualizarEstadoAsistencia">
<soap:operation soapAction="urn:entregaswsdl#actualizarEstadoAsist encia" style="rpc"/>
<input>
<soap:body use="encoded" namespace="urn:entregaswsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:entregaswsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="actualizarFechaCooperacion">
<soap:operation soapAction="urn:entregaswsdl#actualizarFechaCooper acion" style="rpc"/>
<input>
<soap:body use="encoded" namespace="urn:entregaswsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:entregaswsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="actualizarFechaAsistencia">
<soap:operation soapAction="urn:entregaswsdl#actualizarFechaAsiste ncia" style="rpc"/>
<input>
<soap:body use="encoded" namespace="urn:entregaswsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:entregaswsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="entregaswsdl">
<port name="entregaswsdlPort" binding="tns:entregaswsdlBinding">
<soap:address location="http://127.0.0.1/eiel/trunk/webservice_entregas.php"/>
</port>
</service>
</definitions>