_tokenService)) {
// if login method we addWsseLoginHeader
if (in_array('login', $arguments)) {
$this->addWsseLoginHeader();
} elseif ($name == 'getTokens') {
$this->addWsseTokenHeader($this->_tokenService->getLoginToken());
} else {
$this->addWsseSecurityTokenHeader($this->_tokenService->getTokens());
}
}
return parent::__call($name, $arguments);
}
/**
* sets the internal handling for handle token service
*
* @param Zend_Service_DeveloperGarden_SecurityTokenServer $isTokenService
* @return Zend_Service_DeveloperGarden_Client_Soap
*/
public function setTokenService(Zend_Service_DeveloperGarden_SecurityTokenServer $tokenService)
{
$this->_tokenService = $tokenService;
return $this;
}
/**
* returns the currently configured tokenService object
*
* @return Zend_Service_DeveloperGarden_SecurityTokenServer
*/
public function getTokenService()
{
return $this->_tokenService;
}
/**
* Sets new credential callback object
*
* @param Zend_Service_DeveloperGarden_Credential $credential
* @return Zend_Service_DeveloperGarden_Client_Soap
*/
public function setCredential(Zend_Service_DeveloperGarden_Credential $credential)
{
$this->_credential = $credential;
return $this;
}
/**
* returns the internal credential callback object
*
* @return Zend_Service_DeveloperGarden_Credential
*/
public function getCredential()
{
return $this->_credential;
}
/**
* creates the login header and add
*
* @return SoapHeader
*/
public function getWsseLoginHeader()
{
$dom = new DOMDocument();
/**
* Security Element
*/
$securityElement = $dom->createElementNS(
self::WSSE_NAMESPACE_SECEXT,
'wsse:' . self::WSSE_SECURITY_ELEMENT
);
$securityElement->setAttribute('mustUnderstand', true);
/**
* Username Token Element
*/
$usernameTokenElement = $dom->createElementNS(
self::WSSE_NAMESPACE_SECEXT,
self::WSSE_ELEMENT_USERNAMETOKEN
);
/**
* Username Element
*/
$usernameElement = $dom->createElementNS(
self::WSSE_NAMESPACE_SECEXT,
self::WSSE_ELEMENT_USERNAME,
$this->_credential->getUsername(true)
);
/**
* Password Element
*/
$passwordElement = $dom->createElementNS(
self::WSSE_NAMESPACE_SECEXT,
self::WSSE_ELEMENT_PASSWORD,
$this->_credential->getPassword()
);
$passwordElement->setAttribute('Type', self::WSSE_ELEMENT_PASSWORD_TYPE);
$usernameTokenElement->appendChild($usernameElement);
$usernameTokenElement->appendChild($passwordElement);
$securityElement->appendChild($usernameTokenElement);
$dom->appendChild($securityElement);
$authSoapVar = new SoapVar(
$dom->saveXML($securityElement),
XSD_ANYXML,
self::WSSE_NAMESPACE_SECEXT,
self::WSSE_SECURITY_ELEMENT
);
$authSoapHeader = new SoapHeader(
self::WSSE_NAMESPACE_SECEXT,
self::WSSE_SECURITY_ELEMENT,
$authSoapVar,
true
);
return $authSoapHeader;
}
/**
* creates the token auth header for direct calls
*
* @param Zend_Service_DeveloperGarden_Response_SecurityTokenServer_SecurityTokenResponse $token
* @return SoapHeader
*/
public function getWsseTokenHeader(
Zend_Service_DeveloperGarden_Response_SecurityTokenServer_SecurityTokenResponse $token
) {
$format = '%s';
$securityHeader = sprintf(
$format,
self::WSSE_SECURITY_ELEMENT,
self::WSSE_NAMESPACE_SECEXT,
$token->getTokenData(),
self::WSSE_SECURITY_ELEMENT
);
$authSoapVar = new SoapVar(
$securityHeader,
XSD_ANYXML,
self::WSSE_NAMESPACE_SECEXT,
self::WSSE_SECURITY_ELEMENT
);
$authSoapHeader = new SoapHeader(
self::WSSE_NAMESPACE_SECEXT,
self::WSSE_SECURITY_ELEMENT,
$authSoapVar,
true
);
return $authSoapHeader;
}
/**
* creates the security token auth header for direct calls
*
* @param Zend_Service_DeveloperGarden_Response_SecurityTokenServer_SecurityTokenResponse $token
* @return SoapHeader
*/
public function getWsseSecurityTokenHeader(
Zend_Service_DeveloperGarden_Response_SecurityTokenServer_GetTokensResponse $token
) {
$format = '%s';
$securityHeader = sprintf(
$format,
self::WSSE_SECURITY_ELEMENT,
self::WSSE_NAMESPACE_SECEXT,
$token->getTokenData(),
self::WSSE_SECURITY_ELEMENT
);
$authSoapVar = new SoapVar(
$securityHeader,
XSD_ANYXML,
self::WSSE_NAMESPACE_SECEXT,
self::WSSE_SECURITY_ELEMENT
);
$authSoapHeader = new SoapHeader(
self::WSSE_NAMESPACE_SECEXT,
self::WSSE_SECURITY_ELEMENT,
$authSoapVar,
true
);
return $authSoapHeader;
}
/**
* adds the login specific header to the client
*
* @return Zend_Service_DeveloperGarden_Client_Soap
*/
public function addWsseLoginHeader()
{
return $this->addSoapInputHeader($this->getWsseLoginHeader());
}
/**
* adds the earlier fetched token to the header
*
* @param Zend_Service_DeveloperGarden_Response_SecurityTokenServer_SecurityTokenResponse $token
* @return Zend_Service_DeveloperGarden_Client_Soap
*/
public function addWsseTokenHeader(
Zend_Service_DeveloperGarden_Response_SecurityTokenServer_SecurityTokenResponse $token
) {
return $this->addSoapInputHeader($this->getWsseTokenHeader($token));
}
/**
* adds the earlier fetched token to the header
*
* @param Zend_Service_DeveloperGarden_Response_SecurityTokenServer_SecurityTokenResponse $token
* @return Zend_Service_DeveloperGarden_Client_Soap
*/
public function addWsseSecurityTokenHeader(
Zend_Service_DeveloperGarden_Response_SecurityTokenServer_GetTokensResponse $token
) {
return $this->addSoapInputHeader($this->getWsseSecurityTokenHeader($token));
}
}