Example #1
0
 public function attachTokentoSig($token)
 {
     if (!$token instanceof DOMElement) {
         throw new Exception('Invalid parameter: BinarySecurityToken element expected');
     }
     $objXMLSecDSig = new XMLSecurityDSig();
     if ($objDSig = $objXMLSecDSig->locateSignature($this->soapDoc)) {
         $tokenURI = '#' . $token->getAttributeNS(WSSESoap::WSUNS, "Id");
         $this->SOAPXPath->registerNamespace('secdsig', XMLSecurityDSig::XMLDSIGNS);
         $query = "./secdsig:KeyInfo";
         $nodeset = $this->SOAPXPath->query($query, $objDSig);
         $keyInfo = $nodeset->item(0);
         if (!$keyInfo) {
             $keyInfo = $objXMLSecDSig->createNewSignNode('KeyInfo');
             $objDSig->appendChild($keyInfo);
         }
         $tokenRef = $this->soapDoc->createElementNS(WSSESoap::WSSENS, WSSESoap::WSSEPFX . ':SecurityTokenReference');
         $keyInfo->appendChild($tokenRef);
         $reference = $this->soapDoc->createElementNS(WSSESoap::WSSENS, WSSESoap::WSSEPFX . ':Reference');
         $reference->setAttribute('ValueType', $token->getAttribute('ValueType'));
         $reference->setAttribute("URI", $tokenURI);
         $tokenRef->appendChild($reference);
     } else {
         throw new Exception('Unable to locate digital signature');
     }
 }