Skip to content

Commit 5bcf680

Browse files
author
Milos Tomic
committed
binding request from globals & serialization assertion ns & saml message destination optional
Conflicts: src/AerialShip/LightSaml/Model/Assertion/SubjectConfirmation.php src/AerialShip/LightSaml/Model/Assertion/SubjectConfirmationData.php
1 parent fede0be commit 5bcf680

File tree

6 files changed

+54
-25
lines changed

6 files changed

+54
-25
lines changed

src/AerialShip/LightSaml/Binding/Request.php

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,81 +20,107 @@ class Request
2020
/** @var array */
2121
protected $post;
2222

23+
/**
24+
* @return Request
25+
*/
26+
public static function fromGlobals()
27+
{
28+
$result = new Request();
29+
$result->setContentType($_SERVER['CONTENT_TYPE']);
30+
$result->setGet($_GET);
31+
$result->setPost($_POST);
32+
$result->setQueryString($_SERVER['QUERY_STRING']);
33+
$result->setRequestMethod($_SERVER['REQUEST_METHOD']);
34+
35+
return $result;
36+
}
37+
2338
/**
2439
* @param string $contentType
2540
*/
26-
public function setContentType($contentType) {
41+
public function setContentType($contentType)
42+
{
2743
$this->contentType = $contentType;
2844
}
2945

3046
/**
3147
* @return string
3248
*/
33-
public function getContentType() {
49+
public function getContentType()
50+
{
3451
return $this->contentType;
3552
}
3653

3754
/**
3855
* @param array $get
3956
*/
40-
public function setGet($get) {
57+
public function setGet($get)
58+
{
4159
$this->get = $get;
4260
}
4361

4462
/**
4563
* @return array
4664
*/
47-
public function getGet() {
65+
public function getGet()
66+
{
4867
return $this->get;
4968
}
5069

5170
/**
5271
* @param array $post
5372
*/
54-
public function setPost($post) {
73+
public function setPost($post)
74+
{
5575
$this->post = $post;
5676
}
5777

5878
/**
5979
* @return array
6080
*/
61-
public function getPost() {
81+
public function getPost()
82+
{
6283
return $this->post;
6384
}
6485

6586
/**
6687
* @param string $queryString
6788
*/
68-
public function setQueryString($queryString) {
89+
public function setQueryString($queryString)
90+
{
6991
$this->queryString = $queryString;
7092
}
7193

7294
/**
7395
* @return string
7496
*/
75-
public function getQueryString() {
97+
public function getQueryString()
98+
{
7699
return $this->queryString;
77100
}
78101

79102
/**
80103
* @param string $requestMethod
81104
*/
82-
public function setRequestMethod($requestMethod) {
105+
public function setRequestMethod($requestMethod)
106+
{
83107
$this->requestMethod = $requestMethod;
84108
}
85109

86110
/**
87111
* @return string
88112
*/
89-
public function getRequestMethod() {
113+
public function getRequestMethod()
114+
{
90115
return $this->requestMethod;
91116
}
92117

93118

94119

95120

96121

97-
function parseQueryString($queryString = null, $urlDecodeValues = false) {
122+
public function parseQueryString($queryString = null, $urlDecodeValues = false)
123+
{
98124
if ($queryString) {
99125
$this->queryString = $queryString;
100126
}
@@ -109,4 +135,4 @@ function parseQueryString($queryString = null, $urlDecodeValues = false) {
109135
return $result;
110136
}
111137

112-
}
138+
}

src/AerialShip/LightSaml/Model/Assertion/Assertion.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,12 @@ function getXml(\DOMNode $parent, SerializationContext $context) {
292292
$result->setAttribute('Version', $this->getVersion());
293293
$result->setAttribute('IssueInstant', Helper::time2string($this->getIssueInstant()));
294294

295-
$issuerNode = $context->getDocument()->createElement('Issuer', $this->getIssuer());
295+
$issuerNode = $context->getDocument()->createElementNS(Protocol::NS_ASSERTION, 'saml:Issuer', $this->getIssuer());
296296
$result->appendChild($issuerNode);
297297

298298
$this->getSubject()->getXml($result, $context);
299299

300-
$conditionsNode = $context->getDocument()->createElement('Conditions');
300+
$conditionsNode = $context->getDocument()->createElementNS(Protocol::NS_ASSERTION, 'saml:Conditions');
301301
$result->appendChild($conditionsNode);
302302
$conditionsNode->setAttribute('NotBefore', Helper::time2string($this->getNotBefore()));
303303
$conditionsNode->setAttribute('NotOnOrAfter', Helper::time2string($this->getNotOnOrAfter()));
@@ -310,7 +310,7 @@ function getXml(\DOMNode $parent, SerializationContext $context) {
310310
}
311311
}
312312

313-
$attributeStatementNode = $context->getDocument()->createElement('AttributeStatement');
313+
$attributeStatementNode = $context->getDocument()->createElementNS(Protocol::NS_ASSERTION, 'saml:AttributeStatement');
314314
$result->appendChild($attributeStatementNode);
315315
foreach ($this->getAllAttributes() as $attribute) {
316316
$attribute->getXml($attributeStatementNode, $context);

src/AerialShip/LightSaml/Model/Assertion/Attribute.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function getFirstValue()
127127
*/
128128
public function getXml(\DOMNode $parent, SerializationContext $context)
129129
{
130-
$result = $context->getDocument()->createElement('Attribute');
130+
$result = $context->getDocument()->createElementNS(Protocol::NS_ASSERTION, 'saml:Attribute');
131131
$parent->appendChild($result);
132132

133133
$result->setAttribute('Name', $this->getName());
@@ -139,7 +139,7 @@ public function getXml(\DOMNode $parent, SerializationContext $context)
139139
}
140140

141141
foreach ($this->getValues() as $v) {
142-
$valueNode = $context->getDocument()->createElement('AttributeValue', $v);
142+
$valueNode = $context->getDocument()->createElementNS(Protocol::NS_ASSERTION, 'saml:AttributeValue', $v);
143143
$result->appendChild($valueNode);
144144
}
145145

src/AerialShip/LightSaml/Model/Assertion/AuthnStatement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ function getXml(\DOMNode $parent, SerializationContext $context) {
9999
$result->setAttribute('SessionIndex', $this->getSessionIndex());
100100
}
101101

102-
$authnContextNode = $context->getDocument()->createElement('AuthnContext');
102+
$authnContextNode = $context->getDocument()->createElementNS(Protocol::NS_ASSERTION, 'saml:AuthnContext');
103103
$result->appendChild($authnContextNode);
104-
$refNode = $context->getDocument()->createElement('AuthnContextClassRef', $this->getAuthnContext());
104+
$refNode = $context->getDocument()->createElementNS(Protocol::NS_ASSERTION, 'saml:AuthnContextClassRef', $this->getAuthnContext());
105105
$authnContextNode->appendChild($refNode);
106106

107107
return $result;

src/AerialShip/LightSaml/Model/Protocol/Message.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,6 @@ protected function prepareForXml()
241241
if (!$this->getIssueInstant()) {
242242
$this->setIssueInstant(time());
243243
}
244-
if (!$this->getDestination()) {
245-
throw new InvalidMessageException('Destination not set');
246-
}
247244
if (!$this->getIssuer()) {
248245
throw new InvalidMessageException('Issuer not set');
249246
}
@@ -269,7 +266,9 @@ public function getXml(\DOMNode $parent, SerializationContext $context)
269266
$result->setAttribute('ID', $this->getID());
270267
$result->setAttribute('Version', $this->getVersion());
271268
$result->setAttribute('IssueInstant', Helper::time2string($this->getIssueInstant()));
272-
$result->setAttribute('Destination', $this->getDestination());
269+
if ($this->getDestination()) {
270+
$result->setAttribute('Destination', $this->getDestination());
271+
}
273272

274273
$issuerNode = $context->getDocument()->createElementNS(Protocol::NS_ASSERTION, 'saml:Issuer', $this->getIssuer());
275274
$result->appendChild($issuerNode);
@@ -304,7 +303,11 @@ public function getSignedXml(\DOMNode $parent, SerializationContext $context)
304303
*/
305304
public function loadFromXml(\DOMElement $xml)
306305
{
307-
if ($xml->localName != $this->getXmlNodeLocalName()) {
306+
$name = $this->getXmlNodeLocalName();
307+
if (($pos = strpos($name, ':')) !== false) {
308+
$name = substr($name, $pos+1);
309+
}
310+
if ($xml->localName != $name) {
308311
throw new InvalidXmlException('Expected '.$this->getXmlNodeLocalName().' node but got '.$xml->localName);
309312
}
310313
if ($this->getXmlNodeNamespace() && $xml->namespaceURI != $this->getXmlNodeNamespace()) {

src/AerialShip/LightSaml/Model/Protocol/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Response extends StatusResponse
1919
* @return string
2020
*/
2121
function getXmlNodeLocalName() {
22-
return 'Response';
22+
return 'samlp:Response';
2323
}
2424

2525
/**

0 commit comments

Comments
 (0)