Skip to content

Commit

Permalink
Changed to contracts instead of concrete classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zach Jetson committed May 20, 2015
1 parent bf558c2 commit 3a3a9b9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 52 deletions.
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('auth'), app('session'));
return new CasManager(app('auth'));
});
}
/**
Expand Down
19 changes: 7 additions & 12 deletions src/Subfission/Cas/Sso.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' ]);
}
Expand All @@ -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' ]);
Expand All @@ -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();
}
}

0 comments on commit 3a3a9b9

Please sign in to comment.