Skip to content

Commit 020e7cc

Browse files
committed
Add XPath-class
1 parent 3a3837c commit 020e7cc

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/Constants.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class Constants extends \SimpleSAML\XML\Constants
1818
public const string NS_SEC_EXT =
1919
'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
2020

21+
/**
22+
* The namespace for WS-Security extensions 1.1.
23+
*/
24+
public const string NS_SEC_EXT_11 =
25+
'http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd';
26+
2127
/**
2228
* The namespace for WS-Security utilities protocol.
2329
*/

src/Utils/XPath.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\WebServices\Security\Utils;
6+
7+
use DOMNode;
8+
use DOMXPath;
9+
use SimpleSAML\WebServices\Security\Constants as C;
10+
11+
/**
12+
* Compilation of utilities for XPath.
13+
*
14+
* @package simplesamlphp/xml-wss-core
15+
*/
16+
class XPath extends \SimpleSAML\XPath\XPath
17+
{
18+
/*
19+
* Get a DOMXPath object that can be used to search for WS Security elements.
20+
*
21+
* @param \DOMNode $node The document to associate to the DOMXPath object.
22+
* @param bool $autoregister Whether to auto-register all namespaces used in the document
23+
*
24+
* @return \DOMXPath A DOMXPath object ready to use in the given document, with several
25+
* ws-related namespaces already registered.
26+
*/
27+
public static function getXPath(DOMNode $node, bool $autoregister = false): DOMXPath
28+
{
29+
$xp = parent::getXPath($node, $autoregister);
30+
31+
$xp->registerNamespace('wsse', C::NS_SEC_EXT);
32+
$xp->registerNamespace('wsse11', C::NS_SEC_EXT_11);
33+
$xp->registerNamespace('wsu', C::NS_SEC_UTIL);
34+
35+
return $xp;
36+
}
37+
}

0 commit comments

Comments
 (0)