Skip to content

Commit

Permalink
Resolved bug in server version. Cleaned code.
Browse files Browse the repository at this point in the history
  • Loading branch information
subfission authored and subfission committed Dec 29, 2015
1 parent d48ded7 commit c1e3cf9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
9 changes: 7 additions & 2 deletions src/Subfission/Cas/CasManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]);
Expand All @@ -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' ]);

Expand Down
15 changes: 6 additions & 9 deletions src/Subfission/Cas/Middleware/CASAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,19 @@
'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.
| This should only be used for developmental purposes. getAttributes()
| will return null in this condition.
*/
'cas_masquerade' => env('CAS_MASQUERADE', '')



];

0 comments on commit c1e3cf9

Please sign in to comment.