|
1
|
|
|
<?php |
|
2
|
|
|
namespace GoetasWebservices\SoapServices\SoapClient\WssWsSecurity; |
|
3
|
|
|
|
|
4
|
|
|
use GoetasWebservices\SoapServices\SoapClient\WssWsSecurity\Secext\Security as SecextSecurity; |
|
5
|
|
|
use GoetasWebservices\SoapServices\SoapClient\WssWsSecurity\Secext\UsernameToken; |
|
6
|
|
|
use GoetasWebservices\SoapServices\SoapClient\WssWsSecurity\Utility\Timestamp; |
|
7
|
|
|
use JMS\Serializer\EventDispatcher\EventSubscriberInterface; |
|
8
|
|
|
use JMS\Serializer\EventDispatcher\ObjectEvent; |
|
9
|
|
|
use JMS\Serializer\Metadata\ClassMetadata; |
|
10
|
|
|
use JMS\Serializer\Metadata\StaticPropertyMetadata; |
|
11
|
|
|
|
|
12
|
|
|
class WssSecurityHeaderEventHandler implements EventSubscriberInterface |
|
13
|
|
|
{ |
|
14
|
|
|
const WSS_UTP = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0'; |
|
15
|
|
|
const DATETIME_FORMAT = 'Y-m-d\TH:i:s.000\Z'; |
|
16
|
|
|
|
|
17
|
|
|
protected $headerData = []; |
|
18
|
|
|
|
|
19
|
|
|
public static function getSubscribedEvents() |
|
20
|
|
|
{ |
|
21
|
|
|
return array( |
|
22
|
|
|
array( |
|
23
|
|
|
'event' => 'serializer.post_serialize', |
|
24
|
|
|
'method' => 'serializeAnyElement', |
|
25
|
|
|
'class' => SecextSecurity::class, |
|
26
|
|
|
'format' => 'xml' |
|
27
|
|
|
), |
|
28
|
|
|
array( |
|
29
|
|
|
'event' => 'serializer.post_serialize', |
|
30
|
|
|
'method' => 'serializeAnyElement', |
|
31
|
|
|
'class' => UsernameToken::class, |
|
32
|
|
|
'format' => 'xml' |
|
33
|
|
|
), |
|
34
|
|
|
array( |
|
35
|
|
|
'event' => 'serializer.post_serialize', |
|
36
|
|
|
'method' => 'serializeAnyElement', |
|
37
|
|
|
'class' => Timestamp::class, |
|
38
|
|
|
'format' => 'xml' |
|
39
|
|
|
), |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function serializeAnyElement(ObjectEvent $event) |
|
44
|
|
|
{ |
|
45
|
|
|
/** |
|
46
|
|
|
* @var $security SecextSecurity |
|
47
|
|
|
*/ |
|
48
|
|
|
$security = $event->getObject(); |
|
49
|
|
|
$items = $security->getAnyElement(); |
|
50
|
|
|
if (!count($items)) { |
|
51
|
|
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
$context = $event->getContext(); |
|
54
|
|
|
$visitor = $event->getVisitor(); |
|
55
|
|
|
$metadataFactory = $context->getMetadataFactory();; |
|
56
|
|
|
|
|
57
|
|
|
foreach ($items as $item) { |
|
58
|
|
|
/** |
|
59
|
|
|
* @var $itemMetadata ClassMetadata |
|
60
|
|
|
*/ |
|
61
|
|
|
$itemMetadata = $metadataFactory->getMetadataForClass(get_class($item)); |
|
62
|
|
|
|
|
63
|
|
|
$prop = new StaticPropertyMetadata(get_class($item), $itemMetadata->xmlRootName, $item); |
|
64
|
|
|
$prop->serializedName = $itemMetadata->xmlRootName; |
|
65
|
|
|
$prop->xmlNamespace = $itemMetadata->xmlRootNamespace; |
|
66
|
|
|
|
|
67
|
|
|
$visitor->visitProperty($prop, $item, $context); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|