Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.basicAuthenticator.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * basicAuthenticator class
9  *
10  * This class provides methods for HTTP Basic authentication
11  *
12  * @author Anakeen 2009
13  * @version $Id: Class.basicAuthenticator.php,v 1.3 2009/01/16 13:33:00 jerome Exp $
14  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
15  * @package FDL
16  * @subpackage
17  */
18 /**
19  */
20 include_once ('WHAT/Class.Authenticator.php');
21 
23 {
24 
25  public function checkAuthentication()
26  {
27 
28  if (array_key_exists('logout', $_COOKIE) && $_COOKIE['logout'] == "true") {
29  setcookie('logout', '', time() - 3600);
31  }
32 
33  if (!array_key_exists('PHP_AUTH_USER', $_SERVER)) {
34  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Error: undefined _SERVER[PHP_AUTH_USER]");
36  }
37 
38  if (!array_key_exists('PHP_AUTH_PW', $_SERVER)) {
39  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Error: undefined _SERVER[PHP_AUTH_PW] for user " . $_SERVER['PHP_AUTH_USER']);
41  }
42 
43  if (!is_callable(array(
44  $this->provider,
45  'validateCredential'
46  ))) {
47  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Error: " . $this->parms{'type'} . $this->parms{'provider'} . "Provider must implement validateCredential()");
49  }
50 
51  if (!$this->provider->validateCredential($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
53  }
54 
55  if (!$this->freedomUserExists($_SERVER['PHP_AUTH_USER'])) {
56  if (!$this->tryInitializeUser($_SERVER['PHP_AUTH_USER'])) {
58  }
59  }
60 
62  }
63 
64  public function checkAuthorization($opt)
65  {
66  if (is_callable(array(
67  $this->provider,
68  'checkAuthorization'
69  ))) {
70  return $this->provider->checkAuthorization($opt);
71  }
72 
73  return TRUE;
74  }
75 
76  public function askAuthentication($args = array())
77  {
78  if (is_callable(array(
79  $this->provider,
80  'askAuthentication'
81  ))) {
82  return $this->provider->askAuthentication();
83  }
84  header('HTTP/1.1 401 Authentication Required');
85  header('WWW-Authenticate: Basic realm="' . $this->parms{'realm'} . '"');
86  header('Connection: close');
87  return TRUE;
88  }
89 
90  public function getAuthUser()
91  {
92  if (is_callable(array(
93  $this->provider,
94  'getAuthUser'
95  ))) {
96  return $this->provider->getAuthUser();
97  }
98 
99  return $_SERVER['PHP_AUTH_USER'];
100  }
101 
102  public function getAuthPw()
103  {
104  if (is_callable(array(
105  $this->provider,
106  'getAuthPw'
107  ))) {
108  return $this->provider->getAuthPw();
109  }
110 
111  return $_SERVER['PHP_AUTH_PW'];
112  }
113 
114  public function logout($redir_uri = '')
115  {
116  setcookie('logout', 'true', 0);
117  if ($redir_uri == '') {
118  $redir_uri = getParam('CORE_BASEURL');
119  }
120  header('Location: ' . $redir_uri);
121  return TRUE;
122  }
123 
124  public function setSessionVar($name, $value)
125  {
126  return TRUE;
127  }
128 
129  public function getSessionVar($name)
130  {
131  return '';
132  }
133 }
134 ?>
← centre documentaire © anakeen - published under CC License - Dynacase