Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.Authenticator.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  * Authenticator class
9  *
10  * Top-level class to authenticate and authorize users
11  *
12  * @author Anakeen 2009
13  * @version $Id: Class.Authenticator.php,v 1.6 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 
21 abstract class Authenticator
22 {
23  /* Authentication success */
24  const AUTH_OK = 0;
25  /* Authentication failed */
26  const AUTH_NOK = 1;
27  /* Authentication status cannot be determined, and credentials should be asked */
28  const AUTH_ASK = 2;
29 
30  public function __construct($authtype, $authprovider)
31  {
32 
33  include_once ('WHAT/Lib.Common.php');
34 
35  if ($authtype == "") throw new Exception(__CLASS__ . "::" . __FUNCTION__ . " " . "Error: authentication mode not set");
36  if ($authprovider == "") throw new Exception(__CLASS__ . "::" . __FUNCTION__ . " " . "Error: authentication provider not set");
37 
38  $tx = array(
39  'type' => $authtype,
40  'provider' => $authprovider
41  );
43  if ($authprovider != "__for_logout__") {
44  $tp = getAuthParam("", $authprovider);
45  $this->parms = array_merge($tx, $ta, $tp);
46 
47  if (!array_key_exists('provider', $this->parms)) {
48  throw new Exception(__CLASS__ . "::" . __FUNCTION__ . " " . "Error: provider parm not specified at __construct");
49  }
50  $providerClass = $this->parms{'provider'} . 'Provider';
51  $ret = @include_once ('WHAT/Class.' . $providerClass . '.php');
52  if ($ret === FALSE) {
53  throw new Exception(__CLASS__ . "::" . __FUNCTION__ . " " . "Error: WHAT/Class." . $providerClass . ".php not found");
54  }
55  if (!class_exists($providerClass)) {
56  throw new Exception(__CLASS__ . "::" . __FUNCTION__ . " " . "Error: " . $providerClass . " class not found");
57  }
58  global $action;
59  // error_log("Using authentication provider [".$providerClass."]");
60  $this->provider = new $providerClass($authprovider, $this->parms);
61  } else {
62  $this->parms = array_merge($tx, $ta);
63  }
64  }
65 
66  public function freedomUserExists($username)
67  {
68  @include_once ('FDL/Class.Doc.php');
69  @include_once ('WHAT/Class.User.php');
70 
71  $u = new User();
72  if ($u->SetLoginName($username)) {
73  $dbaccess = GetParam("FREEDOM_DB");
74  $du = new_Doc($dbaccess, $u->fid);
75  if ($du->isAlive()) {
76  return TRUE;
77  }
78  }
79  return FALSE;
80  }
81 
82  public function tryInitializeUser($username)
83  {
84  if (!$this->provider->canICreateUser()) {
85  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . sprintf("Authentication failed for user '%s' because auto-creation is disabled for provider '%s'!", $username, $this->provider->pname));
86  return FALSE;
87  }
88  $err = $this->provider->initializeUser($username);
89  if ($err != "") {
90  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . sprintf("Error creating user '%s' err=[%s]", $username, $err));
91  return FALSE;
92  }
93  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . sprintf("Initialized user '%s'!", $username));
94  return TRUE;
95  }
96 
97  public function getProviderErrno()
98  {
99  if ($this->provider) {
100  return $this->provider->errno;
101  }
102  return 0;
103  }
104 
105  abstract function checkAuthentication();
106  abstract function checkAuthorization($opt);
107  abstract function askAuthentication($args);
108  abstract function getAuthUser();
109  abstract function getAuthPw();
110  abstract function logout($redir_uri);
111  abstract function setSessionVar($name, $value);
112  abstract function getSessionVar($name);
113 }
114 ?>
← centre documentaire © anakeen - published under CC License - Dynacase