6 use Elgg\Traits\Loggable;
23 protected array $handlers = [];
43 $handler_string = $this->handlerService->describeCallable(
$handler);
44 if (!isset($this->handlers[$policy])) {
45 $this->handlers[$policy] = [];
48 $this->handlers[$policy][$handler_string] = [
50 'importance' => strtolower($importance),
63 $handler_string = $this->handlerService->describeCallable(
$handler);
65 unset($this->handlers[$policy][$handler_string]);
77 public function authenticate(
string $policy, array $authentication_params = []): bool {
78 if (!isset($this->handlers[$policy])) {
82 $authenticated =
false;
83 $first_exception =
null;
85 foreach ($this->handlers[$policy] as $handler_string => $handler_config) {
86 $handler = $handler_config[
'handler'];
87 $importance = strtolower($handler_config[
'importance']);
89 if (!$this->handlerService->isCallable(
$handler)) {
90 $this->getLogger()->warning(
"PAM handler '{$handler_string}' for policy '{$policy}' isn't callable");
94 $callable = $this->handlerService->resolveCallable(
$handler);
97 $result = call_user_func($callable, $authentication_params);
99 $authenticated =
true;
103 }
catch (\Exception $e) {
104 if (!$e instanceof AuthenticationException) {
105 $e =
new AuthenticationException($e->getMessage(), $e->getCode(), $e);
108 if ($importance ===
'required') {
112 if (!isset($first_exception)) {
113 $first_exception = $e;
118 if (!$authenticated && $first_exception instanceof AuthenticationException) {
119 throw $first_exception;
122 return $authenticated;
Authentication service handles registration of PAM handlers and calling of those handlers.
unregisterHandler($handler, string $policy='user')
Unregister an authentication handler.
registerHandler($handler, string $importance='sufficient', string $policy='user')
Register an authentication handler.
authenticate(string $policy, array $authentication_params=[])
Authenticate.
__construct(protected HandlersService $handlerService)
Create new service.
Thrown by the AuthenticationService.
Helpers for providing callable-based APIs.
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.