ILIAS  release_8 Revision v8.24
ilSamlIdpXmlMetadataParser Class Reference
+ Collaboration diagram for ilSamlIdpXmlMetadataParser:

Public Member Functions

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

Private Member Functions

 beginLogging ()
 
 addErrors ()
 
 endLogging ()
 

Private Attributes

DataTypeFactory $dataFactory
 
ilSamlIdpXmlMetadataErrorFormatter $errorFormatter
 
Result $result
 
bool $xmlErrorState = false
 
array $errorStack = []
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

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

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

34 {
35 $this->dataFactory = $dataFactory;
36 $this->errorFormatter = $errorFormatter;
37 $this->result = new Result\Error('No metadata parsed, yet');
38 }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Error.php:18
ilSamlIdpXmlMetadataErrorFormatter $errorFormatter

References $dataFactory, $errorFormatter, and result().

+ Here is the call graph for this function:

Member Function Documentation

◆ addErrors()

ilSamlIdpXmlMetadataParser::addErrors ( )
private

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

52 : void
53 {
54 $currentErrors = libxml_get_errors();
55 libxml_clear_errors();
56
57 $level = count($this->errorStack) - 1;
58 $this->errorStack[$level] = array_merge($this->errorStack[$level], $currentErrors);
59 }

Referenced by beginLogging(), and endLogging().

+ Here is the caller graph for this function:

◆ beginLogging()

ilSamlIdpXmlMetadataParser::beginLogging ( )
private

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

40 : void
41 {
42 if (0 === count($this->errorStack)) {
43 $this->xmlErrorState = libxml_use_internal_errors(true);
44 libxml_clear_errors();
45 } else {
46 $this->addErrors();
47 }
48
49 $this->errorStack[] = [];
50 }

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 64 of file class.ilSamlIdpXmlMetadataParser.php.

64 : array
65 {
66 $this->addErrors();
67
68 $errors = array_pop($this->errorStack);
69
70 if (0 === count($this->errorStack)) {
71 libxml_use_internal_errors($this->xmlErrorState);
72 }
73
74 return $errors;
75 }
$errors
Definition: imgupload.php:65

References $errors, and addErrors().

Referenced by parse().

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

◆ parse()

ilSamlIdpXmlMetadataParser::parse ( string  $xmlString)

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

77 : void
78 {
79 try {
80 $this->beginLogging();
81
82 $xml = new SimpleXMLElement($xmlString);
83
84 $xml->registerXPathNamespace('md', 'urn:oasis:names:tc:SAML:2.0:metadata');
85 $xml->registerXPathNamespace('mdui', 'urn:oasis:names:tc:SAML:metadata:ui');
86
87 $idps = $xml->xpath('//md:EntityDescriptor[//md:IDPSSODescriptor]');
88 $entityId = null;
89 if ($idps && is_array($idps) && isset($idps[0]) && $idps[0] instanceof SimpleXMLElement) {
90 $attributes = $idps[0]->attributes('', true);
91 if ($attributes && isset($attributes['entityID'])) {
92 $entityId = (string) ($attributes->entityID[0] ?? '');
93 }
94 }
95
96 $errors = $this->endLogging();
97
98 if ($entityId) {
99 $this->result = $this->dataFactory->ok($entityId);
100 return;
101 }
102
103 $error = new LibXMLError();
104 $error->level = LIBXML_ERR_FATAL;
105 $error->code = 0;
106 $error->message = 'No entityID found';
107 $error->line = 1;
108 $error->column = 0;
109
110 $errors[] = $error;
111
112 $this->result = $this->dataFactory->error($this->errorFormatter->formatErrors(...$errors));
113 } catch (Exception $e) {
114 $this->result = $this->dataFactory->error($this->errorFormatter->formatErrors(...$this->endLogging()));
115 }
116 }
if( $source===null) if(!($source instanceof SP)) $entityId
Definition: metadata.php:105
$attributes
Definition: metadata.php:248
$xml
Definition: metadata.php:351

References $attributes, Vendor\Package\$e, $entityId, $errors, $xml, beginLogging(), endLogging(), and result().

+ Here is the call graph for this function:

◆ result()

ilSamlIdpXmlMetadataParser::result ( )

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

118 : Result
119 {
120 return $this->result;
121 }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:15

References $result.

Referenced by __construct(), and parse().

+ Here is the caller graph for this function:

Field Documentation

◆ $dataFactory

DataTypeFactory ilSamlIdpXmlMetadataParser::$dataFactory
private

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

Referenced by __construct().

◆ $errorFormatter

ilSamlIdpXmlMetadataErrorFormatter ilSamlIdpXmlMetadataParser::$errorFormatter
private

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

Referenced by __construct().

◆ $errorStack

array ilSamlIdpXmlMetadataParser::$errorStack = []
private

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

◆ $result

Result ilSamlIdpXmlMetadataParser::$result
private

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

Referenced by result().

◆ $xmlErrorState

bool ilSamlIdpXmlMetadataParser::$xmlErrorState = false
private

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


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