ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilWebDAVAuthentication.php
Go to the documentation of this file.
1 <?php
2 
12 {
26  "Microsoft-WebDAV-MiniRedir",
27  "gvfs"
28  ];
29 
34  public function isUserAgentSessionAware(string $user_agent) : bool
35  {
36  foreach ($this->session_aware_webdav_clients as $webdav_client_name) {
37  if (stristr($user_agent, $webdav_client_name)) {
38  return true;
39  }
40  }
41  return false;
42  }
43 
48  protected function getUserAgent() : string
49  {
50  // is user agent set?
51  $user_agent = isset($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : "";
52 
53  // is value of user agent a string?
54  $user_agent = is_string($user_agent) ? $user_agent : "";
55 
56  return $user_agent;
57  }
58 
66  public function authenticate($a_username, $a_password)
67  {
68  global $DIC;
69 
70  if ($this->isUserAgentSessionAware($this->getUserAgent())) {
71  if ($DIC['ilAuthSession']->isAuthenticated() && $DIC->user()->getId() != 0) {
72  ilLoggerFactory::getLogger('webdav')->debug('User authenticated through session. UserID = ' . $DIC->user()->getId());
73  return true;
74  }
75  } else {
77  }
78 
79  include_once './Services/Authentication/classes/Frontend/class.ilAuthFrontendCredentialsHTTP.php';
80  $credentials = new ilAuthFrontendCredentialsHTTP();
81  $credentials->setUsername($a_username);
82  $credentials->setPassword($a_password);
83 
84  include_once './Services/Authentication/classes/Provider/class.ilAuthProviderFactory.php';
85  $provider_factory = new ilAuthProviderFactory();
86  $providers = $provider_factory->getProviders($credentials);
87 
88  include_once './Services/Authentication/classes/class.ilAuthStatus.php';
89  $status = ilAuthStatus::getInstance();
90 
91  include_once './Services/Authentication/classes/Frontend/class.ilAuthFrontendFactory.php';
92  $frontend_factory = new ilAuthFrontendFactory();
93  $frontend_factory->setContext(ilAuthFrontendFactory::CONTEXT_HTTP);
94  $frontend = $frontend_factory->getFrontend(
95  $DIC['ilAuthSession'],
96  $status,
97  $credentials,
98  $providers
99  );
100 
101  $frontend->authenticate();
102 
103  switch ($status->getStatus()) {
105  ilLoggerFactory::getLogger('webdav')->debug('User authenticated through basic authentication. UserId = ' . $DIC->user()->getId());
106  return true;
107 
109  ilLoggerFactory::getLogger('webdav')->info('Basic authentication failed; Account migration required.');
110  return false;
111 
113  ilLoggerFactory::getLogger('webdav')->info('Basic authentication failed; Wrong login, password.');
114  return false;
115  }
116 
117  return false;
118  }
119 }
static enableWebAccessWithoutSession($enable_web_access_without_session)
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
Class ilWebDAVAuthentication.
isUserAgentSessionAware(string $user_agent)
getUserAgent()
Gets the given user agent from the request.
global $DIC
Definition: saml.php:7
const STATUS_AUTHENTICATION_FAILED
Factory for auth frontend classes.
authenticate($a_username, $a_password)
Callback function.
static getInstance()
Get status instance.
static getLogger($a_component_id)
Get component logger.
const STATUS_ACCOUNT_MIGRATION_REQUIRED