11<?php
22
3+ namespace SimpleSAML \Module \drupalauth \Auth \Source ;
4+
5+ use SimpleSAML \Auth \Source ;
6+ use SimpleSAML \Module \drupalauth \ConfigHelper ;
7+
38/**
49 * Drupalath authentication source for using Drupal's login page.
510 *
9297 * @package drupalauth
9398 * @version $Id$
9499 */
95- class sspmod_drupalauth_Auth_Source_External extends SimpleSAML_Auth_Source {
100+ class External extends Source {
96101
97102 /**
98103 * Whether to turn on debugging
@@ -149,7 +154,7 @@ public function __construct($info, $config) {
149154
150155
151156 /* Get the configuration for this module */
152- $ drupalAuthConfig = new sspmod_drupalauth_ConfigHelper ($ config ,
157+ $ drupalAuthConfig = new ConfigHelper ($ config ,
153158 'Authentication source ' . var_export ($ this ->authId , TRUE ));
154159
155160 $ this ->debug = $ drupalAuthConfig ->getDebug ();
@@ -162,7 +167,7 @@ public function __construct($info, $config) {
162167 define ('DRUPAL_ROOT ' , $ drupalAuthConfig ->getDrupalroot ());
163168 }
164169
165- $ ssp_config = SimpleSAML_Configuration ::getInstance ();
170+ $ ssp_config = \ SimpleSAML \Configuration ::getInstance ();
166171 $ this ->cookie_path = '/ ' . $ ssp_config ->getValue ('baseurlpath ' );
167172 $ this ->cookie_salt = $ ssp_config ->getValue ('secretsalt ' );
168173
@@ -211,7 +216,7 @@ private function getUser() {
211216 if (sha1 ($ this ->cookie_salt . $ arrCookie [1 ]) == $ arrCookie [0 ]) {
212217 $ drupaluid = $ arrCookie [1 ];
213218 } else {
214- throw new SimpleSAML_Error_Exception ('Cookie hash invalid. This indicates either tampering or an out of date drupal4ssp module. ' );
219+ throw new \ SimpleSAML \ Error \ Exception ('Cookie hash invalid. This indicates either tampering or an out of date drupal4ssp module. ' );
215220 }
216221 }
217222
@@ -296,7 +301,7 @@ private function getUser() {
296301 }
297302 $ attributes [$ userAttrNames [$ userKey ]] = is_array ($ value ) ? $ value : array ($ value );
298303 }
299- catch (Exception $ e ) {
304+ catch (\ Exception $ e ) {
300305 watchdog_exception ('simplesaml ' , $ e );
301306 }
302307 }
@@ -317,7 +322,7 @@ private function getUser() {
317322 *
318323 * @param array &$state Information about the current authentication.
319324 */
320- public function authenticate (&$ state ) {
325+ public function authenticate (array &$ state ): void {
321326 assert (is_array ($ state ));
322327
323328 $ attributes = $ this ->getUser ();
@@ -357,14 +362,14 @@ public function authenticate(&$state) {
357362 * and restores it in another location, and thus bypasses steps in
358363 * the authentication process.
359364 */
360- $ stateId = SimpleSAML_Auth_State ::saveState ($ state , 'drupalauth:External ' );
365+ $ stateId = \ SimpleSAML \ Auth \State ::saveState ($ state , 'drupalauth:External ' );
361366
362367 /*
363368 * Now we generate an URL the user should return to after authentication.
364369 * We assume that whatever authentication page we send the user to has an
365370 * option to return the user to a specific page afterwards.
366371 */
367- $ returnTo = SimpleSAML_Module ::getModuleURL ('drupalauth/resume.php ' , array (
372+ $ returnTo = \ SimpleSAML \Module ::getModuleURL ('drupalauth/resume.php ' , array (
368373 'State ' => $ stateId ,
369374 ));
370375
@@ -383,7 +388,8 @@ public function authenticate(&$state) {
383388 * Note the 'ReturnTo' parameter. This must most likely be replaced with
384389 * the real name of the parameter for the login page.
385390 */
386- SimpleSAML_Utilities::redirect ($ authPage , array (
391+ $ http = new \SimpleSAML \Utils \HTTP ();
392+ $ http ->redirectTrustedURL ($ authPage , array (
387393 'ReturnTo ' => $ returnTo ,
388394 ));
389395
@@ -409,27 +415,27 @@ public static function resume() {
409415 * it in the 'State' request parameter.
410416 */
411417 if (!isset ($ _REQUEST ['State ' ])) {
412- throw new SimpleSAML_Error_BadRequest ('Missing "State" parameter. ' );
418+ throw new \ SimpleSAML \ Error \ BadRequest ('Missing "State" parameter. ' );
413419 }
414420 $ stateId = (string )$ _REQUEST ['State ' ];
415421
416422 /*
417423 * Once again, note the second parameter to the loadState function. This must
418424 * match the string we used in the saveState-call above.
419425 */
420- $ state = SimpleSAML_Auth_State ::loadState ($ stateId , 'drupalauth:External ' );
426+ $ state = \ SimpleSAML \ Auth \State ::loadState ($ stateId , 'drupalauth:External ' );
421427
422428 /*
423429 * Now we have the $state-array, and can use it to locate the authentication
424430 * source.
425431 */
426- $ source = SimpleSAML_Auth_Source ::getById ($ state ['drupalauth:AuthID ' ]);
432+ $ source = Source ::getById ($ state ['drupalauth:AuthID ' ]);
427433 if ($ source === NULL ) {
428434 /*
429435 * The only way this should fail is if we remove or rename the authentication source
430436 * while the user is at the login page.
431437 */
432- throw new SimpleSAML_Error_Exception ('Could not find authentication source with id ' . $ state [self :: AUTHID ]);
438+ throw new \ SimpleSAML \ Error \ Exception ('Could not find authentication source with id ' . $ state [' drupalauth:AuthID ' ]);
433439 }
434440
435441 /*
@@ -438,7 +444,7 @@ public static function resume() {
438444 * change config/authsources.php while an user is logging in.
439445 */
440446 if (! ($ source instanceof self)) {
441- throw new SimpleSAML_Error_Exception ('Authentication source type changed. ' );
447+ throw new \ SimpleSAML \ Error \ Exception ('Authentication source type changed. ' );
442448 }
443449
444450
@@ -455,7 +461,7 @@ public static function resume() {
455461 * Here we simply throw an exception, but we could also redirect the user back to the
456462 * login page.
457463 */
458- throw new SimpleSAML_Error_Exception ('User not authenticated after login page. ' );
464+ throw new \ SimpleSAML \ Error \ Exception ('User not authenticated after login page. ' );
459465 }
460466
461467 /*
@@ -464,7 +470,7 @@ public static function resume() {
464470 */
465471
466472 $ state ['Attributes ' ] = $ attributes ;
467- SimpleSAML_Auth_Source ::completeAuth ($ state );
473+ Source ::completeAuth ($ state );
468474
469475 /*
470476 * The completeAuth-function never returns, so we never get this far.
@@ -479,7 +485,7 @@ public static function resume() {
479485 *
480486 * @param array &$state The logout state array.
481487 */
482- public function logout (&$ state ) {
488+ public function logout (array &$ state ): void {
483489 assert (is_array ($ state ));
484490
485491 if (!session_id ()) {
0 commit comments