Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.openAuthenticator.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  * openAuthenticator class
9  *
10  * This class provides methods for private key based authentification
11  *
12  * @author Anakeen 2009
13  * @version $Id: $
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  private $privatelogin = false;
26  /**
27  * no need to ask authentication
28  */
29  public function checkAuthentication()
30  {
31  include_once ('WHAT/Lib.Http.php');
32 
33  $privatekey = getHttpVars("privateid");
34  if (!$privatekey) return Authenticator::AUTH_NOK;
35 
36  $this->privatelogin = $this->getLoginFromPrivateKey($privatekey);
37  if ($this->privatelogin === false) {
39  }
40 
41  $err = $this->consumeToken($privatekey);
42  if ($err === false) {
44  }
45 
47  }
48 
49  public function getLoginFromPrivateKey($privatekey)
50  {
51  include_once ('WHAT/Class.UserToken.php');
52  include_once ('WHAT/Class.User.php');
53 
54  $token = new UserToken('', $privatekey);
55  if (!is_object($token) || !$token->isAffected()) {
56  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . sprintf("Token '%s' not found.", $privatekey));
57  return false;
58  }
59 
60  $uid = $token->userid;
61  $user = new User('', $uid);
62  if (!is_object($user) || !$user->isAffected()) {
63  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . sprintf("Could not get user with uid '%s' for token '%s'.", $uid, $privatekey));
64  return false;
65  }
66 
67  return $user->login;
68  }
69 
70  public function consumeToken($privatekey)
71  {
72  include_once ('WHAT/Class.UserToken.php');
73 
74  $token = new UserToken('', $privatekey);
75  if (!is_object($token) || !$token->isAffected()) {
76  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . sprintf("Token '%s' not found.", $privatekey));
77  return false;
78  }
79 
80  $this->token = $token->getValues();
81  if ($token->expendable === 't') {
82  $token->delete();
83  }
84 
85  return $privatekey;
86  }
87 
88  public function checkAuthorization($opt)
89  {
90  return TRUE;
91  }
92  /**
93  * no ask
94  */
95  public function askAuthentication($args)
96  {
97  return TRUE;
98  }
99 
100  public function getAuthUser()
101  {
102  return $this->privatelogin;
103  }
104  /**
105  * no password needed
106  */
107  public function getAuthPw()
108  {
109  return false;
110  }
111  /**
112  * no logout
113  */
114  public function logout($redir_uri)
115  {
116  header("HTTP/1.0 401 Authorization Required ");
117  print _("private key is not valid");
118  return true;
119  }
120  /**
121  **
122  **
123  *
124  */
125  public function setSessionVar($name, $value)
126  {
127  include_once ('WHAT/Class.Session.php');
128  $session_auth = new Session($this->parms{'cookie'});
129  if (array_key_exists($this->parms{'cookie'}, $_COOKIE)) {
130  $session_auth->Set($_COOKIE[$this->parms{'cookie'}]);
131  } else {
132  $session_auth->Set();
133  }
134 
135  $session_auth->register($name, $value);
136 
137  return $session_auth->read($name);
138  }
139  /**
140  **
141  **
142  *
143  */
144  public function getSessionVar($name)
145  {
146  include_once ('WHAT/Class.Session.php');
147  $session_auth = new Session($this->parms{'cookie'});
148  if (array_key_exists($this->parms{'cookie'}, $_COOKIE)) {
149  $session_auth->Set($_COOKIE[$this->parms{'cookie'}]);
150  } else {
151  $session_auth->Set();
152  }
153 
154  return $session_auth->read($name);
155  }
156 }
157 ?>
← centre documentaire © anakeen - published under CC License - Dynacase