Ejemplo n.º 1
0
 function is_user_logged_in()
 {
     $user = wp_get_current_user();
     // Start session if not started already
     if (!isset($_SESSION)) {
         session_start();
     }
     $mnoSession = new Maestrano_Sso_Session($_SESSION);
     // Check user exists and maestrano session is still valid
     if (!$user->exists() || !$mnoSession->isValid()) {
         return false;
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     try {
         $resp = new Maestrano_Saml_Response($_POST['SAMLResponse']);
         // Check if the Saml response is valid
         if ($resp->isValid()) {
             // Get the user as well as the user group
             $mnoUser = new Maestrano_Sso_User($resp);
             // intilize the user Model
             $userModel = new Maestrano_Sso_Model_User();
             // Find user in db by email if not exist then create locally
             $userResp = $userModel->findOrCreate($mnoUser);
             if ($userResp['id_employee'] > 0) {
                 //update the Cookie for prestashop
                 $cookie = new Cookie('psAdmin');
                 $cookie->id_employee = $userResp['id_employee'];
                 $cookie->email = $mnoUser->email;
                 $cookie->profile = $userResp['id_profile'];
                 $cookie->passwd = $userResp['passwd'];
                 $cookie->remote_addr = (int) ip2long(Tools::getRemoteAddr());
                 $cookie->last_activity = time();
                 // write the cookie in Prestashop session
                 $cookie->write();
                 // Once the user is created/identified, we store the maestrano session.
                 // This session will be used for single logout
                 $mnoSession = new Maestrano_Sso_Session($_SESSION, $mnoUser);
                 $mnoSession->save();
                 // If logged in redirect to admin dashboard startup page
                 if ($cookie->id_employee) {
                     $cookie = new Cookie('psAdDir');
                     Tools::redirect(Tools::getCurrentUrlProtocolPrefix() . Tools::getShopDomain() . __PS_BASE_URI__ . $cookie->admin_directory);
                 }
             }
         } else {
             echo '<p>There was an error during the authentication process.</p><br/>';
             echo '<p>Please try again. If issue persists please contact support@maestrano.com<p>';
             exit;
         }
     } catch (Exception $ex) {
         echo $ex;
         exit;
     }
 }
Ejemplo n.º 3
0
if (!isset($opts)) {
    $opts = array();
}
// Build SAML response
$samlResponse = new Maestrano_Saml_Response($_POST['SAMLResponse']);
try {
    if ($samlResponse->isValid()) {
        // Get the user as well as the user group
        $user = new Maestrano_Sso_User($samlResponse);
        // Get Maestrano User
        $sso_user = new MnoSsoUser($samlResponse, $opts);
        // Find or create the User
        $sso_user->findOrCreate();
        // Once the user is created/identified, we store the maestrano session.
        // This session will be used for single logout
        $mnoSession = new Maestrano_Sso_Session($_SESSION, $user);
        $mnoSession->save();
        // Redirect the user to previous or home page
        if (isset($_SESSION['mno_previous_uri'])) {
            header('Location: ' . $_SESSION['mno_previous_uri']);
        } else {
            header('Location: /wp-admin');
        }
    } else {
        echo 'There was an error during the authentication process.<br/>';
        echo 'Please try again. If issue persists please contact support@maestrano.com';
    }
} catch (Exception $e) {
    echo 'There was an error during the authentication process.<br/>';
    echo 'Please try again. If issue persists please contact support@maestrano.com';
}
Ejemplo n.º 4
0
 public function testIsValidWhenRecheckRequiredAndValidReturnsTrueAndSaveTheSession()
 {
     // Make sure any remote response is negative
     $date = new DateTime();
     $date->add(new DateInterval('PT100M'));
     $resp = array();
     $resp["valid"] = "true";
     $resp["recheck"] = $date->format(DateTime::ISO8601);
     $this->httpClient->setResponseStub($resp);
     // Set local recheck in the past
     $localRecheck = new DateTime();
     $localRecheck->sub(new DateInterval('PT1M'));
     $oldSubject = new Maestrano_Sso_Session($this->httpSession);
     $oldSubject->setRecheck($localRecheck);
     // test 1 - validity
     $this->assertTrue($oldSubject->isValid(false, $this->httpClient));
     // Create a new subject to test session persistence
     $this->subject = new Maestrano_Sso_Session($this->httpSession);
     // test 2 - session persistence
     $this->assertEquals($date->format(DateTime::ISO8601), $this->subject->getRecheck()->format(DateTime::ISO8601));
 }
Ejemplo n.º 5
0
<?php

if (!isset($_SESSION)) {
    session_start();
}
// Include Maestrano required libraries
require_once 'vendor/maestrano/maestrano-php/lib/Maestrano.php';
Maestrano::configure('maestrano.json');
// Check session validity and trigger SSO if not
if (Maestrano::sso()->isSsoEnabled()) {
    $mnoSession = new Maestrano_Sso_Session($_SESSION);
    if (!$mnoSession->isValid()) {
        $_SESSION['mno_previous_uri'] = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
        $req = new Maestrano_Saml_Request($_GET);
        header('Location: ' . $req->getRedirectUrl());
        exit;
    }
}
?>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>File Manager</title>
<link rel="stylesheet" type="text/css" href="styles/reset.css" />
<link rel="stylesheet" type="text/css" href="scripts/jquery.filetree/jqueryFileTree.css" />
<link rel="stylesheet" type="text/css" href="scripts/jquery.contextmenu/jquery.contextMenu-1.01.css" />
<link rel="stylesheet" type="text/css" href="scripts/custom-scrollbar-plugin/jquery.mCustomScrollbar.min.css" />
<style type="text/css">
	#loading-wrap {