Skip to content

Commit f9edc02

Browse files
committed
Merge
2 parents d9f9085 + 6f1e610 commit f9edc02

6 files changed

Lines changed: 48 additions & 13 deletions

File tree

src/Saml2/LogoutRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public function isValid($retrieveParametersFromServer = false)
368368
$security = $this->_settings->getSecurityData();
369369

370370
if ($security['wantXMLValidation']) {
371-
$res = Utils::validateXML($dom, 'saml-schema-protocol-2.0.xsd', $this->_settings->isDebugActive());
371+
$res = Utils::validateXML($dom, 'saml-schema-protocol-2.0.xsd', $this->_settings->isDebugActive(), $this->_settings->getSchemasPath());
372372
if (!$res instanceof DOMDocument) {
373373
throw new ValidationError(
374374
"Invalid SAML Logout Request. Not match the saml-schema-protocol-2.0.xsd",

src/Saml2/LogoutResponse.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class LogoutResponse
6868
*
6969
* @throws Error
7070
* @throws Exception
71-
*
7271
*/
7372
public function __construct(\OneLogin\Saml2\Settings $settings, $response = null)
7473
{
@@ -154,7 +153,7 @@ public function isValid($requestId = null, $retrieveParametersFromServer = false
154153
$security = $this->_settings->getSecurityData();
155154

156155
if ($security['wantXMLValidation']) {
157-
$res = Utils::validateXML($this->document, 'saml-schema-protocol-2.0.xsd', $this->_settings->isDebugActive());
156+
$res = Utils::validateXML($this->document, 'saml-schema-protocol-2.0.xsd', $this->_settings->isDebugActive(), $this->_settings->getSchemasPath());
158157
if (!$res instanceof DOMDocument) {
159158
throw new ValidationError(
160159
"Invalid SAML Logout Response. Not match the saml-schema-protocol-2.0.xsd",

src/Saml2/Response.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function isValid($requestId = null)
172172

173173
if ($security['wantXMLValidation']) {
174174
$errorXmlMsg = "Invalid SAML Response. Not match the saml-schema-protocol-2.0.xsd";
175-
$res = Utils::validateXML($this->document, 'saml-schema-protocol-2.0.xsd', $this->_settings->isDebugActive());
175+
$res = Utils::validateXML($this->document, 'saml-schema-protocol-2.0.xsd', $this->_settings->isDebugActive(), $this->_settings->getSchemasPath());
176176
if (!$res instanceof DOMDocument) {
177177
throw new ValidationError(
178178
$errorXmlMsg,
@@ -182,7 +182,7 @@ public function isValid($requestId = null)
182182

183183
// If encrypted, check also the decrypted document
184184
if ($this->encrypted) {
185-
$res = Utils::validateXML($this->decryptedDocument, 'saml-schema-protocol-2.0.xsd', $this->_settings->isDebugActive());
185+
$res = Utils::validateXML($this->decryptedDocument, 'saml-schema-protocol-2.0.xsd', $this->_settings->isDebugActive(), $this->_settings->getSchemasPath());
186186
if (!$res instanceof DOMDocument) {
187187
throw new ValidationError(
188188
$errorXmlMsg,

src/Saml2/Settings.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private function _loadPaths()
164164
'base' => $basePath,
165165
'config' => $basePath,
166166
'cert' => $basePath.'certs/',
167-
'lib' => $basePath.'src/'
167+
'lib' => $basePath.'src/Saml2/'
168168
);
169169

170170
if (defined('ONELOGIN_CUSTOMPATH')) {
@@ -220,9 +220,23 @@ public function getLibPath()
220220
*/
221221
public function getSchemasPath()
222222
{
223+
if (isset($this->_paths['schemas'])) {
224+
return $this->_paths['schemas'];
225+
}
223226
return $this->_paths['lib'].'schemas/';
224227
}
225228

229+
/**
230+
* Set schemas path
231+
*
232+
* @param string $path
233+
* @return $this
234+
*/
235+
public function setSchemasPath($path)
236+
{
237+
$this->_paths['schemas'] = $path;
238+
}
239+
226240
/**
227241
* Loads settings info from a settings Array
228242
*
@@ -934,7 +948,7 @@ public function validateMetadata($xml)
934948
assert(is_string($xml));
935949

936950
$errors = array();
937-
$res = Utils::validateXML($xml, 'saml-schema-metadata-2.0.xsd', $this->_debug);
951+
$res = Utils::validateXML($xml, 'saml-schema-metadata-2.0.xsd', $this->_debug, $this->getSchemasPath());
938952
if (!$res instanceof DOMDocument) {
939953
$errors[] = $res;
940954
} else {

src/Saml2/Utils.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,13 @@ public static function loadXML(DOMDocument $dom, $xml)
111111
* @param string|DOMDocument $xml The XML string or document which should be validated.
112112
* @param string $schema The schema filename which should be used.
113113
* @param bool $debug To disable/enable the debug mode
114+
* @param string $schemaPath Change schema path
114115
*
115116
* @return string|DOMDocument $dom string that explains the problem or the DOMDocument
116117
*
117118
* @throws Exception
118119
*/
119-
public static function validateXML($xml, $schema, $debug = false)
120+
public static function validateXML($xml, $schema, $debug = false, $schemaPath = null)
120121
{
121122
assert(is_string($xml) || $xml instanceof DOMDocument);
122123
assert(is_string($schema));
@@ -134,7 +135,12 @@ public static function validateXML($xml, $schema, $debug = false)
134135
}
135136
}
136137

137-
$schemaFile = __DIR__ . '/schemas/' . $schema;
138+
if (isset($schemaPath)) {
139+
$schemaFile = $schemaPath . $schema;
140+
} else {
141+
$schemaFile = __DIR__ . '/schemas/' . $schema;
142+
}
143+
138144
$oldEntityLoader = libxml_disable_entity_loader(false);
139145
$res = $dom->schemaValidate($schemaFile);
140146
libxml_disable_entity_loader($oldEntityLoader);
@@ -622,7 +628,7 @@ public static function getSelfRoutedURLNoQuery()
622628
if (!empty($_SERVER['REQUEST_URI'])) {
623629
$route = $_SERVER['REQUEST_URI'];
624630
if (!empty($_SERVER['QUERY_STRING'])) {
625-
$route = self::str_lreplace($_SERVER['QUERY_STRING'], '', $route);
631+
$route = self::strLreplace($_SERVER['QUERY_STRING'], '', $route);
626632
if (substr($route, -1) == '?') {
627633
$route = substr($route, 0, -1);
628634
}
@@ -644,7 +650,7 @@ public static function getSelfRoutedURLNoQuery()
644650
return $selfRoutedURLNoQuery;
645651
}
646652

647-
public static function str_lreplace($search, $replace, $subject)
653+
public static function strLreplace($search, $replace, $subject)
648654
{
649655
$pos = strrpos($subject, $search);
650656

tests/src/OneLogin/Saml2/SettingsTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testGetLibPath()
8787
$settings = new Settings();
8888
$base = $settings->getBasePath();
8989

90-
$this->assertEquals($base.'src/', $settings->getLibPath());
90+
$this->assertEquals($base.'src/Saml2/', $settings->getLibPath());
9191
}
9292

9393
/**
@@ -100,10 +100,26 @@ public function testGetSchemasPath()
100100
$settings = new Settings();
101101
$base = $settings->getBasePath();
102102

103-
$this->assertEquals($base.'src/schemas/', $settings->getSchemasPath());
103+
$this->assertEquals($base.'src/Saml2/schemas/', $settings->getSchemasPath());
104104

105105
}
106106

107+
/**
108+
* Tests getSchemasPath method of the Settings
109+
*
110+
* @covers OneLogin\Saml2\Settings::setSchemasPath
111+
*/
112+
public function testSetSchemasPath()
113+
{
114+
$settings = new Settings();
115+
$base = $settings->getBasePath();
116+
117+
$this->assertEquals($base.'src/Saml2/schemas/', $settings->getSchemasPath());
118+
119+
$settings->setSchemasPath('custompath/');
120+
$this->assertEquals('custompath/', $settings->getSchemasPath());
121+
}
122+
107123
/**
108124
* Tests shouldCompressRequests method of Settings.
109125
*

0 commit comments

Comments
 (0)