/** * @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; } }
/** * Construct the Maestrano_Sso_User object from a SAML response * * @param Maestrano_Saml_Response $saml_response * A SamlResponse object from Maestrano containing details * about the user being authenticated */ public function __construct($saml_response) { // Get assertion attributes $att = $saml_response->getAttributes(); // Group related information $this->groupUid = $att['group_uid']; $this->groupRole = $att['group_role']; // Extract mno session information $this->ssoSession = $att['mno_session']; $this->ssoSessionRecheck = new DateTime($att['mno_session_recheck']); // Extract user metadata $this->uid = $att['uid']; $this->virtualUid = $att['virtual_uid']; $this->email = $att['email']; $this->virtualEmail = $att['virtual_email']; $this->firstName = $att['name']; $this->lastName = $att['surname']; $this->country = $att['country']; $this->companyName = $att['company_name']; }
if (isset($_SESSION['mno_previous_url'])) { $previous_url = $_SESSION['mno_previous_url']; } session_unset(); session_destroy(); // Restart session and inject previous url if defined session_start(); if (isset($previous_url)) { $_SESSION['mno_previous_url'] = $previous_url; } // Options variable 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']);