ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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  $credentials = new ilAuthFrontendCredentialsHTTP();
80  $credentials->setUsername($a_username);
81  $credentials->setPassword($a_password);
82 
83  $provider_factory = new ilAuthProviderFactory();
84  $providers = $provider_factory->getProviders($credentials);
85 
86  $status = ilAuthStatus::getInstance();
87 
88  $frontend_factory = new ilAuthFrontendFactory();
89  $frontend_factory->setContext(ilAuthFrontendFactory::CONTEXT_HTTP);
90  $frontend = $frontend_factory->getFrontend(
91  $DIC['ilAuthSession'],
92  $status,
93  $credentials,
94  $providers
95  );
96 
97  $frontend->authenticate();
98 
99  switch ($status->getStatus()) {
101  ilLoggerFactory::getLogger('webdav')->debug('User authenticated through basic authentication. UserId = ' . $DIC->user()->getId());
102  return true;
103 
105  ilLoggerFactory::getLogger('webdav')->info('Basic authentication failed; Account migration required.');
106  return false;
107 
109  ilLoggerFactory::getLogger('webdav')->info('Basic authentication failed; Wrong login, password.');
110  return false;
111  }
112 
113  return false;
114  }
115 }
static enableWebAccessWithoutSession($enable_web_access_without_session)
Class ilWebDAVAuthentication.
isUserAgentSessionAware(string $user_agent)
getUserAgent()
Gets the given user agent from the request.
const STATUS_AUTHENTICATION_FAILED
Factory for auth frontend classes.
authenticate($a_username, $a_password)
Callback function.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
global $DIC
Definition: goto.php:24
static getInstance()
Get status instance.
static getLogger($a_component_id)
Get component logger.
const STATUS_ACCOUNT_MIGRATION_REQUIRED