Posts in web services

Cómo utilizar Zend_Auth_Adapter con Web Services

mayo 27th, 2011 Posted by php, web services, zend framework 0 thoughts on “Cómo utilizar Zend_Auth_Adapter con Web Services”
<?
class My_Auth_Adapter implements Zend_Auth_Adapter_Interface {

const OK_RESPONSE = 'OK';
const KO_RESPONSE = 'KO';

private $_username = '';
private $_password = '';
private $_data = null;

public function setIdentity($username) {
$this->_username = $username;
}

public function setCredential($password) {
$this->_password = $password;
}

/**
* Authenticate the user
*
* @return Zend_Auth_Result
*/
public function authenticate() {
$endpointLoginAuthor = Zend_Registry::get('config')->endpoint->userService->loginAuthor;

$client = new Zend_Rest_Client($endpointLoginAuthor);
$client->username($this->_username);
$client->password($this->_password);

$response = $client->get();

$authenticated = ($response->ResponseDescription == $this::OK_RESPONSE);
$authResult = Zend_Auth_Result::FAILURE;

$authMessages = array();

if ($authenticated){
// user is authenticated, overwrite the auth result:
$authResult = Zend_Auth_Result::SUCCESS;
$this->_data = $response->Author;
} else {
// Couldn't authenticate the user, set a message:
$authMessages[] = 'Datos de acceso inválidos.';
}

// return the result:
return new Zend_Auth_Result( $authResult, $this->_username, $authMessages );

}

/**
*
* @param <type> $returnColumns
* @param <type> $omitColumns
* @return <type> SimpleXMLObject
*/
public function getResultRowObject($returnColumns = null, $omitColumns = null){
// If no data is set, return false:
if (!$this->_data) {
return false;
}

return $this->_data;
}
}

?>


Copyright © 2018 programadorfreelanceargentina.com

Programador Freelance Argentina