Skip to content

Commit

Permalink
Switch SAML implementation to use namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dasgarner committed Jul 4, 2018
1 parent 59ec509 commit 3bb7718
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/Middleware/SAMLAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
namespace Xibo\Middleware;


use OneLogin\Saml2\Auth;
use OneLogin\Saml2\Error;
use OneLogin\Saml2\Settings;
use OneLogin\Saml2\Utils;
use Slim\Middleware;
use Xibo\Entity\User;
use Xibo\Exception\AccessDeniedException;
Expand Down Expand Up @@ -55,7 +59,7 @@ public function samlLogout()
isset($this->app->configService->samlSettings['workflow']['slo']) &&
$this->app->configService->samlSettings['workflow']['slo'] == true) {
// Initiate SAML SLO
$auth = new \OneLogin_Saml2_Auth($this->app->configService->samlSettings);
$auth = new Auth($this->app->configService->samlSettings);
$auth->logout();
} else {
$this->app->redirect($this->app->urlFor('logout'));
Expand All @@ -80,7 +84,7 @@ public function call()
$app->logoutRoute = 'saml.logout';

$app->get('/saml/metadata', function () {
$settings = new \OneLogin_Saml2_Settings($this->app->configService->samlSettings, true);
$settings = new Settings($this->app->configService->samlSettings, true);
$metadata = $settings->getSPMetadata();
$errors = $settings->validateMetadata($metadata);
if (empty($errors)) {
Expand All @@ -90,14 +94,14 @@ public function call()
} else {
throw new \Xibo\Exception\ConfigurationException(
'Invalid SP metadata: '.implode(', ', $errors),
\OneLogin_Saml2_Error::METADATA_SP_INVALID
Error::METADATA_SP_INVALID
);
}
});

$app->get('/saml/login', function () {
// Initiate SAML SSO
$auth = new \OneLogin_Saml2_Auth($this->app->configService->samlSettings);
$auth = new Auth($this->app->configService->samlSettings);
$auth->login();
});

Expand All @@ -110,21 +114,21 @@ public function call()
$app = $this->getApplication();

// Log some interesting things
$app->getLog()->debug('Arrived at the ACS route with own URL: ' . \OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery());
$app->getLog()->debug('Arrived at the ACS route with own URL: ' . Utils::getSelfRoutedURLNoQuery());

// Inject the POST parameters required by the SAML toolkit
$_POST = $this->app->request->post();

// Pull out the SAML settings
$samlSettings = $this->app->configService->samlSettings;

$auth = new \OneLogin_Saml2_Auth($samlSettings);
$auth = new Auth($samlSettings);
$auth->processResponse();

$errors = $auth->getErrors();

if (!empty($errors)) {
throw new \OneLogin_Saml2_Error(
throw new Error(
'SAML SSO failed: '.implode(', ', $errors) . '. Last Reason: ' . $auth->getLastErrorReason()
);
} else {
Expand Down Expand Up @@ -315,7 +319,7 @@ public function call()
// Inject the GET parameters required by the SAML toolkit
$_GET = $this->app->request->get();

$auth = new \OneLogin_Saml2_Auth($this->app->configService->samlSettings);
$auth = new Auth($this->app->configService->samlSettings);
$auth->processSLO(false, null, false, function() use ($app) {
// Grab a login controller
/** @var \Xibo\Controller\Login $loginController */
Expand Down Expand Up @@ -347,7 +351,7 @@ public function call()
}
else {
// Initiate SAML SSO
$auth = new \OneLogin_Saml2_Auth($this->app->configService->samlSettings);
$auth = new Auth($this->app->configService->samlSettings);
$auth->login();
}
};
Expand Down

0 comments on commit 3bb7718

Please sign in to comment.