ILIAS  release_8 Revision v8.24
class.ilWebDAVAuthentication.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
25{
39 "Microsoft-WebDAV-MiniRedir",
40 "gvfs"
41 ];
42
43 protected ilObjUser $user;
45
47 {
48 $this->user = $user;
49 $this->session = $session;
50 }
51
52 protected function isUserAgentSessionAware(string $user_agent): bool
53 {
54 foreach ($this->session_aware_webdav_clients as $webdav_client_name) {
55 if (stristr($user_agent, $webdav_client_name)) {
56 return true;
57 }
58 }
59 return false;
60 }
61
62 protected function getUserAgent(): string
63 {
64 $user_agent = $_SERVER["HTTP_USER_AGENT"] ?? "";
65 $user_agent = is_string($user_agent) ? $user_agent : "";
66
67 return $user_agent;
68 }
69
70 public function authenticate(string $a_username, string $a_password): bool
71 {
72 if ($this->isUserAgentSessionAware($this->getUserAgent())) {
73 if ($this->session->isAuthenticated() && $this->user->getId() != 0) {
74 ilLoggerFactory::getLogger('webdav')->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 ilLoggerFactory::getLogger('webdav')->debug('User authenticated through basic authentication. UserId = ' . $this->user->getId());
104 return true;
105
107 ilLoggerFactory::getLogger('webdav')->info('Basic authentication failed; Account migration required.');
108 return false;
109
111 ilLoggerFactory::getLogger('webdav')->info('Basic authentication failed; Wrong login, password.');
112 return false;
113 }
114
115 return false;
116 }
117}
Factory for auth frontend classes.
static getInstance()
Get status instance.
const STATUS_AUTHENTICATION_FAILED
const STATUS_ACCOUNT_MIGRATION_REQUIRED
static getLogger(string $a_component_id)
Get component logger.
User class.
static enableWebAccessWithoutSession(bool $enable_web_access_without_session)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
authenticate(string $a_username, string $a_password)
isUserAgentSessionAware(string $user_agent)
__construct(ilObjUser $user, ilAuthSession $session)
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10