Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Ws security #9

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@ Installation

The recommended way to install goetas-webservices / soap-client is using [Composer](https://getcomposer.org/):

Add this packages to your `composer.json` file.

```
{
"require": {
"goetas-webservices/soap-client": "^0.2",
},
"require-dev": {
"goetas-webservices/wsdl2php": "^0.3",
},
}
composer require goetas-webservices/soap-client
composer require goetas-webservices/wsdl2php --dev

# to use WS Security
composer require ass/xmlsecurity
```

More dependencies might be needed depending on your PSR-7 and HTTP client preferred implementation.
Expand All @@ -65,7 +61,7 @@ Here is an example:
# config.yml

soap_client:
alternative_endpoints:
alternative_endpoints: # optional
MyServiceName:
MySoapPortName: http://localhost:8080/service

Expand All @@ -75,7 +71,7 @@ soap_client:
'TestNs/MyApp': soap/src
destinations_jms:
'TestNs/MyApp': soap/metadata
aliases:
aliases: # optional
'http://www.example.org/test/':
MyCustomXSDType: 'MyCustomMappedPHPType'

Expand Down
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@
"require-dev": {
"phpunit/phpunit": "^4.8|^5.0",

"goetas-webservices/wsdl2php": "^0.3",
"goetas-webservices/wsdl2php": "^0.4",
"goetas-webservices/xsd2php": "^0.2.3",

"jms/serializer": "dev-xml-namespaces-improvements as 1.5.0",

"goetas-webservices/wsdl-reader": "^v0.3.1",

"ass/xmlsecurity" : "^1.0",
"php-http/guzzle6-adapter": "^1.0",
"php-http/message": "^1.0"
},
"suggest": {
"ass/xmlsecurity" : "Required for WS Security features"
},
"autoload": {
"psr-4": {
"GoetasWebservices\\SoapServices\\SoapClient\\": "src"
Expand Down
14 changes: 8 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>

<filter>
<whitelist>
<directory>src</directory>
<exclude>
<directory>src/WssWsSecurity/XmlSign</directory>
</exclude>
</whitelist>
</filter>
</phpunit>


13 changes: 2 additions & 11 deletions src/Arguments/Headers/Handler/HeaderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
use JMS\Serializer\SerializationContext;
use JMS\Serializer\XmlDeserializationVisitor;
use JMS\Serializer\XmlSerializationVisitor;
use Symfony\Component\DependencyInjection\SimpleXMLElement;

class HeaderHandler implements SubscribingHandlerInterface
{
const SOAP = 'http://schemas.xmlsoap.org/soap/envelope/';
const SOAP_12 = 'http://www.w3.org/2003/05/soap-envelope';

protected $headerData = [];

public static function getSubscribingMethods()
Expand Down Expand Up @@ -67,7 +63,7 @@ public function serializeHeader(XmlSerializationVisitor $visitor, HeaderPlacehol

$metadata = new StaticPropertyMetadata($classMetadata->name, $classMetadata->xmlRootName, $header->getData());
$metadata->xmlNamespace = $classMetadata->xmlRootNamespace;
$metadata->serializedName = $classMetadata->xmlRootName;
$metadata->serializedName = $classMetadata->xmlRootName ?: 'header';

$visitor->visitProperty($metadata, $header->getData(), $context);

Expand All @@ -88,12 +84,7 @@ private function handleOptions(XmlSerializationVisitor $visitor, $header)
foreach ($options as $option => $value) {
if (in_array($option, ['mustUnderstand', 'required', 'role', 'actor'])) {

if ($currentNode->ownerDocument->documentElement->namespaceURI === self::SOAP_12) {
$envelopeNS = self::SOAP_12;
} else {
$envelopeNS = self::SOAP;
}
$this->setAttributeOnNode($currentNode->lastChild, $option, $value, $envelopeNS);
$this->setAttributeOnNode($currentNode->lastChild, $option, $value, $currentNode->ownerDocument->documentElement->namespaceURI);
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ public function getConfigTreeBuilder()
->prototype('scalar')->end()
->end()


->scalarNode('any_element')
->defaultValue(false)
->end()
->scalarNode('any_attribute')
->defaultValue(false)
->end()



Expand Down
9 changes: 9 additions & 0 deletions src/DependencyInjection/SoapClientExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public function load(array $configs, ContainerBuilder $container)


foreach (['php', 'jms'] as $type) {

$converter = $container->getDefinition('goetas_webservices.xsd2php.converter.' . $type);

$converterWsdl = $container->getDefinition('goetas_webservices.wsdl2php.converter.' . $type);

foreach ($config['namespaces'] as $xml => $php) {
$converter->addMethodCall('addNamespace', [$xml, self::sanitizePhp($php)]);
}
Expand All @@ -53,6 +57,11 @@ public function load(array $configs, ContainerBuilder $container)
}
}

$schemaReader = $container->getDefinition('goetas_webservices.xsd2php.schema_reader');
foreach ($config['known_locations'] as $namespace => $location) {
$schemaReader->addMethodCall('addKnownSchemaLocation', [$namespace, $location]);
}


$definition = $container->getDefinition('goetas_webservices.xsd2php.naming_convention.' . $config['naming_strategy']);
$container->setDefinition('goetas_webservices.xsd2php.naming_convention', $definition);
Expand Down
9 changes: 9 additions & 0 deletions src/WssWsSecurity/Exception/ClientException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace GoetasWebservices\SoapServices\SoapClient\WssWsSecurity\Exception;

use GoetasWebservices\SoapServices\SoapClient\Exception\ClientException as BaseException;

class ClientException extends BaseException
{
}
81 changes: 81 additions & 0 deletions src/WssWsSecurity/Security.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace GoetasWebservices\SoapServices\SoapClient\WssWsSecurity;

class Security
{
/**
* (UT 3.1) Password type: plain text.
*/
const PASSWORD_TYPE_TEXT = 0;

/**
* (UT 3.1) Password type: digest.
*/
const PASSWORD_TYPE_DIGEST = 1;

/**
* (UT 3.1) Password.
*
* @var string
*/
protected $password;

/**
* (UT 3.1) Password type: text or digest.
*
* @var int
*/
protected $passwordType = self::PASSWORD_TYPE_DIGEST;

/**
* (UT 3.1) Username.
*
* @var string
*/
protected $username;

/**
* @return string
*/
public function getPassword()
{
return $this->password;
}

/**
* @param string $password
* @param int $passwordType
*/
public function setPassword($password, $passwordType = self::PASSWORD_TYPE_DIGEST)
{
$this->password = $password;
$this->passwordType = $passwordType;
}

public function isPasswordDigest()
{
return $this->passwordType === self::PASSWORD_TYPE_DIGEST;
}

public function isPasswordPlain()
{
return $this->passwordType === self::PASSWORD_TYPE_TEXT;
}

/**
* @return string
*/
public function getUsername()
{
return $this->username;
}

/**
* @param string $username
*/
public function setUsername($username)
{
$this->username = $username;
}
}
101 changes: 101 additions & 0 deletions src/WssWsSecurity/SecurityKeyPair.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

namespace GoetasWebservices\SoapServices\SoapClient\WssWsSecurity;

use ass\XmlSecurity\Key as XmlSecurityKey;

class SecurityKeyPair
{
/**
* Private key.
*
* @var \ass\XmlSecurity\Key
*/
private $privateKey = null;

/**
* Public key.
*
* @var \ass\XmlSecurity\Key
*/
private $publicKey = null;

/**
* Add private key.
*
* @param string $encryptionType Encryption type
* @param string $key Private key
* @param boolean $keyIsFile Given key parameter is path to key file
* @param string $passphrase Passphrase for key
*
* @return void
*/
public function setPrivateKey($encryptionType, $key = null, $keyIsFile = true, $passphrase = null)
{
$this->privateKey = XmlSecurityKey::factory($encryptionType, $key, $keyIsFile, XmlSecurityKey::TYPE_PRIVATE, $passphrase);
}

/**
* Add public key.
*
* @param string $encryptionType Encryption type
* @param string $key Public key
* @param boolean $keyIsFile Given key parameter is path to key file
*
* @return void
*/
public function setPublicKey($encryptionType, $key = null, $keyIsFile = true)
{
$this->publicKey = XmlSecurityKey::factory($encryptionType, $key, $keyIsFile, XmlSecurityKey::TYPE_PUBLIC);
}

/**
* Get private key.
*
* @return \ass\XmlSecurity\Key
*/
public function getPrivateKey()
{
return $this->privateKey;
}

/**
* Get public key.
*
* @return \ass\XmlSecurity\Key
*/
public function getPublicKey()
{
return $this->publicKey;
}

/**
* Has private and public key?
*
* @return boolean
*/
public function hasKeys()
{
return null !== $this->privateKey && null !== $this->publicKey;
}

/**
* Has private key?
*
* @return boolean
*/
public function hasPrivateKey()
{
return null !== $this->privateKey;
}

/**
* Has public key?
*
* @return boolean
*/
public function hasPublicKey()
{
return null !== $this->publicKey;
}
}
Loading