From bf558c2717f224ccf00e935ad58b01c1868bfb43 Mon Sep 17 00:00:00 2001 From: Zach Jetson Date: Wed, 20 May 2015 14:00:31 -0700 Subject: [PATCH 1/2] Adjusted code to follow laravel standards, removed excess session handling --- .gitignore | 2 +- src/Subfission/Cas/CasServiceProvider.php | 2 +- src/Subfission/Cas/Middleware/CASAuth.php | 15 ++++++--------- src/Subfission/Cas/Sso.php | 19 ++++++------------- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 166e25d..cf67674 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /bootstrap/compiled.php .env.*.php .env.php - +.idea diff --git a/src/Subfission/Cas/CasServiceProvider.php b/src/Subfission/Cas/CasServiceProvider.php index f96d7a2..f70e30d 100644 --- a/src/Subfission/Cas/CasServiceProvider.php +++ b/src/Subfission/Cas/CasServiceProvider.php @@ -32,7 +32,7 @@ public function register() { $this->app->bindShared('cas', function() { - return new CasManager(App::make('auth'), App::make('session')); + return new CasManager(app('auth'), app('session')); }); } /** diff --git a/src/Subfission/Cas/Middleware/CASAuth.php b/src/Subfission/Cas/Middleware/CASAuth.php index 86b5c9d..012224a 100644 --- a/src/Subfission/Cas/Middleware/CASAuth.php +++ b/src/Subfission/Cas/Middleware/CASAuth.php @@ -1,10 +1,7 @@ config = Config::get('cas'); - $this->auth = App::make('auth'); - $this->session = App::make('session'); + $this->auth = $auth; + $this->config = config('cas'); + $this->session = app('session'); } /** @@ -36,7 +33,7 @@ public function handle($request, Closure $next) } else { - $cas = (App::make('cas')); + $cas = app('cas'); $cas->authenticate(); } } diff --git a/src/Subfission/Cas/Sso.php b/src/Subfission/Cas/Sso.php index 2c01855..056417b 100644 --- a/src/Subfission/Cas/Sso.php +++ b/src/Subfission/Cas/Sso.php @@ -1,7 +1,7 @@ config = $config; $this->auth = $auth; - $this->session = $session; - $this->cas_init(); } @@ -107,7 +101,7 @@ public function logout() { $this->auth->logout(); } - $this->session->flush(); + Session::flush(); phpCAS::logout(); exit; } @@ -138,7 +132,6 @@ private function cas_init() // set login and logout URLs of the CAS server phpCAS::setServerLoginURL($this->config[ 'cas_login_url' ]); phpCAS::setServerLogoutURL($this->config[ 'cas_logout_url' ]); - } /** @@ -172,6 +165,7 @@ private function configureSslValidation() private function setRemoteUser() { $this->remoteUser = phpCAS::getUser(); + Session::put('cas_user', $this->remoteUser); } private function detect_authentication() @@ -182,5 +176,4 @@ private function detect_authentication() $this->setRemoteUser(); } } - } \ No newline at end of file From 3a3a9b9d297224b63fb381b681d3751db9d927f4 Mon Sep 17 00:00:00 2001 From: Zach Jetson Date: Wed, 20 May 2015 15:18:10 -0700 Subject: [PATCH 2/2] Changed to contracts instead of concrete classes --- src/Subfission/Cas/CasManager.php | 52 ++++++----------------- src/Subfission/Cas/CasServiceProvider.php | 3 +- src/Subfission/Cas/Sso.php | 19 +++------ 3 files changed, 22 insertions(+), 52 deletions(-) diff --git a/src/Subfission/Cas/CasManager.php b/src/Subfission/Cas/CasManager.php index fddb48c..9537ee4 100644 --- a/src/Subfission/Cas/CasManager.php +++ b/src/Subfission/Cas/CasManager.php @@ -1,39 +1,29 @@ config = Config::get('cas'); + $this->config = config('cas'); $this->auth = $auth; - $this->session = $session; } /** @@ -42,38 +32,24 @@ public function __construct(AuthManager $auth, SessionManager $session) * @param string $name * @return app\Cas\Directory */ - public function connection($name = null) + public function connection() { - if ( ! isset($this->connections[ $name ]) ) + if ( ! isset($this->connections) ) { - $this->connections[ $name ] = $this->createConnection($name); + $this->connections = $this->createConnection(); } - return $this->connections[ $name ]; + return $this->connections; } /** * Create the given connection by name. * - * @param string $name * @return app\Cas\Sso */ - protected function createConnection($name) - { - $connection = new Sso($this->config, $this->auth, $this->session); - - return $connection; - } - - - /** - * Get the default connection name. - * - * @return string - */ - protected function getDefaultConnection() + protected function createConnection() { - return 'default'; + return new Sso($this->config, $this->auth); } /** diff --git a/src/Subfission/Cas/CasServiceProvider.php b/src/Subfission/Cas/CasServiceProvider.php index f70e30d..e7b5ec6 100644 --- a/src/Subfission/Cas/CasServiceProvider.php +++ b/src/Subfission/Cas/CasServiceProvider.php @@ -1,7 +1,6 @@ app->bindShared('cas', function() { - return new CasManager(app('auth'), app('session')); + return new CasManager(app('auth')); }); } /** diff --git a/src/Subfission/Cas/Sso.php b/src/Subfission/Cas/Sso.php index 056417b..ef67010 100644 --- a/src/Subfission/Cas/Sso.php +++ b/src/Subfission/Cas/Sso.php @@ -51,10 +51,10 @@ public function __construct($config, Guard $auth) */ public function authenticate() { -// attempt to authenticate with CAS server + // attempt to authenticate with CAS server if ( phpCAS::forceAuthentication() ) { -// retrieve authenticated credentials + // retrieve authenticated credentials $this->setRemoteUser(); return true; @@ -117,19 +117,18 @@ public function logout() private function cas_init() { session_name( (isset($this->config['session_name']) ? $this->config['session_name'] : 'CASAuth' )); - // initialize CAS client $this->configureCasClient(); $this->configureSslValidation(); $this->detect_authentication(); -// set service URL for authorization with CAS server -//\phpCAS::setFixedServiceURL(); + // set service URL for authorization with CAS server + //\phpCAS::setFixedServiceURL(); if ( ! empty($this->config[ 'cas_service' ]) ) { phpCAS::allowProxyChain(new \CAS_ProxyChain_Any); } -// set login and logout URLs of the CAS server + // set login and logout URLs of the CAS server phpCAS::setServerLoginURL($this->config[ 'cas_login_url' ]); phpCAS::setServerLogoutURL($this->config[ 'cas_logout_url' ]); } @@ -146,7 +145,7 @@ private function configureCasClient() private function configureSslValidation() { -// set SSL validation for the CAS server + // set SSL validation for the CAS server if ( $this->config[ 'cas_validation' ] == 'self' ) { phpCAS::setCasServerCert($this->config[ 'cas_cert' ]); @@ -170,10 +169,6 @@ private function setRemoteUser() private function detect_authentication() { - $this->isAuthenticated = phpCAS::isAuthenticated(); - if ( $this->isAuthenticated ) - { - $this->setRemoteUser(); - } + if ( ($this->isAuthenticated = phpCAS::isAuthenticated()) ) $this->setRemoteUser(); } } \ No newline at end of file