ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilSamlMappedUserAttributeValueParser Class Reference
+ Collaboration diagram for ilSamlMappedUserAttributeValueParser:

Public Member Functions

 __construct (private ilExternalAuthUserAttributeMappingRule $rule, private array $userData)
 
 getAttributeKey ()
 
 parse ()
 

Private Member Functions

 getValueIndex ()
 

Private Attributes

const string ATTR_REGEX = '/^(.*?)(\|(\d+))?$/'
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilSamlMappedUserAttributeValueParser::__construct ( private ilExternalAuthUserAttributeMappingRule  $rule,
private array  $userData 
)
Parameters
array<string,mixed>$userData

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

31  {
32  }

Member Function Documentation

◆ getAttributeKey()

ilSamlMappedUserAttributeValueParser::getAttributeKey ( )

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

Referenced by parse().

48  : string
49  {
50  $attribute = '';
51 
52  $matches = [];
53  preg_match(self::ATTR_REGEX, $this->rule->getExternalAttribute(), $matches);
54 
55  if (is_array($matches) && isset($matches[1]) && is_string($matches[1])) {
56  $attribute = $matches[1];
57  }
58 
59  return $attribute;
60  }
+ Here is the caller graph for this function:

◆ getValueIndex()

ilSamlMappedUserAttributeValueParser::getValueIndex ( )
private

Definition at line 34 of file class.ilSamlMappedUserAttributeValueParser.php.

References ILIAS\Repository\int().

Referenced by parse().

34  : int
35  {
36  $index = 0;
37 
38  $matches = [];
39  preg_match(self::ATTR_REGEX, $this->rule->getExternalAttribute(), $matches);
40 
41  if (is_array($matches) && isset($matches[3]) && is_numeric($matches[3])) {
42  $index = (int) $matches[3];
43  }
44 
45  return max($index, 0);
46  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse()

ilSamlMappedUserAttributeValueParser::parse ( )

Definition at line 62 of file class.ilSamlMappedUserAttributeValueParser.php.

References getAttributeKey(), and getValueIndex().

62  : string
63  {
64  $attributeKey = $this->getAttributeKey();
65 
66  if (!array_key_exists($attributeKey, $this->userData)) {
67  throw new ilSamlException(sprintf(
68  "Configured external attribute of mapping '%s' -> '%s' does not exist in SAML attribute data.",
69  $this->rule->getAttribute(),
70  $this->rule->getExternalAttribute()
71  ));
72  }
73 
74  $value = $this->userData[$attributeKey];
75 
76  if (is_array($value)) {
77  $valueIndex = $this->getValueIndex();
78 
79  if (!array_key_exists($valueIndex, $value)) {
80  throw new ilSamlException(sprintf(
81  "Configured external attribute of mapping '%s' -> '%s' does not exist in SAML attribute data.",
82  $this->rule->getAttribute(),
83  $this->rule->getExternalAttribute()
84  ));
85  }
86 
87  $value = $value[$valueIndex];
88  }
89 
90  if (!is_scalar($value)) {
91  throw new ilSamlException(sprintf(
92  "Could not parse a scalar value based on the user attribute mapping '%s' -> '%s'.",
93  $this->rule->getAttribute(),
94  $this->rule->getExternalAttribute()
95  ));
96  }
97 
98  return (string) $value;
99  }
+ Here is the call graph for this function:

Field Documentation

◆ ATTR_REGEX

const string ilSamlMappedUserAttributeValueParser::ATTR_REGEX = '/^(.*?)(\|(\d+))?$/'
private

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