Subversion Repositories Applications.annuaire

Compare Revisions

No changes between revisions

Ignore whitespace Rev 560 → Rev 561

/trunk/jrest/services/Utilisateur.php
445,7 → 445,7
}
 
/**
* Permet d'identifier un utilisateur.
* Permet d'identifier un utilisateur, sans utiliser SSO (à l'ancienne).
* RESSOURCE : /utilisateur
* POST :
* - methode = 'connexion' : methode doit valoir 'connexion' pour connecter l'utilisateur.
/trunk/jrest/bibliotheque/JRestService.php
351,41 → 351,47
}
 
protected function authentifier() {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="www.tela-botanica.org"');
header('HTTP/1.0 401 Unauthorized');
header('Content-type: text/html; charset=UTF-8');
echo 'Accès interdit';
exit;
} else {
if ($this->verifierAcces()) {
return ;
} else {
if (JRest::$cgi === false) { // si on est en CGI, accès libre pour tous (pas trouvé mieux)
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="www.tela-botanica.org"');
header('HTTP/1.0 401 Unauthorized');
header('Content-type: text/html; charset=UTF-8');
echo 'Accès interdit';
exit ;
exit;
} else {
if ($this->verifierAcces()) {
return ;
} else {
header('WWW-Authenticate: Basic realm="www.tela-botanica.org"');
header('HTTP/1.0 401 Unauthorized');
header('Content-type: text/html; charset=UTF-8');
echo 'Accès interdit';
exit ;
}
}
}
}
 
protected function verifierAcces($id = null, $mdp = null) {
$id = is_null($id) ? $_SERVER['PHP_AUTH_USER'] : $id;
$mdp = is_null($mdp) ? $_SERVER['PHP_AUTH_PW'] : $mdp;
 
$requete = 'SELECT '.$this->config['database_ident']['ann_id'].' AS courriel '.
'FROM '.$this->config['database_ident']['database'].'.'.$this->config['database_ident']['annuaire'].' '.
'WHERE '.$this->config['database_ident']['ann_id'].' = '.$this->bdd->quote($id).' '.
' AND '.$this->config['database_ident']['ann_pwd'].' = '.$this->config['database_ident']['pass_crypt_funct'].'('.$this->bdd->quote($mdp).')' ;
$resultat = $this->bdd->query($requete)->fetch();
 
$identifie = false;
if (isset($resultat['courriel'])) {
$identifie = true;
if (JRest::$cgi === false) { // si on est en CGI, accès libre pour tous (pas trouvé mieux)
$id = is_null($id) ? $_SERVER['PHP_AUTH_USER'] : $id;
$mdp = is_null($mdp) ? $_SERVER['PHP_AUTH_PW'] : $mdp;
$requete = 'SELECT '.$this->config['database_ident']['ann_id'].' AS courriel '.
'FROM '.$this->config['database_ident']['database'].'.'.$this->config['database_ident']['annuaire'].' '.
'WHERE '.$this->config['database_ident']['ann_id'].' = '.$this->bdd->quote($id).' '.
' AND '.$this->config['database_ident']['ann_pwd'].' = '.$this->config['database_ident']['pass_crypt_funct'].'('.$this->bdd->quote($mdp).')' ;
$resultat = $this->bdd->query($requete)->fetch();
$identifie = false;
if (isset($resultat['courriel'])) {
$identifie = true;
}
return $identifie;
} else {
return true; // ça fait un peu mal...
}
return $identifie;
}
 
/**
398,9 → 404,11
protected function authentificationHttpSimple() {
$autorise = true;
// contrôle d'accès
$nomUtil = $_SERVER['PHP_AUTH_USER'];
$mdp = $_SERVER['PHP_AUTH_PW'];
$autorise = (($nomUtil == $this->config['database_ident']['username']) && ($mdp == $this->config['database_ident']['password']));
if (JRest::$cgi === false) { // si on est en CGI, accès libre pour tous (pas trouvé mieux)
$nomUtil = $_SERVER['PHP_AUTH_USER'];
$mdp = $_SERVER['PHP_AUTH_PW'];
$autorise = (($nomUtil == $this->config['database_ident']['username']) && ($mdp == $this->config['database_ident']['password']));
}
// entêtes HTTP
if (! $autorise) {
header('WWW-Authenticate: Basic realm="Annuaire de Tela Botanica"');
/trunk/jrest/JRest.php
23,6 → 23,9
/** Identifiant unique resource. */
private $uid = NULL;
 
/** True si le type d'api est CGI / FastCGI, false si on a un module Apache... ou autre ? */
public static $cgi;
 
/**
* Constructor. Parses the configuration file "JRest.ini", grabs any request data sent, records the HTTP
* request method used and parses the request URL to find out the requested resource
63,6 → 66,10
}
}
 
// détection du type d'API : CGI ou module Apache - le CGI ne permet pas
// d'utiliser l'authentification HTTP Basic :-(
self::$cgi = substr(php_sapi_name(), 0, 3) == 'cgi';
 
$this->method = $_SERVER['REQUEST_METHOD'];
} else {
trigger_error('I require the server variables REQUEST_URI, REQUEST_METHOD and QUERY_STRING to work.', E_USER_ERROR);
261,10 → 268,12
* Send a HTTP 401 response header.
*/
private function unauthorized($realm = 'JRest') {
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
header('WWW-Authenticate: Basic realm="'.$realm.'"');
if (self::$cgi === false) { // si on est en CGI, accès libre pour tous (pas trouvé mieux)
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
header('WWW-Authenticate: Basic realm="'.$realm.'"');
}
header('HTTP/1.0 401 Unauthorized');
}
header('HTTP/1.0 401 Unauthorized');
}
 
/**
/trunk/.
Property changes:
Modified: svn:mergeinfo
Merged /branches/v1.4-baleine:r560