1414include_once ( dirname (__FILE__ ) . '/../../UI/include/Authentication.php ' );
1515
1616/**
17- * ???
17+ * die Klasse CGate stellt gesicherte Zugriffe auf interne Komponenten bereit
18+ * hierzu gehört die Komponente DBGate, deren Tabellen die Profile, Benutzer und Regeln definieren
19+ *
20+ * Es gibt die Zugangsarten
21+ * -> noAuth = keine Authentifizierung
22+ * -> httpAuth = die HTTP-Standardanmeldung im Header unter "Authorization"
23+ * siehe https://de.wikipedia.org/wiki/HTTP-Authentifizierung
24+ * -> tokenAuth = die Angabe eines Tokens im Header unter "PRIVATE-TOKEN" (ist in der gateauth-Tabelle dann der "GA_login")
1825 */
1926class CGate extends Model
2027{
2128
2229 /**
23- * ???
30+ * Konstruktor
2431 */
2532 public function __construct ( )
2633 {
34+ // hier wird die Model-Klasse gestartet
2735 parent ::__construct ('' , dirname (__FILE__ ), $ this , false , false , array ('addRequestToParams ' =>true ));
2836 $ this ->run ();
2937 }
3038
3139 /**
32- * ???
40+ * diese Methode bearbeitet die Anfragen
3341 */
3442 public function request ( $ callName , $ input , $ params = array () )
3543 {
36- $ authType = 'noAuth ' ;
44+ $ authType = 'noAuth ' ; // das ist der default-Anmeldetyp, wenn kein anderer erkannt wird
3745 $ profile = $ params ['profile ' ];
3846 $ component = $ params ['component ' ];
3947 $ order = '/ ' .implode ('/ ' ,$ params ['path ' ]);
@@ -48,30 +56,36 @@ public function request( $callName, $input, $params = array() )
4856 $ login = $ headers ['PHP_AUTH_USER ' ];
4957 $ passwd = (isset ($ headers ['PHP_AUTH_PW ' ]) ? $ headers ['PHP_AUTH_PW ' ] : '' );
5058 $ authType = 'httpAuth ' ;
59+ } elseif (isset ($ headers ['HTTP_PRIVATE_TOKEN ' ])){
60+ // wir prüfen nun ob eine Authentifizierung über einen Token gewollt ist
61+ $ login = $ headers ['HTTP_PRIVATE_TOKEN ' ];
62+ $ passwd = null ;
63+ $ authType = 'tokenAuth ' ;
5164 }
5265
5366 $ positive = function ($ gateProfile , $ method , $ order , $ component , $ body , $ authType , $ login , $ passwd ) {
54- $ gateProfile = $ gateProfile [0 ];
67+ // wenn diese Funktion aufgerufen wird, dann existiert das Profil und dazu der Login.
68+ // Wir wissen aber noch nicht, ob er sich wirklich korrekt angemeldet hat, sofern noch ein Passwort
69+ // erforderlich ist
70+
71+ $ gateProfile = $ gateProfile [0 ]; // dieses Profil entstammt der Datenbank, wenn dort Profil und Nutzername gefunden wurden
5572
5673 $ auths = $ gateProfile ->getAuths ();
57- $ accepted = false ;
74+ $ accepted = false ; // dieses Flag gibt an, ob der Zugang erfolgreich gewährt wurde
5875
59- $ authentication = new Authentication ();
60-
6176 foreach ($ auths as $ auth ){
6277 $ authType = $ auth ->getType ();
63- if ($ authType == 'noAuth ' ){
78+ if ($ authType == 'tokenAuth ' ){
79+ // wir gelangen nur an diesen Punkt, wenn es den entsprechenden Token in der Datenbank als
80+ // 'login' gibt, daher ist der Zugang dann erlaubt
81+ $ accepted = true ;
82+ break ;
83+ } elseif ($ authType == 'noAuth ' ){
84+ // es ist keine weitere Prüfung erforderlich
6485 $ accepted = true ;
6586 break ;
6687 } elseif ($ authType == 'httpAuth ' ){
67- $ params = $ auth ->getParams ();
68-
69- /*$salt = '';
70- if (isset($params['salt'])){
71- $salt = $params['salt'];
72- }
73-
74- $hashedPasswd = $authentication->hashPassword($passwd, $salt);*/
88+ //$params = $auth->getParams();
7589
7690 if ($ auth ->getLogin () == $ login && $ auth ->getPasswd () == $ passwd ){
7791 $ accepted = true ;
@@ -95,6 +109,9 @@ public function request( $callName, $input, $params = array() )
95109
96110 // nun muss geprüft werden, ob der Aufruf auch erlaubt ist
97111 if (in_array ("Slim \\Slim " , get_declared_classes ())) {
112+
113+ // hier wird slim vorbereitet, um später für uns zu prüfen, ob eine der Regelpfade auf
114+ // unsere Anfrage passt
98115 $ router = new \Slim \Router ();
99116 foreach ($ rules as $ rule ){
100117 if ($ rule ->getType () == 'httpCall ' && $ rule ->getComponent () == $ component ){
@@ -153,6 +170,7 @@ public function request( $callName, $input, $params = array() )
153170 if ($ authType == 'noAuth ' ){
154171 return Model::call ('getComponentProfileWithAuth ' , array ('profName ' =>$ profile , 'authType ' =>$ authType , 'component ' =>$ component ), '' , 200 , $ positive , array ('method ' =>$ method , 'order ' =>$ order , 'component ' =>$ component , 'body ' =>$ input , 'authType ' =>$ authType , 'login ' =>$ login , 'passwd ' =>$ passwd ), 'Model::isRejected ' , array (), 'GateProfile ' );
155172 } else {
173+ // es ist eine andere Zugangsart, sodass auch geprüft wird, ob es eine Anmeldung mit dem entsprechenden Nutzernamen gibt
156174 return Model::call ('getComponentProfileWithAuthLogin ' , array ('login ' =>$ login , 'profName ' =>$ profile , 'authType ' =>$ authType , 'component ' =>$ component ), '' , 200 , $ positive , array ('method ' =>$ method , 'order ' =>$ order , 'component ' =>$ component , 'body ' =>$ input , 'authType ' =>$ authType , 'login ' =>$ login , 'passwd ' =>$ passwd ), 'Model::isRejected ' , array (), 'GateProfile ' );
157175 }
158176 }
0 commit comments