1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the LightSAML-Core package. |
5
|
|
|
* |
6
|
|
|
* (c) Milos Tomic <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace LightSaml\Binding; |
13
|
|
|
|
14
|
|
|
use LightSaml\Context\Profile\Helper\MessageContextHelper; |
15
|
|
|
use LightSaml\Context\Profile\MessageContext; |
16
|
|
|
use LightSaml\Error\LightSamlBindingException; |
17
|
|
|
use LightSaml\Model\Protocol\AbstractRequest; |
18
|
|
|
use LightSaml\Model\Protocol\SamlMessage; |
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
20
|
|
|
|
21
|
|
|
class HttpPostBinding extends AbstractBinding |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @param MessageContext $context |
25
|
|
|
* @param null|string $destination |
26
|
|
|
* |
27
|
|
|
* @return SamlPostResponse |
28
|
|
|
*/ |
29
|
4 |
|
public function send(MessageContext $context, $destination = null) |
30
|
|
|
{ |
31
|
4 |
|
$message = MessageContextHelper::asSamlMessage($context); |
32
|
4 |
|
$destination = $message->getDestination() ? $message->getDestination() : $destination; |
33
|
|
|
|
34
|
4 |
|
$serializationContext = $context->getSerializationContext(); |
35
|
4 |
|
$message->serialize($serializationContext->getDocument(), $serializationContext); |
|
|
|
|
36
|
4 |
|
$msgStr = $serializationContext->getDocument()->saveXML(); |
|
|
|
|
37
|
|
|
|
38
|
4 |
|
$this->dispatchSend($msgStr); |
39
|
|
|
|
40
|
4 |
|
$msgStr = base64_encode($msgStr); |
41
|
|
|
|
42
|
4 |
|
$type = $message instanceof AbstractRequest ? 'SAMLRequest' : 'SAMLResponse'; |
43
|
|
|
|
44
|
4 |
|
$data = array($type => $msgStr); |
45
|
4 |
|
if ($message->getRelayState()) { |
|
|
|
|
46
|
2 |
|
$data['RelayState'] = $message->getRelayState(); |
47
|
|
|
} |
48
|
|
|
|
49
|
4 |
|
$result = new SamlPostResponse($destination, $data); |
50
|
4 |
|
$result->renderContent(); |
51
|
|
|
|
52
|
4 |
|
return $result; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param Request $request |
57
|
|
|
* @param MessageContext $context |
58
|
|
|
*/ |
59
|
3 |
|
public function receive(Request $request, MessageContext $context) |
60
|
|
|
{ |
61
|
3 |
|
$post = $request->request->all(); |
62
|
3 |
|
if (array_key_exists('SAMLRequest', $post)) { |
63
|
1 |
|
$msg = $post['SAMLRequest']; |
64
|
2 |
|
} elseif (array_key_exists('SAMLResponse', $post)) { |
65
|
1 |
|
$msg = $post['SAMLResponse']; |
66
|
|
|
} else { |
67
|
1 |
|
throw new LightSamlBindingException('Missing SAMLRequest or SAMLResponse parameter'); |
68
|
|
|
} |
69
|
|
|
|
70
|
2 |
|
$msg = base64_decode($msg); |
71
|
|
|
|
72
|
2 |
|
$this->dispatchReceive($msg); |
73
|
|
|
|
74
|
2 |
|
$deserializationContext = $context->getDeserializationContext(); |
75
|
2 |
|
$result = SamlMessage::fromXML($msg, $deserializationContext); |
|
|
|
|
76
|
|
|
|
77
|
2 |
|
if (array_key_exists('RelayState', $post)) { |
78
|
1 |
|
$result->setRelayState($post['RelayState']); |
79
|
|
|
} |
80
|
|
|
|
81
|
2 |
|
$context->setMessage($result); |
82
|
2 |
|
} |
83
|
|
|
} |
84
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.