ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilSamlIdpXmlMetadataParser Class Reference
+ Collaboration diagram for ilSamlIdpXmlMetadataParser:

Public Member Functions

 __construct (private readonly DataTypeFactory $dataFactory, private readonly ilSamlIdpXmlMetadataErrorFormatter $errorFormatter)
 
 parse (string $xmlString)
 

Private Member Functions

 beginLogging ()
 
 addErrors ()
 
 endLogging ()
 
 ok (string $entity_id)
 
 error ($additional_errors=[])
 

Private Attributes

bool $xmlErrorState = false
 
array $errorStack = []
 

Detailed Description

Definition at line 24 of file class.ilSamlIdpXmlMetadataParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilSamlIdpXmlMetadataParser::__construct ( private readonly DataTypeFactory  $dataFactory,
private readonly ilSamlIdpXmlMetadataErrorFormatter  $errorFormatter 
)

Definition at line 30 of file class.ilSamlIdpXmlMetadataParser.php.

33 {
34 }

Member Function Documentation

◆ addErrors()

ilSamlIdpXmlMetadataParser::addErrors ( )
private

Definition at line 48 of file class.ilSamlIdpXmlMetadataParser.php.

48 : void
49 {
50 $currentErrors = libxml_get_errors();
51 libxml_clear_errors();
52
53 $level = count($this->errorStack) - 1;
54 $this->errorStack[$level] = array_merge($this->errorStack[$level], $currentErrors);
55 }

Referenced by beginLogging(), and endLogging().

+ Here is the caller graph for this function:

◆ beginLogging()

ilSamlIdpXmlMetadataParser::beginLogging ( )
private

Definition at line 36 of file class.ilSamlIdpXmlMetadataParser.php.

36 : void
37 {
38 if ([] === $this->errorStack) {
39 $this->xmlErrorState = libxml_use_internal_errors(true);
40 libxml_clear_errors();
41 } else {
42 $this->addErrors();
43 }
44
45 $this->errorStack[] = [];
46 }

References addErrors().

Referenced by parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ endLogging()

ilSamlIdpXmlMetadataParser::endLogging ( )
private
Returns
LibXMLError[] An array with the LibXMLErrors which has occurred since beginLogging() was called.

Definition at line 60 of file class.ilSamlIdpXmlMetadataParser.php.

60 : array
61 {
62 $this->addErrors();
63
64 $errors = array_pop($this->errorStack);
65
66 if ([] === $this->errorStack) {
67 libxml_use_internal_errors($this->xmlErrorState);
68 }
69
70 return $errors;
71 }

References addErrors().

Referenced by ok().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ error()

ilSamlIdpXmlMetadataParser::error (   $additional_errors = [])
private
Parameters
list<LibXMLError>$additional_errors

Definition at line 118 of file class.ilSamlIdpXmlMetadataParser.php.

118 : Result
119 {
120 return $this->dataFactory->error($this->errorFormatter->formatErrors(...$this->endLogging(), ...$additional_errors));
121 }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29
error()
Get the encapsulated error.

References ILIAS\Data\Result\error().

Referenced by parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ok()

ilSamlIdpXmlMetadataParser::ok ( string  $entity_id)
private

Definition at line 108 of file class.ilSamlIdpXmlMetadataParser.php.

108 : Result
109 {
110 $this->endLogging();
111
112 return $this->dataFactory->ok($entity_id);
113 }

References endLogging().

Referenced by parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse()

ilSamlIdpXmlMetadataParser::parse ( string  $xmlString)
Returns
Result<non-empty-string>

Definition at line 76 of file class.ilSamlIdpXmlMetadataParser.php.

76 : Result
77 {
78 try {
79 $this->beginLogging();
80
81 $xml = new SimpleXMLElement($xmlString);
82
83 $xml->registerXPathNamespace('md', 'urn:oasis:names:tc:SAML:2.0:metadata');
84 $xml->registerXPathNamespace('mdui', 'urn:oasis:names:tc:SAML:metadata:ui');
85
86 $idps = $xml->xpath('//md:EntityDescriptor[//md:IDPSSODescriptor]');
87
88 $entity_id = ($idps[0] ?? null)?->attributes('', true)['entityID'][0] ?? '';
89 $entity_id = (string) $entity_id;
90
91 if ($entity_id !== '') {
92 return $this->ok($entity_id);
93 }
94
95 $error = new LibXMLError();
96 $error->level = LIBXML_ERR_FATAL;
97 $error->code = 0;
98 $error->message = 'No entityID found';
99 $error->line = 1;
100 $error->column = 0;
101
102 return $this->error([$error]);
103 } catch (Exception) {
104 return $this->error();
105 }
106 }

References beginLogging(), error(), and ok().

+ Here is the call graph for this function:

Field Documentation

◆ $errorStack

array ilSamlIdpXmlMetadataParser::$errorStack = []
private

Definition at line 28 of file class.ilSamlIdpXmlMetadataParser.php.

◆ $xmlErrorState

bool ilSamlIdpXmlMetadataParser::$xmlErrorState = false
private

Definition at line 26 of file class.ilSamlIdpXmlMetadataParser.php.


The documentation for this class was generated from the following file: