ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilUserPasswordEncoderFactory Class Reference
+ Collaboration diagram for ilUserPasswordEncoderFactory:

Public Member Functions

 __construct (array $config=[])
 
 getDefaultEncoder ()
 
 setDefaultEncoder (string $defaultEncoder)
 
 getEncoders ()
 
 setEncoders (array $encoders)
 
 getSupportedEncoderNames ()
 
 getEncoderByName ($name, $get_default_on_mismatch=false)
 
 getFirstEncoderForEncodedPasswordAndMatchers (string $encoded, array $matchers)
 

Protected Member Functions

 getValidEncoders ($config)
 
 initEncoders (array $config)
 

Protected Attributes

 $defaultEncoder
 
 $encoders = array()
 

Detailed Description

Definition at line 11 of file class.ilUserPasswordEncoderFactory.php.

Constructor & Destructor Documentation

◆ __construct()

ilUserPasswordEncoderFactory::__construct ( array  $config = [])
Parameters
array$config
Exceptions
ilPasswordException

Definition at line 25 of file class.ilUserPasswordEncoderFactory.php.

References $config, initEncoders(), and setDefaultEncoder().

26  {
27  if (!empty($config)) {
28  foreach ($config as $key => $value) {
29  switch (strtolower($key)) {
30  case 'default_password_encoder':
31  $this->setDefaultEncoder($value);
32  break;
33  }
34  }
35  }
36 
37  $this->initEncoders($config);
38  }
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
+ Here is the call graph for this function:

Member Function Documentation

◆ getDefaultEncoder()

ilUserPasswordEncoderFactory::getDefaultEncoder ( )
Returns
string

Definition at line 74 of file class.ilUserPasswordEncoderFactory.php.

References $defaultEncoder.

Referenced by getEncoderByName(), and getFirstEncoderForEncodedPasswordAndMatchers().

74  : ?string
75  {
76  return $this->defaultEncoder;
77  }
+ Here is the caller graph for this function:

◆ getEncoderByName()

ilUserPasswordEncoderFactory::getEncoderByName (   $name,
  $get_default_on_mismatch = false 
)
Parameters
string$name
bool$get_default_on_mismatch
Returns
ilPasswordEncoder
Exceptions
ilUserException

Definition at line 127 of file class.ilUserPasswordEncoderFactory.php.

References $name, and getDefaultEncoder().

Referenced by getFirstEncoderForEncodedPasswordAndMatchers().

128  {
129  if (!isset($this->encoders[$name])) {
130  if (!$get_default_on_mismatch) {
131  throw new ilUserException(sprintf('The encoder "%s" was not configured.', $name));
132  } elseif (!$this->getDefaultEncoder()) {
133  throw new ilUserException('No default encoder specified, fallback not possible.');
134  } elseif (!isset($this->encoders[$this->getDefaultEncoder()])) {
135  throw new ilUserException("No default encoder found for name: '{$this->getDefaultEncoder()}'.");
136  }
137 
138  return $this->encoders[$this->getDefaultEncoder()];
139  }
140 
141  return $this->encoders[$name];
142  }
Class for user related exception handling in ILIAS.
if($format !==null) $name
Definition: metadata.php:230
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getEncoders()

ilUserPasswordEncoderFactory::getEncoders ( )
Returns
ilPasswordEncoder[]

Definition at line 90 of file class.ilUserPasswordEncoderFactory.php.

References $encoders.

Referenced by getFirstEncoderForEncodedPasswordAndMatchers(), and getSupportedEncoderNames().

90  : array
91  {
92  return $this->encoders;
93  }
+ Here is the caller graph for this function:

◆ getFirstEncoderForEncodedPasswordAndMatchers()

ilUserPasswordEncoderFactory::getFirstEncoderForEncodedPasswordAndMatchers ( string  $encoded,
array  $matchers 
)
Parameters
string$encoded
array$matchersAn key/value pair callback functions (accepting the encoded password) assigned to the respective encoder name
Returns
ilPasswordEncoder
Exceptions
ilUserException

Definition at line 150 of file class.ilUserPasswordEncoderFactory.php.

References getDefaultEncoder(), getEncoderByName(), and getEncoders().

151  {
152  foreach ($this->getEncoders() as $encoder) {
153  foreach ($matchers as $encoderName => $callback) {
154  if (
155  $encoder->getName() === $encoderName &&
156  is_callable($callback) && $callback($encoded) === true
157  ) {
158  return $encoder;
159  }
160  }
161  }
162 
163  return $this->getEncoderByName($this->getDefaultEncoder());
164  }
getEncoderByName($name, $get_default_on_mismatch=false)
+ Here is the call graph for this function:

◆ getSupportedEncoderNames()

ilUserPasswordEncoderFactory::getSupportedEncoderNames ( )
Returns
string[]

Definition at line 116 of file class.ilUserPasswordEncoderFactory.php.

References getEncoders().

116  : array
117  {
118  return array_keys($this->getEncoders());
119  }
+ Here is the call graph for this function:

◆ getValidEncoders()

ilUserPasswordEncoderFactory::getValidEncoders (   $config)
protected
Parameters
array$config
Returns
ilPasswordEncoder[]
Exceptions
ilPasswordException

Definition at line 45 of file class.ilUserPasswordEncoderFactory.php.

References $config.

Referenced by initEncoders().

+ Here is the caller graph for this function:

◆ initEncoders()

ilUserPasswordEncoderFactory::initEncoders ( array  $config)
protected
Parameters
array$config
Exceptions
ilPasswordException

Definition at line 58 of file class.ilUserPasswordEncoderFactory.php.

References $encoders, and getValidEncoders().

Referenced by __construct().

59  {
60  $this->encoders = [];
61 
63 
64  foreach ($encoders as $encoder) {
65  if ($encoder->isSupportedByRuntime()) {
66  $this->encoders[$encoder->getName()] = $encoder;
67  }
68  }
69  }
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDefaultEncoder()

ilUserPasswordEncoderFactory::setDefaultEncoder ( string  $defaultEncoder)
Parameters
string$defaultEncoder

Definition at line 82 of file class.ilUserPasswordEncoderFactory.php.

References $defaultEncoder.

Referenced by __construct().

83  {
84  $this->defaultEncoder = $defaultEncoder;
85  }
+ Here is the caller graph for this function:

◆ setEncoders()

ilUserPasswordEncoderFactory::setEncoders ( array  $encoders)
Parameters
ilPasswordEncoder[]$encoders
Exceptions
ilUserException

Definition at line 99 of file class.ilUserPasswordEncoderFactory.php.

99  : void
100  {
101  $this->encoders = array();
102  foreach ($encoders as $encoder) {
103  if (!($encoder instanceof ilPasswordEncoder)) {
104  throw new ilUserException(sprintf(
105  'One of the passed encoders is not valid: %s.',
106  json_encode($encoder)
107  ));
108  }
109  $this->encoders[$encoder->getName()] = $encoder;
110  }
111  }
Class for user related exception handling in ILIAS.

Field Documentation

◆ $defaultEncoder

ilUserPasswordEncoderFactory::$defaultEncoder
protected

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

Referenced by getDefaultEncoder(), and setDefaultEncoder().

◆ $encoders

ilUserPasswordEncoderFactory::$encoders = array()
protected

Definition at line 19 of file class.ilUserPasswordEncoderFactory.php.

Referenced by getEncoders(), and initEncoders().


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