我正在尝试通过 SOAP webservice 实现自定义身份验证
根据参考链接
http://it-cook-de.blogspot.in/2013/07/zend-framework-2-custom-authentication-with-soap-webservice-part-1.html http://samsonasik.wordpress.com/2012 /10/23/zend-framework-2-create-login-authentication-using-authenticationservice-with-rememberme/#comment-6117
现在得到错误
代码 :
<?php
namespace Application\Adapter;
use Zend\Authentication\Adapter\AdapterInterface;
use Zend\Authentication\Result;
use Zend\Soap\Client;
use Zend\Soap\Client\DotNet as DotNet;
class SoapAuthenticationAdapter implements AdapterInterface
{
//:TODO: move to configuration
//private $module = 'my_application_name_in_auth_system';
private $module = 'student';
//:TODO: move to configuration
// private $uri = 'full_url_to_soap_webservice_of_auth_system';
private $uri = 'http://ip/Service/student.svc?wsdl';
//:TODO: move to configuration
//private $location = 'full_url_to_soap_webservice_of_auth_system';
private $location = 'http://ip/Service/student.svc?wsdl';
protected $username;
protected $password;
protected $customercode;
function __construct()
{
}
public function authenticate()
{
$client = new DotNet($this->uri);
$param=array("customercode"=>$this->customercode,"username"=>$this->username,"password"=>$this->password);
$result = $client->call('ValidateUser',array($param));
if ($result) {
$this->permissions = $param;
return $this->getResult(Result::SUCCESS, $this->permissions, 'SUCCESS');
} else {
return $this->getResult(Result::FAILURE_CREDENTIAL_INVALID, null, 'FAILURE_CREDENTIAL_INVALID');
}
} catch (\SoapFault $e) {
// switch ($e->getMessage()) {
return $this->getResult(Result::FAILURE_UNCATEGORIZED, null, $e->getMessage());
// }
}
}
public function setIdentity($username)
{
$this->username = $username;
}
public function setCredential($password)
{
$this->password = $password;
}
public function setCustomerCode($customercode)
{
$this->customercode =$customercode;
}
private function getResult($type, $identity, $message)
{
return new Result($type, $identity, array(
$message
));
}
}
/////In IndexController
public function getAuthService()
{
if (! $this->authservice) {
$this->authservice = $this->getServiceLocator()
->get('SoapAuthenticationService');
}
return $this->authservice;
}
public function someAction()
{
$request = $this->getRequest();
if ($request->isPost()){
$this->getAuthService()->getAdapter()
->setIdentity($request->getPost('username'))
->setCredential($request->getPost('password'))
->setCustomerCode($request->getPost('customercode'));
$result = $this->getAuthService()->authenticate();
foreach($result->getMessages() as $message)
{
//save message temporary into flashmessenger
$this->flashmessenger()->addMessage($message);
}
if ($result->isValid()) {
$redirect = 'home';
//check if it has rememberMe :
if ($request->getPost('rememberme') == 1 ) {
$this->getSessionStorage()
->setRememberMe(1);
//set storage again
$this->getAuthService()->setStorage($this->getSessionStorage());
}
$this->getAuthService()->setStorage($this->getSessionStorage());
$this->getAuthService()->getStorage()->write($request->getPost('username'));
}
else
{
$redirect ='login';
}
return $this->redirect()->toRoute($redirect);
}
在模块.php
public function getServiceConfig()
{
return array(
'factories' => array(
//Add the following lines
'Application\Model\SoapAuthenticationStorage' => function($sm){
return new SoapAuthenticationStorage('student');
},
'SoapAuthenticationService' => function($sm) {
$authAdapter = new SoapAuthenticationAdapter();
$authService = new AuthenticationService();
$authService->setAdapter($authAdapter);
$authService->setStorage($sm->get('Application\Model\SoapAuthenticationStorage'));
return $authService;
}
)
);
}
任何帮助解决这个问题