Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
ce445821
"lib/SimpleSAML/Store/SQLStore.php" did not exist on "8b6abc0a5d0f954a2a982750581717c6c54f0514"
Commit
ce445821
authored
10 years ago
by
Jaime Perez Crespo
Browse files
Options
Downloads
Patches
Plain Diff
Move SimpleSAML_Utilities::validateXML() to SimpleSAML\Utils\XML::isValid().
parent
78cf59db
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/SimpleSAML/Utilities.php
+3
-43
3 additions, 43 deletions
lib/SimpleSAML/Utilities.php
lib/SimpleSAML/Utils/XML.php
+56
-0
56 additions, 0 deletions
lib/SimpleSAML/Utils/XML.php
with
59 additions
and
43 deletions
lib/SimpleSAML/Utilities.php
+
3
−
43
View file @
ce445821
...
...
@@ -311,51 +311,11 @@ class SimpleSAML_Utilities {
/**
* This function attempts to validate an XML string against the specified schema.
*
* It will parse the string into a DOM document and validate this document against the schema.
*
* @param $xml The XML string or document which should be validated.
* @param $schema The schema which should be used.
* @return Returns a string with the errors if validation fails. An empty string is
* returned if validation passes.
* @deprecated
* @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\XML::isValid() instead.
*/
public
static
function
validateXML
(
$xml
,
$schema
)
{
assert
(
'is_string($xml) || $xml instanceof DOMDocument'
);
assert
(
'is_string($schema)'
);
SimpleSAML_XML_Errors
::
begin
();
if
(
$xml
instanceof
DOMDocument
)
{
$dom
=
$xml
;
$res
=
TRUE
;
}
else
{
$dom
=
new
DOMDocument
;
$res
=
$dom
->
loadXML
(
$xml
);
}
if
(
$res
)
{
$config
=
SimpleSAML_Configuration
::
getInstance
();
$schemaPath
=
$config
->
resolvePath
(
'schemas'
)
.
'/'
;
$schemaFile
=
$schemaPath
.
$schema
;
$res
=
$dom
->
schemaValidate
(
$schemaFile
);
if
(
$res
)
{
SimpleSAML_XML_Errors
::
end
();
return
''
;
}
$errorText
=
"Schema validation failed on XML string:
\n
"
;
}
else
{
$errorText
=
"Failed to parse XML string for schema validation:
\n
"
;
}
$errors
=
SimpleSAML_XML_Errors
::
end
();
$errorText
.
=
SimpleSAML_XML_Errors
::
formatErrors
(
$errors
);
return
$errorText
;
$result
=
\SimpleSAML\Utils\XML
::
isValid
(
$xml
,
$schema
);
return
(
$result
===
true
)
?
''
:
$result
;
}
...
...
This diff is collapsed.
Click to expand it.
lib/SimpleSAML/Utils/XML.php
+
56
−
0
View file @
ce445821
...
...
@@ -271,6 +271,7 @@ class XML
*
* @return boolean True if both namespace and local name matches, false otherwise.
* @throws \SimpleSAML_Error_Exception If the namespace shortcut is unknown.
*
* @author Andreas Solberg, UNINETT AS <andreas.solberg@uninett.no>
* @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
*/
...
...
@@ -311,4 +312,59 @@ class XML
}
return
true
;
}
/**
* This function attempts to validate an XML string against the specified schema. It will parse the string into a
* DOM document and validate this document against the schema.
*
* Note that this function returns values that are evaluated as a logical true, both when validation works and when
* it doesn't. Please use strict comparisons to check the values returned.
*
* @param string|\DOMDocument $xml The XML string or document which should be validated.
* @param string $schema The filename of the schema that should be used to validate the document.
*
* @return boolean|string Returns a string with errors found if validation fails. True if validation passes ok.
* @throws \InvalidArgumentException If $schema is not a string, or $xml is neither a string nor a \DOMDocument.
*
* @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
*/
public
static
function
isValid
(
$xml
,
$schema
)
{
if
(
!
(
is_string
(
$schema
)
&&
(
is_string
(
$xml
)
||
$xml
instanceof
\DOMDocument
)))
{
throw
new
\InvalidArgumentException
(
'Invalid input parameters.'
);
}
\SimpleSAML_XML_Errors
::
begin
();
if
(
$xml
instanceof
\DOMDocument
)
{
$dom
=
$xml
;
$res
=
true
;
}
else
{
$dom
=
new
\DOMDocument
;
$res
=
$dom
->
loadXML
(
$xml
);
}
if
(
$res
)
{
$config
=
\SimpleSAML_Configuration
::
getInstance
();
$schemaPath
=
$config
->
resolvePath
(
'schemas'
)
.
'/'
;
$schemaFile
=
$schemaPath
.
$schema
;
$res
=
$dom
->
schemaValidate
(
$schemaFile
);
if
(
$res
)
{
\SimpleSAML_XML_Errors
::
end
();
return
true
;
}
$errorText
=
"Schema validation failed on XML string:
\n
"
;
}
else
{
$errorText
=
"Failed to parse XML string for schema validation:
\n
"
;
}
$errors
=
\SimpleSAML_XML_Errors
::
end
();
$errorText
.
=
\SimpleSAML_XML_Errors
::
formatErrors
(
$errors
);
return
$errorText
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment