ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilSamlMappedUserAttributeValueParser Class Reference

Class ilSamlMappedUserAttributeValueParser. More...

+ Collaboration diagram for ilSamlMappedUserAttributeValueParser:

Public Member Functions

 __construct (\ilExternalAuthUserAttributeMappingRule $rule, array $userData)
 ilSamlMappedUserAttributeValueParser constructor. More...
 
 getAttributeKey ()
 
 parse ()
 

Data Fields

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

Protected Member Functions

 getValueIndex ()
 

Protected Attributes

 $rule
 
 $userData = []
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilSamlMappedUserAttributeValueParser::__construct ( \ilExternalAuthUserAttributeMappingRule  $rule,
array  $userData 
)

Member Function Documentation

◆ getAttributeKey()

ilSamlMappedUserAttributeValueParser::getAttributeKey ( )
Returns
string

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

Referenced by parse().

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

◆ getValueIndex()

ilSamlMappedUserAttributeValueParser::getValueIndex ( )
protected
Returns
int

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

References $index.

Referenced by parse().

30  : int
31  {
32  $index = 0;
33 
34  $matches = [];
35  preg_match(self::ATTR_REGEX, $this->rule->getExternalAttribute(), $matches);
36 
37  if (is_array($matches) && isset($matches[3]) && is_numeric($matches[3])) {
38  $index = (int) $matches[3];
39  }
40 
41  return $index >= 0 ? $index : 0;
42  }
$index
Definition: metadata.php:128
+ Here is the caller graph for this function:

◆ parse()

ilSamlMappedUserAttributeValueParser::parse ( )
Exceptions

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

References getAttributeKey(), and getValueIndex().

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

Field Documentation

◆ $rule

ilSamlMappedUserAttributeValueParser::$rule
protected

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

Referenced by __construct().

◆ $userData

ilSamlMappedUserAttributeValueParser::$userData = []
protected

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

Referenced by __construct().

◆ ATTR_REGEX

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

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