ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilSamlMappedUserAttributeValueParser Class Reference

Class ilSamlMappedUserAttributeValueParser. More...

+ Collaboration diagram for ilSamlMappedUserAttributeValueParser:

Public Member Functions

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

Private Member Functions

 getValueIndex ()
 

Private Attributes

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

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

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

35  {
36  }

Member Function Documentation

◆ getAttributeKey()

ilSamlMappedUserAttributeValueParser::getAttributeKey ( )

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

Referenced by parse().

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

◆ getValueIndex()

ilSamlMappedUserAttributeValueParser::getValueIndex ( )
private

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

References ILIAS\Repository\int().

Referenced by parse().

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

◆ parse()

ilSamlMappedUserAttributeValueParser::parse ( )

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

References getAttributeKey(), and getValueIndex().

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

Field Documentation

◆ ATTR_REGEX

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

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