ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilWebDAVAuthentication.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
38  protected array $session_aware_webdav_clients = [
39  "Microsoft-WebDAV-MiniRedir",
40  "gvfs"
41  ];
42 
43  public function __construct(
44  protected ilObjUser $user,
45  protected ilAuthSession $session,
46  protected ilLogger $logger
47  ) {
48  }
49 
50  protected function isUserAgentSessionAware(string $user_agent): bool
51  {
52  foreach ($this->session_aware_webdav_clients as $webdav_client_name) {
53  if (stristr($user_agent, $webdav_client_name)) {
54  return true;
55  }
56  }
57  return false;
58  }
59 
60  protected function getUserAgent(): string
61  {
62  $user_agent = $_SERVER["HTTP_USER_AGENT"] ?? "";
63  $user_agent = is_string($user_agent) ? $user_agent : "";
64 
65  return $user_agent;
66  }
67 
68  public function authenticate(string $a_username, string $a_password): bool
69  {
70  if ($this->isUserAgentSessionAware($this->getUserAgent())) {
71  if ($this->session->isAuthenticated()
72  && $this->user->getId() !== 0
73  && $this->user->getId() !== ANONYMOUS_USER_ID) {
74  $this->logger->debug('User authenticated through session. UserID = ' . $this->user->getId());
75  return true;
76  }
77  } else {
79  }
80 
81  $credentials = new ilAuthFrontendCredentialsHTTP();
82  $credentials->setUsername($a_username);
83  $credentials->setPassword($a_password);
84 
85  $provider_factory = new ilAuthProviderFactory();
86  $providers = $provider_factory->getProviders($credentials);
87 
88  $status = ilAuthStatus::getInstance();
89 
90  $frontend_factory = new ilAuthFrontendFactory();
91  $frontend_factory->setContext(ilAuthFrontendFactory::CONTEXT_HTTP);
92  $frontend = $frontend_factory->getFrontend(
93  $this->session,
94  $status,
95  $credentials,
96  $providers
97  );
98 
99  $frontend->authenticate();
100 
101  switch ($status->getStatus()) {
103  $this->logger->debug(
104  'User authenticated through basic authentication. UserId = ' . $this->user->getId()
105  );
106  return true;
107 
109  $this->logger->info('Basic authentication failed; Account migration required.');
110  return false;
111 
113  $this->logger->info('Basic authentication failed; Wrong login, password.');
114  return false;
115  }
116 
117  return false;
118  }
119 }
static enableWebAccessWithoutSession(bool $enable_web_access_without_session)
isUserAgentSessionAware(string $user_agent)
const ANONYMOUS_USER_ID
Definition: constants.php:27
const STATUS_AUTHENTICATION_FAILED
Factory for auth frontend classes.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
__construct(protected ilObjUser $user, protected ilAuthSession $session, protected ilLogger $logger)
authenticate(string $a_username, string $a_password)
static getInstance()
Get status instance.
const STATUS_ACCOUNT_MIGRATION_REQUIRED