| Line 47... |
Line 47... |
| 47 |
}
|
47 |
}
|
| 48 |
}
|
48 |
}
|
| Line 49... |
Line 49... |
| 49 |
|
49 |
|
| Line 50... |
Line 50... |
| 50 |
class identificationSso {
|
50 |
class identificationSso {
|
| 51 |
|
51 |
|
| 52 |
// Attention bien vérifier la présence des variables suivantes :
|
52 |
// Attention bien v�rifier la pr�sence des variables suivantes :
|
| 53 |
// IDEN_UTILISE_SSO, IDEN_URL_SSO, IDEN_HEADER_SSO, IDEN_COOKIE_SSO
|
53 |
// IDEN_UTILISE_SSO, IDEN_URL_SSO, IDEN_HEADER_SSO, IDEN_COOKIE_SSO
|
| - |
|
54 |
// dans le fichier iden_config.inc.php
|
| 54 |
// dans le fichier iden_config.inc.php
|
55 |
private $cookie_tentative_identification = "";
|
| Line 55... |
Line 56... |
| 55 |
private $cookie_tentative_identification = "";
|
56 |
/** Une tentative par minute pour s'identifier suffit largement */
|
| Line 56... |
Line 57... |
| 56 |
private $delai_tentative_identification = 60;
|
57 |
private $delai_tentative_identification = 60;
|
| Line 71... |
Line 72... |
| 71 |
|
72 |
|
| 72 |
$this->cookie_tentative_identification = IDEN_COOKIE_SSO;
|
73 |
$this->cookie_tentative_identification = IDEN_COOKIE_SSO;
|
| 73 |
$this->auth_header = IDEN_HEADER_SSO;
|
74 |
$this->auth_header = IDEN_HEADER_SSO;
|
| Line 74... |
Line 75... |
| 74 |
$this->annuaire_url = IDEN_URL_SSO;
|
75 |
$this->annuaire_url = IDEN_URL_SSO;
|
| 75 |
|
76 |
|
| 76 |
// c'est moche mais je n'ai pas trouvé plus simple pour récuperer la table annuaire en cours
|
77 |
// c'est moche mais je n'ai pas trouv� plus simple pour r�cuperer la table annuaire en cours
|
| 77 |
// d'utilisation pour le site actuel (la bdd annuaire est la dernière partie du dsn)
|
78 |
// d'utilisation pour le site actuel (la bdd annuaire est la derni�re partie du dsn)
|
| 78 |
$dsn_annuaire = $this->communs_papyrus['info_auth_bdd']->gsab_dsn;
|
79 |
$dsn_annuaire = $this->communs_papyrus['info_auth_bdd']->gsab_dsn;
|
| Line 79... |
Line 80... |
| 79 |
$dsn_annuaire = explode('/', $dsn_annuaire);
|
80 |
$dsn_annuaire = explode('/', $dsn_annuaire);
|
| Line 86... |
Line 87... |
| 86 |
|
87 |
|
| 87 |
function getToken() {
|
88 |
function getToken() {
|
| 88 |
// Premier essai, dans le header
|
89 |
// Premier essai, dans le header
|
| 89 |
$headers = @apache_request_headers();
|
90 |
$headers = @apache_request_headers();
|
| 90 |
$token = !empty($headers['Authorization']) ? $headers['Authorization'] : null;
|
91 |
$token = !empty($headers['Authorization']) ? $headers['Authorization'] : null;
|
| 91 |
// Eventuellement, le jeton a pu être passé dans un header non standard, comme dans
|
92 |
// Eventuellement, le jeton a pu �tre pass� dans un header non standard, comme dans
|
| 92 |
// le cas où le header Authorization est supprimé par le mod cgi d'apache
|
93 |
// le cas o� le header Authorization est supprim� par le mod cgi d'apache
|
| 93 |
// Dans ce cas là on vérifie aussi dans un header alternatif si celui ci a été renseigné
|
94 |
// Dans ce cas l� on v�rifie aussi dans un header alternatif si celui ci a �t� renseign�
|
| 94 |
if($token == null && $this->auth_header != 'Authorization') {
|
95 |
if($token == null && $this->auth_header != 'Authorization') {
|
| 95 |
$token = !empty($headers[$this->auth_header]) ? $headers[$this->auth_header] : null;
|
96 |
$token = !empty($headers[$this->auth_header]) ? $headers[$this->auth_header] : null;
|
| Line 96... |
Line 97... |
| 96 |
}
|
97 |
}
|
| Line 116... |
Line 117... |
| 116 |
// http://stackoverflow.com/questions/1251582/beautiful-way-to-remove-get-variables-with-php?lq=1
|
117 |
// http://stackoverflow.com/questions/1251582/beautiful-way-to-remove-get-variables-with-php?lq=1
|
| 117 |
function supprimerUrlVar($url, $var) {
|
118 |
function supprimerUrlVar($url, $var) {
|
| 118 |
return rtrim(preg_replace('/([?&])'.$var.'=[^&]+(&|$)/','$1',$url), '&?');
|
119 |
return rtrim(preg_replace('/([?&])'.$var.'=[^&]+(&|$)/','$1',$url), '&?');
|
| 119 |
}
|
120 |
}
|
| Line 120... |
Line 121... |
| 120 |
|
121 |
|
| 121 |
function connecterEtRediriger($utilisateur, $pass) {
|
122 |
function connecterEtRediriger() {
|
| 122 |
$url_redirect = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
123 |
$url_redirect = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
| 123 |
$params = 'login='.$_POST['username'].'&password='.$_POST['password'].'&redirect_url='.urlencode($url_redirect);
|
124 |
$params = 'login='.$_POST['username'].'&password='.$_POST['password'].'&redirect_url='.urlencode($url_redirect);
|
| Line 124... |
Line 125... |
| 124 |
$connexion_url = $this->annuaire_url."connexion?".$params;
|
125 |
$connexion_url = $this->annuaire_url."connexion?".$params;
|
| Line 136... |
Line 137... |
| 136 |
header('Location: '.$deconnexion_url);
|
137 |
header('Location: '.$deconnexion_url);
|
| 137 |
exit;
|
138 |
exit;
|
| 138 |
}
|
139 |
}
|
| Line 139... |
Line 140... |
| 139 |
|
140 |
|
| 140 |
function verifierIdentiteEtRediriger() {
|
- |
|
| - |
|
141 |
function verifierIdentiteEtRediriger() {
|
| - |
|
142 |
// si on fait autre chose qu'un GET, on ne vérifie pas l'identité, car
|
| - |
|
143 |
// cela conduirait à une redirection en GET (avec le jeton), qui
|
| - |
|
144 |
// supprimerait les données du corps de la requête
|
| 141 |
|
145 |
if ($_SERVER['REQUEST_METHOD'] == "GET") {
|
| 142 |
if(empty($_COOKIE['sso_tentative_identification'])) {
|
146 |
if(empty($_COOKIE['sso_tentative_identification'])) {
|
| 143 |
|
147 |
|
| 144 |
if($this->communs_papyrus['pear_auth']->getAuth()) {
|
148 |
if($this->communs_papyrus['pear_auth']->getAuth()) {
|
| 145 |
|
149 |
|
| 146 |
$cookie_persistant_nom = session_name().'-memo';
|
150 |
$cookie_persistant_nom = session_name().'-memo';
|
| 147 |
$cookie_utilisateur_nom = session_name().'-utilisateur';
|
151 |
$cookie_utilisateur_nom = session_name().'-utilisateur';
|
| 148 |
|
152 |
|
| 149 |
// Si l'utilisateur est déjà connecté par pear
|
153 |
// Si l'utilisateur est d�j� connect� par pear
|
| 150 |
// on fait tout de même une opération de logout
|
154 |
// on fait tout de m�me une op�ration de logout
|
| 151 |
// pour coordonner la déconnection depuis une autre application
|
155 |
// pour coordonner la d�connection depuis une autre application
|
| 152 |
$this->communs_papyrus['pear_auth']->logout();
|
156 |
$this->communs_papyrus['pear_auth']->logout();
|
| 153 |
// Destruction du cookie de session de Papyrus : est ce utile?
|
157 |
// Destruction du cookie de session de Papyrus : est ce utile?
|
| 154 |
setcookie(session_name(), session_id(), time()-3600, '/');
|
158 |
setcookie(session_name(), session_id(), time()-3600, '/');
|
| 155 |
// Destruction du cookie de permanence de l'identitification de Papyrus
|
159 |
// Destruction du cookie de permanence de l'identitification de Papyrus
|
| 156 |
setcookie($cookie_persistant_nom, '', time()-3600, '/');
|
160 |
setcookie($cookie_persistant_nom, '', time()-3600, '/');
|
| 157 |
setcookie($cookie_utilisateur_nom, '', time()-3600, '/');
|
- |
|
| 158 |
}
|
- |
|
| 159 |
|
- |
|
| 160 |
$url_redirect = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
- |
|
| 161 |
$url = $this->annuaire_url."identite?redirect_url=".urlencode($url_redirect);
|
- |
|
| 162 |
|
- |
|
| 163 |
// une tentative par minute pour s'identifier suffit largement
|
- |
|
| 164 |
setcookie($this->cookie_tentative_identification, 1, time()+60, '/');
|
- |
|
| 165 |
|
- |
|
| 166 |
header('Location: '.$url);
|
- |
|
| 167 |
|
- |
|
| 168 |
} else {
|
- |
|
| 169 |
$jeton = $this->getToken();
|
- |
|
| 170 |
|
- |
|
| 171 |
if($jeton != null) {
|
- |
|
| 172 |
$jeton_decode = $this->decoderToken($jeton);
|
- |
|
| 173 |
|
- |
|
| 174 |
// Récupération du mot de passe pour remplir les infos de l'objet PEAR Auth
|
- |
|
| 175 |
$requete = 'SELECT '.$this->champ_mdp.' '.
|
- |
|
| 176 |
'FROM '.$this->bdd_annuaire.'.'.$this->table_annuaire.' '.
|
- |
|
| 177 |
'WHERE '.$this->champ_login.' = "'.$jeton_decode['sub'].'" ';
|
- |
|
| 178 |
|
- |
|
| 179 |
// TODO: normalement ça n'est jamais le cas mais que fait t'on si l'utilisateur n'existe pas
|
- |
|
| 180 |
// dans notre base de données ? (au pire il ne sera pas connecté)
|
- |
|
| 181 |
|
- |
|
| 182 |
$this->communs_papyrus['pear_auth']->username = $jeton_decode['sub'];
|
- |
|
| 183 |
$this->communs_papyrus['pear_auth']->password = $this->communs_papyrus['pear_db']->getOne($requete);
|
- |
|
| 184 |
|
- |
|
| 185 |
// Le mot de passe est déjà crypté dans la bdd donc il faut indiquer à pear de ne pas le re crytper
|
- |
|
| 186 |
if (isset($this->communs_papyrus['pear_auth']->storage_options)) {
|
- |
|
| 187 |
$this->communs_papyrus['pear_auth']->storage_options['cryptType'] = 'none';
|
161 |
setcookie($cookie_utilisateur_nom, '', time()-3600, '/');
|
| - |
|
162 |
}
|
| - |
|
163 |
|
| - |
|
164 |
$url_redirect = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
| - |
|
165 |
$url = $this->annuaire_url."identite?redirect_url=".urlencode($url_redirect);
|
| - |
|
166 |
|
| - |
|
167 |
// une tentative toutes les $this->delai_tentative_identification
|
| - |
|
168 |
setcookie($this->cookie_tentative_identification, 1, time() + $this->delai_tentative_identification, '/');
|
| - |
|
169 |
|
| - |
|
170 |
header('Location: '.$url);
|
| - |
|
171 |
|
| - |
|
172 |
} else {
|
| - |
|
173 |
$jeton = $this->getToken();
|
| - |
|
174 |
|
| - |
|
175 |
if($jeton != null) {
|
| - |
|
176 |
// Verification du jeton aupres de l'annuaire
|
| - |
|
177 |
$valide = $this->verifierToken($jeton);
|
| - |
|
178 |
if ($valide === true) {
|
| - |
|
179 |
$jeton_decode = $this->decoderToken($jeton);
|
| - |
|
180 |
|
| - |
|
181 |
// R�cup�ration du mot de passe pour remplir les infos de l'objet PEAR Auth
|
| - |
|
182 |
$requete = 'SELECT '.$this->champ_mdp.' '.
|
| - |
|
183 |
'FROM '.$this->bdd_annuaire.'.'.$this->table_annuaire.' '.
|
| - |
|
184 |
'WHERE '.$this->champ_login.' = "'.$jeton_decode['sub'].'" ';
|
| - |
|
185 |
|
| - |
|
186 |
// TODO: normalement �a n'est jamais le cas mais que fait t'on si l'utilisateur n'existe pas
|
| - |
|
187 |
// dans notre base de donn�es ? (au pire il ne sera pas connect�)
|
| - |
|
188 |
|
| - |
|
189 |
$this->communs_papyrus['pear_auth']->username = $jeton_decode['sub'];
|
| - |
|
190 |
$this->communs_papyrus['pear_auth']->password = $this->communs_papyrus['pear_db']->getOne($requete);
|
| - |
|
191 |
|
| - |
|
192 |
// Le mot de passe est d�j� crypt� dans la bdd donc il faut indiquer � pear de ne pas le re crytper
|
| - |
|
193 |
if (isset($this->communs_papyrus['pear_auth']->storage_options)) {
|
| - |
|
194 |
$this->communs_papyrus['pear_auth']->storage_options['cryptType'] = 'none';
|
| 188 |
}
|
195 |
}
|
| 189 |
if (isset($this->communs_papyrus['pear_auth']->storage->options)) {
|
196 |
if (isset($this->communs_papyrus['pear_auth']->storage->options)) {
|
| - |
|
197 |
$this->communs_papyrus['pear_auth']->storage->options['cryptType'] = 'none';
|
| - |
|
198 |
}
|
| 190 |
$this->communs_papyrus['pear_auth']->storage->options['cryptType'] = 'none';
|
199 |
}
|
| 191 |
}
|
200 |
}
|
| 192 |
}
|
201 |
}
|
| 193 |
}
|
202 |
}
|
| - |
|
203 |
}
|
| - |
|
204 |
|
| - |
|
205 |
/**
|
| - |
|
206 |
* Vérifie un jeton auprès de l'annuaire
|
| - |
|
207 |
*/
|
| - |
|
208 |
protected function verifierToken($token) {
|
| - |
|
209 |
$verificationServiceURL = $this->annuaire_url . "verifytoken";
|
| - |
|
210 |
$verificationServiceURL .= "?token=" . $token;
|
| - |
|
211 |
|
| - |
|
212 |
$info = file_get_contents($verificationServiceURL);
|
| - |
|
213 |
$info = json_decode($info, true);
|
| - |
|
214 |
|
| - |
|
215 |
return ($info === true);
|
| 194 |
}
|
216 |
}
|
| 195 |
}
|
217 |
}
|
| 196 |
?>
|
218 |
?>
|