From 4b3fec9a242083ed7a861cf69c795be2590c590e Mon Sep 17 00:00:00 2001
From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de>
Date: Mon, 12 Sep 2022 14:06:11 +0000
Subject: [PATCH] update phpCAS API usage for phpCAS 1.5.0, fixes #1573

Closes #1573

Merge request studip/studip!1003
---
 app/controllers/cas.php                       |  3 +-
 .../auth_plugins/StudipAuthCAS.class.php      | 29 ++++++++-----------
 2 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/app/controllers/cas.php b/app/controllers/cas.php
index e12443c6286..37cf6804452 100644
--- a/app/controllers/cas.php
+++ b/app/controllers/cas.php
@@ -12,7 +12,6 @@
  * @category    Stud.IP
  */
 
-require_once 'composer/jasig/phpcas/CAS.php';
 require_once 'lib/classes/cas/CAS_PGTStorage_Cache.php';
 
 class CasController extends StudipController
@@ -25,7 +24,7 @@ class CasController extends StudipController
         $pgt = Request::get('pgtId');
         $pgt_iou = Request::get('pgtIou');
         $cas_config = $GLOBALS['STUDIP_AUTH_CONFIG_CAS'];
-        $cas = new CAS_Client(CAS_VERSION_2_0, true, $cas_config['host'], $cas_config['port'], $cas_config['uri'], false);
+        $cas = phpCAS::proxy(CAS_VERSION_2_0, $cas_config['host'], $cas_config['port'], $cas_config['uri'], false);
         $pgt_storage = new CAS_PGTStorage_Cache($cas);
         $pgt_storage->write($pgt, $pgt_iou);
         $this->render_nothing();
diff --git a/lib/classes/auth_plugins/StudipAuthCAS.class.php b/lib/classes/auth_plugins/StudipAuthCAS.class.php
index d87aada3529..79c3cf8e223 100644
--- a/lib/classes/auth_plugins/StudipAuthCAS.class.php
+++ b/lib/classes/auth_plugins/StudipAuthCAS.class.php
@@ -1,7 +1,4 @@
 <?php
-# Lifter007: TODO
-# Lifter003: TODO
-# Lifter010: TODO
 /**
  * Stud.IP authentication against CAS Server
  *
@@ -10,18 +7,15 @@
  * @package
  */
 
-require_once 'composer/jasig/phpcas/CAS.php';
 require_once 'lib/classes/cas/CAS_PGTStorage_Cache.php';
 
 class StudipAuthCAS extends StudipAuthSSO
 {
-
     public $host;
     public $port;
     public $uri;
     public $cacert;
 
-    public $cas;
     public $userdata;
 
     /**
@@ -37,18 +31,19 @@ class StudipAuthCAS extends StudipAuthSSO
             $this->login_description = _('für Single Sign On mit CAS');
         }
         if (Request::get('sso') === $this->plugin_name) {
-            $this->cas = new CAS_Client(CAS_VERSION_2_0, $this->proxy, $this->host, $this->port, $this->uri, false);
-
             if ($this->proxy) {
                 URLHelper::setBaseUrl($GLOBALS['ABSOLUTE_URI_STUDIP']);
-                $this->cas->setPGTStorage(new CAS_PGTStorage_Cache($this->cas));
-                $this->cas->setCallbackURL(URLHelper::getURL('dispatch.php/cas/proxy'));
+                $cas = phpCAS::proxy(CAS_VERSION_2_0, $this->host, $this->port, $this->uri, false);
+                phpCAS::setPGTStorage(new CAS_PGTStorage_Cache($cas));
+                phpCAS::setFixedCallbackURL(URLHelper::getURL('dispatch.php/cas/proxy'));
+            } else {
+                phpCAS::client(CAS_VERSION_2_0, $this->host, $this->port, $this->uri, false);
             }
 
             if (isset($this->cacert)) {
-                $this->cas->setCasServerCACert($this->cacert);
+                phpCAS::setCasServerCACert($this->cacert);
             } else {
-                $this->cas->setNoCasServerValidation();
+                phpCAS::setNoCasServerValidation();
             }
         }
     }
@@ -58,7 +53,7 @@ class StudipAuthCAS extends StudipAuthSSO
      */
     function getUser()
     {
-        return $this->cas->getUser();
+        return phpCAS::getUser();
     }
 
     /**
@@ -67,7 +62,7 @@ class StudipAuthCAS extends StudipAuthSSO
      */
     function verifyUsername($username)
     {
-        $this->cas->forceAuthentication();
+        phpCAS::forceAuthentication();
         return $this->getUser();
     }
 
@@ -82,13 +77,13 @@ class StudipAuthCAS extends StudipAuthSSO
         if (empty($this->userdata)) {
             $this->userdata = new $userdataclassname();
         }
-        return $this->userdata->getUserData($key, $this->cas->getUser());
+        return $this->userdata->getUserData($key, phpCAS::getUser());
     }
 
     function logout()
     {
         // do a global cas logout
-        $this->cas = new CAS_Client(CAS_VERSION_2_0, false, $this->host, $this->port, $this->uri, false);
-        $this->cas->logout();
+        phpCAS::client(CAS_VERSION_2_0, $this->host, $this->port, $this->uri, false);
+        phpCAS::logout();
     }
 }
-- 
GitLab