-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAnnuaire.php
131 lines (107 loc) · 4.07 KB
/
Annuaire.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
require_once __DIR__ . '/AnnuaireInterface.php';
require_once __DIR__ . '/lib/SSO.php';
/**
* Impémente l'interface AnnuaireInterface en mettant en jeu un design-pattern
* "adapter" qui permet de changer d'implémentation par un simple paramètre
* dans la config
* https://fr.wikipedia.org/wiki/Adaptateur_(patron_de_conception)
*/
class Annuaire implements AnnuaireInterface {
/** Config en JSON */
protected $config = array();
public static $CHEMIN_CONFIG = __DIR__ . "/config/config.json";
/** Implémentation de l'interface AnnuaireInterface par un adapteur */
protected $adapter;
/** Bibliothèque SSO */
protected $SSO;
public function __construct() {
// config
if (file_exists(self::$CHEMIN_CONFIG)) {
$contenuConfig = file_get_contents(self::$CHEMIN_CONFIG);
// dé-commentarisation du pseudo-JSON @TODO valider cette stratégie cheloute
$contenuConfig = preg_replace('`^[\t ]*//.*\n`m', '', $contenuConfig);
$this->config = json_decode($contenuConfig, true);
} else {
throw new Exception("fichier de configuration " . self::$CHEMIN_CONFIG . " introuvable");
}
// SSO
$this->SSO = new SSO($this->config);
// adapteur
$adapterName = $this->config['adapter'];
$adapterPath = __DIR__ . '/adapters/' . $adapterName . '.php';
if (strpos($adapterName, "..") != false || $adapterName == '' || ! file_exists($adapterPath)) {
throw new Exception ("adapteur " . $adapterPath . " introuvable");
}
require $adapterPath;
// on passe la config à l'adapteur - à lui de stocker ses paramètres
// dans un endroit correct (adapters.nomdeladapteur par exemple)
$this->adapter = new $adapterName($this->config, $this->SSO);
}
/**
* Renvoie la lib SSO (pour utilisation par le service Auth notamment)
*/
public function getSSO() {
return $this->SSO;
}
public function idParCourriel($courriel) {
return $this->adapter->idParCourriel($courriel);
}
public function courrielParId($id) {
return $this->adapter->courrielParId($id);
}
public function courrielParLogin($login) {
return $this->adapter->courrielParLogin($login);
}
public function verifierCourrielOuConvertirDepuisLogin($courrielOuLogin) {
return $this->adapter->verifierCourrielOuConvertirDepuisLogin($courrielOuLogin);
}
public function getDateDerniereModifProfil($id) {
return $this->adapter->getDateDerniereModifProfil($id);
}
public function inscrireUtilisateur($donneesProfil) {
return $this->adapter->inscrireUtilisateur($donneesProfil);
}
public function getAllRoles() {
return $this->adapter->getAllRoles();
}
// -------------- rétrocompatibilité (11/2016) -------------------
/**
* Vérifie l'accès en se basant sur $id et $mdp si ceux-ci sont fournis; sinon,
* lit les valeurs transmises par l'authentification HTTP BASIC AUTH
*/
public function verifierAcces($courriel = null, $mdp = null) {
return $this->adapter->verifierAcces($courriel, $mdp);
}
/**
* Vérifie si un utilisateur ayant l'adresse email $courriel existe, et si
* son mot de passe est bien $mdpHache; retourne true si ces conditions
* sont réunies, false sinon
*/
public function identificationCourrielMdp($courriel, $mdp) {
return $this->adapter->identificationCourrielMdp($courriel, $mdp);
}
/**
* Vérifie si un utilisateur ayant l'adresse email $courriel existe, et si
* son mot de passe haché est bien $mdpHache; retourne true si ces conditions
* sont réunies, false sinon
*/
public function identificationCourrielMdpHache($courriel, $mdpHache) {
return $this->adapter->identificationCourrielMdpHache($courriel, $mdpHache);
}
/**
* Renvoie le nombre d'inscrits
*/
public function nbInscrits() {
return $this->adapter->nbInscrits();
}
public function infosParIds($unOuPlusieursIds) {
return $this->adapter->infosParIds($unOuPlusieursIds);
}
public function infosParCourriels($unOuPlusieursCourriels) {
return $this->adapter->infosParCourriels($unOuPlusieursCourriels);
}
public function envoyerMessage($destinataire, $sujet, $contenu, $expediteur=null) {
return $this->adapter->envoyerMessage($destinataire, $sujet, $contenu, $expediteur);
}
}