From c1e3cf92e53a16ec47990276adbbee60d30cf96d Mon Sep 17 00:00:00 2001 From: subfission Date: Tue, 29 Dec 2015 11:20:49 -0700 Subject: [PATCH] Resolved bug in server version. Cleaned code. --- src/Subfission/Cas/CasManager.php | 9 +++++++-- src/Subfission/Cas/Middleware/CASAuth.php | 15 ++++++--------- src/config/config.php | 11 ++++++++--- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Subfission/Cas/CasManager.php b/src/Subfission/Cas/CasManager.php index 36ebe61..0b676e7 100644 --- a/src/Subfission/Cas/CasManager.php +++ b/src/Subfission/Cas/CasManager.php @@ -13,7 +13,12 @@ class CasManager public function __construct(array $config) { $this->parseConfig($config); - phpCAS::setDebug($this->config[ 'cas_debug' ]); + if ($this->config[ 'cas_debug' ] === true) { + phpCAS::setDebug(); + } else { + phpCAS::setDebug($this->config[ 'cas_debug' ]); + } + phpCAS::setVerbose($this->config[ 'cas_verbose_errors' ]); session_name($this->config[ 'cas_session_name' ]); @@ -33,7 +38,7 @@ public function __construct(array $config) */ protected function configureCas($method = 'client') { - $server_version = $this->config[ 'cas_enable_saml' ] ? 'CAS_VERSION_2_0' : 'SAML_VERSION_1_1'; + $server_version = $this->config[ 'cas_enable_saml' ] ? SAML_VERSION_1_1 : CAS_VERSION_2_0; phpCAS::$method($server_version, $this->config[ 'cas_hostname' ], (int)$this->config[ 'cas_port' ], $this->config[ 'cas_uri' ], $this->config[ 'cas_control_session' ]); diff --git a/src/Subfission/Cas/Middleware/CASAuth.php b/src/Subfission/Cas/Middleware/CASAuth.php index d44cc4d..1f3847b 100644 --- a/src/Subfission/Cas/Middleware/CASAuth.php +++ b/src/Subfission/Cas/Middleware/CASAuth.php @@ -5,15 +5,13 @@ class CASAuth { - protected $config; protected $auth; - protected $session; + protected $cas; public function __construct(Guard $auth) { $this->auth = $auth; - $this->config = config('cas'); - $this->session = app('session'); + $this->cas = app('cas'); } /** @@ -25,17 +23,16 @@ public function __construct(Guard $auth) */ public function handle($request, Closure $next) { - if ($this->auth->guest()) + if ($this->auth->guest() || ! $this->cas->isAuthenticated()) { if ($request->ajax()) { return response('Unauthorized.', 401); } // We setup CAS here to reduce the amount of objects we need to build at runtime. This - // way, we only create the CAS calls if the user has not yet authenticated. - $cas = app('cas'); - $cas->authenticate(); - session()->put('cas_user', $cas->User()); + // way, we only create the CAS calls only if the user has not yet authenticated. + $this->cas->authenticate(); + session()->put('cas_user', $this->cas->User()); } return $next($request); diff --git a/src/config/config.php b/src/config/config.php index bd68f4e..bff7739 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -132,6 +132,14 @@ 'cas_debug' => env('CAS_DEBUG', false), + /* + |-------------------------------------------------------------------------- + | Enable Verbose error messages. Not recommended for production. + | true | false + |-------------------------------------------------------------------------- + */ + 'cas_verbose_errors' => env('CAS_VERBOSE_ERRORS', false), + /* |-------------------------------------------------------------------------- | This will cause CAS to skip authentication and assume this user id. @@ -139,7 +147,4 @@ | will return null in this condition. */ 'cas_masquerade' => env('CAS_MASQUERADE', '') - - - ]; \ No newline at end of file