Skip to content

Commit

Permalink
Merge pull request #6 from subfission/develop
Browse files Browse the repository at this point in the history
Updated Cas for contracts, removed duplicates and typos
  • Loading branch information
subfission committed May 20, 2015
2 parents 09d2d34 + 3a3a9b9 commit 989fe17
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/bootstrap/compiled.php
.env.*.php
.env.php

.idea
52 changes: 14 additions & 38 deletions src/Subfission/Cas/CasManager.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
<?php namespace Subfission\Cas;

use Config;
use Illuminate\Auth\AuthManager;
use Illuminate\Session\SessionManager;
use Illuminate\Support\Manager;
use Illuminate\Contracts\Auth\Guard;

class CasManager {

var $config;
/**
* The active connection instances.
* The active connection instance.
*
* @var array
* @var string
*/
protected $connections = array();
protected $connections;
/**
* @var \Illuminate\Auth\AuthManager
* @var \Illuminate\Contracts\Auth\Guard
*/
private $auth;
/**
* @var \Illuminate\Session\SessionManager
*/
private $session;

/**
* @param array $config
* @param AuthManager $auth
* @param SessionManager $session
* @param Guard $auth
*/

public function __construct(AuthManager $auth, SessionManager $session)
public function __construct(Guard $auth)
{
$this->config = Config::get('cas');
$this->config = config('cas');
$this->auth = $auth;
$this->session = $session;
}

/**
Expand All @@ -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);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Subfission/Cas/CasServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php namespace Subfission\Cas;

use Illuminate\Support\ServiceProvider;
use App;

class CasServiceProvider extends ServiceProvider {

Expand Down Expand Up @@ -32,7 +31,7 @@ public function register()
{
$this->app->bindShared('cas', function()
{
return new CasManager(App::make('auth'), App::make('session'));
return new CasManager(app('auth'));
});
}
/**
Expand Down
15 changes: 6 additions & 9 deletions src/Subfission/Cas/Middleware/CASAuth.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
<?php namespace Subfission\Cas\Middleware;

use App;
use Config;
use Closure;
use Illuminate\Auth\AuthManager;
use Illuminate\Session\SessionManager;
use Illuminate\Contracts\Auth\Guard;

class CASAuth {

protected $config;
protected $auth;
protected $session;

public function __construct(AuthManager $auth, SessionManager $session)
public function __construct(Guard $auth)
{
$this->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');
}

/**
Expand All @@ -36,7 +33,7 @@ public function handle($request, Closure $next)
}
else
{
$cas = (App::make('cas'));
$cas = app('cas');
$cas->authenticate();
}
}
Expand Down
38 changes: 13 additions & 25 deletions src/Subfission/Cas/Sso.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php namespace Subfission\Cas;

use Illuminate\Auth\AuthManager;
use Illuminate\Session\SessionManager;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Support\Facades\Session;
use phpCAS;

/**
Expand All @@ -27,23 +27,17 @@ class Sso {
* @var \Illuminate\Auth\AuthManager
*/
private $auth;
/**
* @var \Illuminate\Session\SessionManager
*/
private $session;

private $isAuthenticated;

/**
* @param $config
* @param Auth $auth
* @param Session $session
*/
public function __construct($config, AuthManager $auth, SessionManager $session)
public function __construct($config, Guard $auth)
{
$this->config = $config;
$this->auth = $auth;
$this->session = $session;

$this->cas_init();
}

Expand All @@ -57,10 +51,10 @@ public function __construct($config, AuthManager $auth, SessionManager $session)
*/
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;
Expand Down Expand Up @@ -107,7 +101,7 @@ public function logout()
{
$this->auth->logout();
}
$this->session->flush();
Session::flush();
phpCAS::logout();
exit;
}
Expand All @@ -123,22 +117,20 @@ 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' ]);

}

/**
Expand All @@ -153,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' ]);
Expand All @@ -172,15 +164,11 @@ private function configureSslValidation()
private function setRemoteUser()
{
$this->remoteUser = phpCAS::getUser();
Session::put('cas_user', $this->remoteUser);
}

private function detect_authentication()
{
$this->isAuthenticated = phpCAS::isAuthenticated();
if ( $this->isAuthenticated )
{
$this->setRemoteUser();
}
if ( ($this->isAuthenticated = phpCAS::isAuthenticated()) ) $this->setRemoteUser();
}

}

0 comments on commit 989fe17

Please sign in to comment.