66
77use DOMElement ;
88use SimpleSAML \WSSecurity \Assert \Assert ;
9- use SimpleSAML \WSSecurity \XML \auth \ConstrainedValue ;
10- use SimpleSAML \WSSecurity \XML \auth \Description ;
11- use SimpleSAML \WSSecurity \XML \auth \DisplayName ;
12- use SimpleSAML \WSSecurity \XML \auth \DisplayValue ;
13- use SimpleSAML \WSSecurity \XML \auth \EncryptedValue ;
14- use SimpleSAML \WSSecurity \XML \auth \StructuredValue ;
15- use SimpleSAML \WSSecurity \XML \auth \Value ;
9+ use SimpleSAML \WSSecurity \XML \auth \{
10+ ConstrainedValue ,
11+ Description ,
12+ DisplayName ,
13+ DisplayValue ,
14+ EncryptedValue ,
15+ StructuredValue ,
16+ Value ,
17+ };
1618use SimpleSAML \XML \Chunk ;
17- use SimpleSAML \XML \Exception \InvalidDOMElementException ;
18- use SimpleSAML \XML \Exception \TooManyElementsException ;
19- use SimpleSAML \XML \ExtendableAttributesTrait ;
20- use SimpleSAML \XML \SerializableElementInterface ;
19+ use SimpleSAML \XML \Exception \{InvalidDOMElementException , TooManyElementsException };
20+ use SimpleSAML \XML \{ExtendableAttributesTrait , ExtendableElementTrait , SerializableElementInterface };
21+ use SimpleSAML \XML \Type \{AnyURIValue , BooleanValue };
2122use SimpleSAML \XML \XsNamespace as NS ;
2223
2324use function array_filter ;
2425use function array_merge ;
2526use function array_pop ;
27+ use function var_export ;
2628
2729/**
2830 * Class defining the ClaimType element
3234abstract class AbstractClaimType extends AbstractAuthElement
3335{
3436 use ExtendableAttributesTrait;
37+ use ExtendableElementTrait;
3538
3639 /** The namespace-attribute for the xs:anyAttribute */
3740 public const XS_ANY_ATTR_NAMESPACE = NS ::OTHER ;
3841
42+ /** The namespace-attribute for the xs:any element */
43+ public const XS_ANY_ELT_NAMESPACE = NS ::OTHER ;
44+
3945
4046 /**
4147 * AbstractClaimType constructor
4248 *
43- * @param string $uri
44- * @param bool |null $optional
49+ * @param \SimpleSAML\XML\Type\AnyURIValue $uri
50+ * @param \SimpleSAML\XML\Type\BooleanValue |null $optional
4551 * @param \SimpleSAML\WSSecurity\XML\auth\DisplayName|null $displayName
4652 * @param \SimpleSAML\WSSecurity\XML\auth\Description|null $description
4753 * @param \SimpleSAML\WSSecurity\XML\auth\DisplayValue|null $displayValue
@@ -56,15 +62,14 @@ abstract class AbstractClaimType extends AbstractAuthElement
5662 * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
5763 */
5864 final public function __construct (
59- protected string $ uri ,
60- protected ?bool $ optional = null ,
65+ protected AnyURIValue $ uri ,
66+ protected ?BooleanValue $ optional = null ,
6167 protected ?DisplayName $ displayName = null ,
6268 protected ?Description $ description = null ,
6369 protected ?DisplayValue $ displayValue = null ,
6470 protected null |Value |EncryptedValue |StructuredValue |ConstrainedValue |SerializableElementInterface $ value = null ,
6571 array $ namespacedAttributes = [],
6672 ) {
67- Assert::validURI ($ uri );
6873 if (
6974 !($ value === null ||
7075 $ value instanceof Value ||
@@ -133,9 +138,9 @@ public function getDescription(): ?Description
133138 /**
134139 * Get the value of the uri property.
135140 *
136- * @return string
141+ * @return \SimpleSAML\XML\Type\AnyURIValue
137142 */
138- public function getURI (): string
143+ public function getURI (): AnyURIValue
139144 {
140145 return $ this ->uri ;
141146 }
@@ -144,9 +149,9 @@ public function getURI(): string
144149 /**
145150 * Get the value of the optional property.
146151 *
147- * @return bool |null
152+ * @return \SimpleSAML\XML\Type\BooleanValue |null
148153 */
149- public function getOptional (): ?bool
154+ public function getOptional (): ?BooleanValue
150155 {
151156 return $ this ->optional ;
152157 }
@@ -179,15 +184,7 @@ public static function fromXML(DOMElement $xml): static
179184 $ structuredValue = StructuredValue::getChildrenOfClass ($ xml );
180185 $ encryptedValue = EncryptedValue::getChildrenOfClass ($ xml );
181186 $ constrainedValue = ConstrainedValue::getChildrenOfClass ($ xml );
182-
183- $ otherValue = [];
184- foreach ($ xml ->childNodes as $ child ) {
185- if (!($ child instanceof DOMElement)) {
186- continue ;
187- } elseif ($ child ->namespaceURI !== static ::NS ) {
188- $ otherValue [] = new Chunk ($ child );
189- }
190- }
187+ $ otherValue = self ::getChildElementsFromXML ($ xml );
191188
192189 $ value = array_filter (array_merge (
193190 $ simpleValue ,
@@ -199,8 +196,8 @@ public static function fromXML(DOMElement $xml): static
199196 Assert::maxCount ($ value , 1 , TooManyElementsException::class);
200197
201198 return new static (
202- self ::getAttribute ($ xml , 'Uri ' ),
203- self ::getOptionalBooleanAttribute ($ xml , 'Optional ' , null ),
199+ self ::getAttribute ($ xml , 'Uri ' , AnyURIValue::class ),
200+ self ::getOptionalAttribute ($ xml , 'Optional ' , BooleanValue::class , null ),
204201 array_pop ($ displayName ),
205202 array_pop ($ description ),
206203 array_pop ($ displayValue ),
@@ -220,9 +217,9 @@ public function toXML(?DOMElement $parent = null): DOMElement
220217 {
221218 $ e = $ this ->instantiateParentElement ($ parent );
222219
223- $ e ->setAttribute ('Uri ' , $ this ->getURI ());
220+ $ e ->setAttribute ('Uri ' , $ this ->getURI ()-> getValue () );
224221 if ($ this ->getOptional () !== null ) {
225- $ e ->setAttribute ('Optional ' , $ this ->getOptional () ? ' true ' : ' false ' );
222+ $ e ->setAttribute ('Optional ' , var_export ( $ this ->getOptional ()-> toBoolean (), true ) );
226223 }
227224
228225 $ this ->getDisplayName ()?->toXML($ e );
0 commit comments