Ejemplo n.º 1
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.º 2
0
 public function testSaveSavesTheMaestranoSessionInHttpSession()
 {
     $oldSubject = new Maestrano_Sso_Session($this->httpSession);
     $oldSubject->setUid($oldSubject->getUid() + "aaa");
     $oldSubject->setGroupUid($oldSubject->getGroupUid() + "aaa");
     $oldSubject->setSessionToken($oldSubject->getSessionToken() + "aaa");
     $date = new DateTime();
     $date->add(new DateInterval('PT100M'));
     $oldSubject->setRecheck($date);
     $oldSubject->save();
     $this->subject = new Maestrano_Sso_Session($this->httpSession);
     $this->assertEquals($oldSubject->getUid(), $this->subject->getUid());
     $this->assertEquals($oldSubject->getGroupUid(), $this->subject->getGroupUid());
     $this->assertEquals($oldSubject->getSessionToken(), $this->subject->getSessionToken());
     $this->assertEquals($oldSubject->getRecheck(), $this->subject->getRecheck());
 }
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';
}