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),
65 $handler_string = $this->handlerService->describeCallable(
$handler);
67 unset($this->handlers[$policy][$handler_string]);
79 public function authenticate(
string $policy, array $authentication_params = []): bool {
80 if (!isset($this->handlers[$policy])) {
84 $authenticated =
false;
85 $first_exception =
null;
87 foreach ($this->handlers[$policy] as $handler_string => $handler_config) {
88 $handler = $handler_config[
'handler'];
89 $importance = strtolower($handler_config[
'importance']);
91 if (!$this->handlerService->isCallable(
$handler)) {
92 $this->getLogger()->warning(
"PAM handler '{$handler_string}' for policy '{$policy}' isn't callable");
96 $callable = $this->handlerService->resolveCallable(
$handler);
99 $result = call_user_func($callable, $authentication_params);
101 $authenticated =
true;
105 }
catch (\Exception $e) {
106 if (!$e instanceof AuthenticationException) {
107 $e =
new AuthenticationException($e->getMessage(), $e->getCode(), $e);
110 if ($importance ===
'required') {
114 if (!isset($first_exception)) {
115 $first_exception = $e;
120 if (!$authenticated && $first_exception instanceof AuthenticationException) {
121 throw $first_exception;
124 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.