ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
ILIASAuthenticationCallback.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\WebDAV\Auth;
22
25use ilObjUser;
26use ilLogger;
27use ilSession;
29use ilAuthStatus;
33
38{
53 "Microsoft-WebDAV-MiniRedir",
54 "gvfs"
55 ];
56
57 public function __construct(
58 protected ilObjUser $user,
59 protected ilAuthSession $session,
60 protected ilLogger $logger,
61 Filesystem $filesystem,
62 SecretKeyRotation $secret_key_rotation
63 ) {
64 $this->file_cache = new ILIASAuthenticationFileCache(
65 $filesystem,
66 $secret_key_rotation
67 );
68 }
69
70 protected function isUserAgentSessionAware(string $user_agent): bool
71 {
72 return array_any($this->session_aware_webdav_clients, fn($webdav_client_name): string|false => stristr($user_agent, (string) $webdav_client_name));
73 }
74
75 protected function getUserAgent(): string
76 {
77 return $_SERVER["HTTP_USER_AGENT"] ?? '';
78 }
79
80 public function authenticate(string $a_username, string $a_password): bool
81 {
82 global $DIC;
83
84 $cached = $this->file_cache->isAuthenticated($a_username, $a_password);
85 if ($cached !== null) {
86 $this->logger->info('WEBDAV: User authenticated through cache. UserID = ' . $cached);
87 $DIC->user()->setId($cached);
89 return true;
90 }
91 if ($this->isUserAgentSessionAware($this->getUserAgent())) {
92 if ($this->session->isAuthenticated()
93 && $this->user->getId() !== 0
94 && $this->user->getId() !== ANONYMOUS_USER_ID) {
95 $this->logger->debug('User authenticated through session. UserID = ' . $this->user->getId());
96 return true;
97 }
98 } else {
100 }
101
102 $credentials = new ilAuthFrontendCredentialsHTTP();
103 $credentials->setUsername($a_username);
104 $credentials->setPassword($a_password);
105
106 $provider_factory = new ilAuthProviderFactory();
107 $providers = $provider_factory->getProviders($credentials);
108
109 $status = ilAuthStatus::getInstance();
110
111 $frontend_factory = new ilAuthFrontendFactory();
112 $frontend_factory->setContext(ilAuthFrontendFactory::CONTEXT_HTTP);
113 $frontend = $frontend_factory->getFrontend(
114 $this->session,
115 $status,
116 $credentials,
117 $providers
118 );
119
120 $frontend->authenticate();
121
122 switch ($status->getStatus()) {
124 $this->logger->debug(
125 'User authenticated through basic authentication. UserId = ' . $this->user->getId()
126 );
127
128 $this->file_cache->setAuthenticated($a_username, $a_password, (int) $DIC->user()->getId());
129 return true;
130
132 $this->logger->info('Basic authentication failed; Account migration required.');
133 return false;
134
136 $this->logger->info('Basic authentication failed; Wrong login, password.');
137 return false;
138 }
139
140 return false;
141 }
142}
Key rotation can provide an extra layer of mitigation against an attacker discovering a secret key.
authenticate(string $a_username, string $a_password)
__construct(protected ilObjUser $user, protected ilAuthSession $session, protected ilLogger $logger, Filesystem $filesystem, SecretKeyRotation $secret_key_rotation)
const int STATUS_AUTHENTICATION_FAILED
const int STATUS_ACCOUNT_MIGRATION_REQUIRED
const int STATUS_AUTHENTICATED
static getInstance()
Get status instance.
Component logger with individual log levels by component id.
User class.
static enableWebAccessWithoutSession(bool $enable_web_access_without_session)
const ANONYMOUS_USER_ID
Definition: constants.php:27
The filesystem interface provides the public interface for the Filesystem service API consumer.
Definition: Filesystem.php:37
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
global $DIC
Definition: shib_login.php:26