| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the AMFWebServicesClientBundle package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) Amine Fattouch <http://github.com/fattouchsquall> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace AMF\WebServicesClientBundle\Soap\Security; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * Add security wsse layer to soap webservices. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @author Mohamed Amine Fattouch <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | class Wsse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     protected $username; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     protected $password; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * The constructor class. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @param string $username The username of wsse security. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @param string $password The password of wsse security. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 37 | 6 |  |     public function __construct($username, $password) | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 39 | 6 |  |         $this->username = $username; | 
            
                                                                        
                            
            
                                    
            
            
                | 40 | 6 |  |         $this->password = $password; | 
            
                                                                        
                            
            
                                    
            
            
                | 41 | 6 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * Generates WSSE header for SOAP. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @return \SoapHeader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 6 |  |     public function generateHeader() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 6 |  |         if (isset($this->username) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 6 |  |                 && strlen($this->username) > 0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 6 |  |                 && isset($this->password) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 6 |  |                 && strlen($this->password) > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 3 |  |             $xsdNamespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 3 |  |             $usernameSoapVar  = new \SoapVar( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 3 |  |                 $this->username, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 3 |  |                 XSD_STRING, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 3 |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 3 |  |                 $xsdNamespace, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 3 |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 $xsdNamespace | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 3 |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 3 |  |             $passwordSoapVar  = new \SoapVar( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 3 |  |                 $this->password, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 3 |  |                 XSD_STRING, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 3 |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 3 |  |                 $xsdNamespace, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 3 |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                 $xsdNamespace | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 3 |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 3 |  |             $wsseAuth         = new WsseAuth($usernameSoapVar, $passwordSoapVar); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 3 |  |             $wsseAuthSoapVar  = new \SoapVar( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 3 |  |                 $wsseAuth, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 3 |  |                 SOAP_ENC_OBJECT, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 3 |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 3 |  |                 $xsdNamespace, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 3 |  |                 'UsernameToken', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                 $xsdNamespace | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 3 |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 3 |  |             $wsseToken        = new WsseToken($wsseAuthSoapVar); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 3 |  |             $wsseTokenSoapVar = new \SoapVar( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 3 |  |                 $wsseToken, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 3 |  |                 SOAP_ENC_OBJECT, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 3 |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 3 |  |                 $xsdNamespace, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 3 |  |                 'UsernameToken', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                 $xsdNamespace | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 3 |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 3 |  |             $secHeaderValue   = new \SoapVar( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 3 |  |                 $wsseTokenSoapVar, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 3 |  |                 SOAP_ENC_OBJECT, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 3 |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 3 |  |                 $xsdNamespace, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 3 |  |                 'Security', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                 $xsdNamespace | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 3 |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 3 |  |             return new \SoapHeader($xsdNamespace, 'Security', $secHeaderValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 3 |  |         throw new \Exception('Username and password cannot be empty'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 104 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 105 |  |  |  | 
            
                        
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: