/** * @see FrontController::initContent() */ public function initContent() { parent::initContent(); try { if (!Maestrano::param('connec.enabled')) { return false; } $client = new Maestrano_Connec_Client(); $notification = json_decode(file_get_contents('php://input'), false); $entity_name = strtoupper(trim($notification->entity)); $entity_id = $notification->id; switch ($entity_name) { case "PERSONS": $customerMapper = new CustomerMapper(); $customerMapper->fetchConnecResource($entity_id); break; case "ITEMS": $productMapper = new ProductMapper(); $productMapper->fetchConnecResource($entity_id); break; case "TAXCODES": $taxMapper = new TaxMapper(); $taxMapper->fetchConnecResource($entity_id); break; } } catch (Exception $e) { error_log("Caught exception in subscribe " . json_encode($e->getMessage())); } }
public static function newWithPreset($preset, $saml_response, $settings = null) { if ($settings == null) { $settings = Maestrano::with($preset)->sso()->getSamlSettings(); } return new Maestrano_Saml_Response($get_params, $settings); }
/** * Initializes the Test Suite */ public function setUp() { $this->config = array('environment' => 'production', 'app' => array('host' => "https://mysuperapp.com"), 'api' => array('id' => "myappid", 'key' => "myappkey", 'group_id' => "mygroupid", 'host' => 'https://someapihost.com'), 'sso' => array('init_path' => "/mno/init_path.php", 'consume_path' => "/mno/consume_path.php", 'idp' => "https://mysuperidp.com", 'idm' => "https://mysuperidm.com", 'x509_fingerprint' => "some-x509_fingerprint", 'x509_certificate' => "some-x509_certificate"), 'connec' => array('enabled' => true, 'host' => 'http://connec.maestrano.io', 'base_path' => '/api', 'v2_path' => '/v2', 'reports_path' => '/reports'), 'webhook' => array('account' => array('groups_path' => "/mno/groups/:id", 'group_users_path' => "/mno/groups/:group_id/users/:id"), 'connec' => array('enabled' => true, 'initialization_path' => "/mno/connec/initialization", 'notifications_path' => "/mno/connec/notifications", 'subscriptions' => array('organizations' => true, 'people' => true)))); $preset = 'some-marketplace'; Maestrano::with($preset)->configure($this->config); $this->ssoService = Maestrano::ssoWithPreset($preset); }
/** * Configure Maestrano presets with fetched marketplaces * * @param $conf_array array Array containing the environments to load */ public static function loadMultipleMarketplaces($conf_array) { // Load every environments foreach ($conf_array as $marketplace) { Maestrano::with($marketplace['marketplace'])->configure($marketplace); } }
/** * Construct the Request object. * * @param $get_params the GET parameters associative array */ public function __construct($get_params = array(), $settings = null) { if ($settings == null) { $settings = Maestrano::sso()->getSamlSettings(); } $this->_settings = $settings; $this->_get_params = $get_params; }
/** * Return the real email if Maestrano Sso Creation Mode is set * to "real" and the Virtual email otherwise ("virtual" mode) * @return */ public function toEmail() { if (Maestrano::param('sso.creation_mode') == "real") { return $this->email; } else { return $this->virtualEmail; } }
/** * Construct the response object. * * @param string $saml_response A UUEncoded SAML response from the IdP. */ public function __construct($saml_response, $settings = null) { if ($settings == null) { $settings = Maestrano::sso()->getSamlSettings(); } $this->_settings = $settings; $this->assertion = base64_decode($saml_response); $this->document = new DOMDocument(); $this->document->loadXML($this->assertion); }
function mno_redirect_user_from_login() { if ($_GET["loggedout"] == 'true') { // Redirect to blog home page $redirect = '/'; } else { // Login - Trigger SSO $redirect = Maestrano::sso()->getInitPath(); } echo "<script type='text/javascript'>window.location = '{$redirect}';</script>"; }
public function __construct() { if (Maestrano::sso()->isSsoEnabled()) { if (!$this->isAdminLogged()) { $samlController = array('init', 'consume'); if (!in_array(Tools::getValue('controller'), $samlController)) { // calling the function generate the cookie for admin directory $this->cookieForAdminDirectory(); Tools::redirect(Tools::getCurrentUrlProtocolPrefix() . Tools::getShopDomain() . __PS_BASE_URI__ . Maestrano::sso()->getInitPath()); } } } }
public function __construct() { $this->name = 'maestranointegration'; $this->tab = 'administration'; $this->version = '1.6.4'; $this->author = 'PrestaShop'; $this->need_instance = 0; $this->bootstrap = true; // Check the Maestrano class exit othewise throws error if (class_exists($this->maestranoClass)) { // Include the Maestrano config file. Maestrano::configure(dirname(__FILE__) . '/' . $this->maestranoConfig); $mn = new MaestranoSso(); } else { $this->warning = $this->l($this->maestranoClass . " Class doesn't Exist."); } parent::__construct(); $this->displayName = $this->l('Maestrano integration'); $this->description = $this->l('Maestrano SSO integration and data'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); if (!Configuration::get('maestrano')) { $this->warning = $this->l('No name provided'); } }
<?php // Include Maestrano required libraries require_once dirname(__FILE__) . '/lib/Maestrano.php'; require_once dirname(__FILE__) . '/connec/init.php'; // Maestrano Config Include Maestrano::configure(dirname(__FILE__) . '/maestrano.json');
public function setUp() { Maestrano::configure(array('environment' => 'production')); $this->settings = SamlTestHelper::getXmlSecSamlTestSettings(); }
/** * @param number $errno * @param string $message * @throws Maestrano_Api_ConnectionError */ public function handleCurlError($errno, $message) { $apiBase = Maestrano::param('api.host'); switch ($errno) { case CURLE_COULDNT_CONNECT: case CURLE_COULDNT_RESOLVE_HOST: case CURLE_OPERATION_TIMEOUTED: $msg = "Could not connect to Maestrano ({$apiBase}). Please check your " . "internet connection and try again. If this problem persists, " . "you should check Maestrano's service status at " . "https://twitter.com/Maestrano, or"; break; case CURLE_SSL_CACERT: case CURLE_SSL_PEER_CERTIFICATE: $msg = "Could not verify Maestrano's SSL certificate. Please make sure " . "that your network is not intercepting certificates. " . "(Try going to {$apiBase} in your browser.) " . "If this problem persists,"; break; default: $msg = "Unexpected error communicating with Maestrano. " . "If this problem persists,"; } $msg .= " let us know at support@Maestrano.com."; $msg .= "\n\n(Network error [errno {$errno}]: {$message})"; throw new Maestrano_Api_ConnectionError($msg); }
public function processLocalUpdate($model, $pushToConnec = true, $delete = false, $saveResult = false) { $pushToConnec = $pushToConnec && Maestrano::param('connec.enabled'); error_log("process local update entity={$this->connec_entity_name}, local_id=" . $this->getId($model) . ", pushToConnec={$pushToConnec}, delete={$delete}"); if ($pushToConnec) { $this->pushToConnec($model, $saveResult); } if ($delete) { $this->flagAsDeleted($model); } }
<?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 {
public function testToMetadata() { Maestrano::configure($this->config); $expected = array('environment' => $this->config['environment'], 'app' => array('host' => $this->config['app']['host']), 'api' => array('id' => $this->config['api']['id'], 'version' => Maestrano::VERSION, 'verify_ssl_certs' => false, 'lang' => 'php', 'lang_version' => phpversion() . " " . php_uname(), 'host' => Maestrano::$EVT_CONFIG[$this->config['environment']]['api.host'], 'base' => Maestrano::$EVT_CONFIG[$this->config['environment']]['api.base']), 'sso' => array('enabled' => true, 'slo_enabled' => true, 'init_path' => $this->config['sso']['init_path'], 'consume_path' => $this->config['sso']['consume_path'], 'creation_mode' => 'real', 'idm' => $this->config['sso']['idm'], 'idp' => $this->config['sso']['idp'], 'name_id_format' => Maestrano::$EVT_CONFIG[$this->config['environment']]['sso.name_id_format'], 'x509_fingerprint' => Maestrano::$EVT_CONFIG[$this->config['environment']]['sso.x509_fingerprint'], 'x509_certificate' => Maestrano::$EVT_CONFIG[$this->config['environment']]['sso.x509_certificate']), 'connec' => array('enabled' => $this->config['connec']['enabled'], 'host' => $this->config['connec']['host'], 'base_path' => $this->config['connec']['base_path'], 'v2_path' => $this->config['connec']['v2_path'], 'reports_path' => $this->config['connec']['reports_path']), 'webhook' => array('account' => array('groups_path' => $this->config['webhook']['account']['groups_path'], 'group_users_path' => $this->config['webhook']['account']['group_users_path']), 'connec' => array('initialization_path' => $this->config['webhook']['connec']['initialization_path'], 'notifications_path' => $this->config['webhook']['connec']['notifications_path'], 'subscriptions' => $this->config['webhook']['connec']['subscriptions']))); $this->assertEquals(json_encode($expected), Maestrano::toMetadata()); }
public function testLoadMultipleMarketplaces() { $fromServer = json_decode('[ { "marketplace": "maestrano-uat", "environment": "local", "app": { "host": "http://php-demoapp.maestrano.io" }, "api": { "id": "e30ac587-54ee-429d-92ff-66efdd1abf32", "key": "6z3KsJaDfyFZ3VNTxIVzEg" } }, { "marketplace": "maestrano-prod", "environment": "local", "app": { "host": "http://php-demoapp.maestrano.io" }, "api": { "id": "e30ac587-54ee-429d-92ff-66efdd1abf32", "key": "6z3KsJaDfyFZ3VNTxIVzEg" } } ]', true); Maestrano_Config_Client::loadMultipleMarketplaces($fromServer); $this->assertEquals(Maestrano::with('maestrano-uat')->param('environment'), 'local'); $this->assertEquals(Maestrano::with('maestrano-prod')->param('environment'), 'local'); }
/** * Initializes the Test Suite */ public function setUp() { Maestrano::with('some-preset')->configure(array('environment' => 'test', 'api' => array('id' => 'app-1', 'key' => 'gfcmbu8269wyi0hjazk4t7o1sndpvrqxl53e1'))); }
/** * Initializes the Test Suite */ public function setUp() { Maestrano::configure(array('environment' => 'production')); $this->samlResp = new SamlMnoRespStub(); $this->subject = new Maestrano_Sso_Group($this->samlResp); }
/** * Perform check to see if session is valid * Check is only performed if current time is after * the recheck timestamp * If a remote check is performed then the mno_session_recheck * timestamp is updated in session. * * @return boolean the validity of the session */ public function isValid($ifSession = false, $httpClient = null) { $svc = Maestrano::sso(); if (!$svc->isSloEnabled()) { return true; } if ($ifSession) { return true; } if (!$this->ssoTokenExists()) { return false; } if ($this->isRemoteCheckRequired()) { if ($this->performRemoteCheck($httpClient)) { $this->save(); return true; } else { return false; } } else { return true; } }
<?php //----------------------------------------------- // Define root folder //----------------------------------------------- if (!defined('MAESTRANO_ROOT')) { define("MAESTRANO_ROOT", realpath(dirname(__FILE__) . '/../../')); } if (!defined('ROOT_PATH')) { define('ROOT_PATH', realpath(MAESTRANO_ROOT . '/../')); } // Include Maestrano required libraries require_once ROOT_PATH . '/vendor/autoload.php'; Maestrano::configure(ROOT_PATH . '/maestrano.json'); require_once MAESTRANO_ROOT . '/app/sso/MnoSsoUser.php';
public function testisValidWhenSloDisabled_ItShouldReturnTrue() { // Disable SLO Maestrano::configure(array('environment' => 'production', 'sso' => array('slo_enabled' => false))); // Response preparation (session not valid) $date = new DateTime(); $date->add(new DateInterval('PT1M')); $resp = array(); $resp["valid"] = "false"; $resp["recheck"] = $date->format(DateTime::ISO8601); $this->httpClient->setResponseStub($resp); // Set local recheck to force remote recheck $localRecheck = new DateTime(); $localRecheck->sub(new DateInterval('PT1M')); $this->subject = new Maestrano_Sso_Session($this->httpSession); $this->subject->setRecheck($localRecheck); $this->assertTrue($this->subject->isValid(false, $this->httpClient)); }
/** * Initializes the Test Suite */ public function setUp() { $this->config = array('environment' => 'test', 'api' => array('id' => 'app-1', 'key' => 'gfcmbu8269wyi0hjazk4t7o1sndpvrqxl53e1')); Maestrano::configure($this->config); }
/** * Initializes the Test Suite */ public function setUp() { Maestrano::configure(array('environment' => 'test', 'api' => array('id' => 'app-1', 'key' => 'gfcmbu8269wyi0hjazk4t7o1sndpvrqxl53e1', 'group_id' => 'cld-3'))); $this->subject = new Maestrano_Connec_Client(); }
/** * Return a json string describing the configuration * currently used by the PHP bindings */ public static function toMetadataWithPreset($preset) { $config = array('environment' => Maestrano::with($preset)->param('environment'), 'app' => array('host' => Maestrano::with($preset)->param('app.host')), 'api' => array('id' => Maestrano::with($preset)->param('api.id'), 'version' => Maestrano::with($preset)->param('api.version'), 'verify_ssl_certs' => false, 'lang' => Maestrano::with($preset)->param('api.lang'), 'lang_version' => Maestrano::with($preset)->param('api.lang_version'), 'host' => Maestrano::with($preset)->param('api.host'), 'base' => Maestrano::with($preset)->param('api.base')), 'sso' => array('enabled' => Maestrano::with($preset)->param('sso.enabled'), 'slo_enabled' => Maestrano::with($preset)->param('sso.slo_enabled'), 'init_path' => Maestrano::with($preset)->param('sso.init_path'), 'consume_path' => Maestrano::with($preset)->param('sso.consume_path'), 'creation_mode' => Maestrano::with($preset)->param('sso.creation_mode'), 'idm' => Maestrano::with($preset)->param('sso.idm'), 'idp' => Maestrano::with($preset)->param('sso.idp'), 'name_id_format' => Maestrano::with($preset)->param('sso.name_id_format'), 'x509_fingerprint' => Maestrano::with($preset)->param('sso.x509_fingerprint'), 'x509_certificate' => Maestrano::with($preset)->param('sso.x509_certificate')), 'connec' => array('enabled' => Maestrano::with($preset)->param('connec.enabled'), 'host' => Maestrano::with($preset)->param('connec.host'), 'base_path' => Maestrano::with($preset)->param('connec.base_path'), 'v2_path' => Maestrano::with($preset)->param('connec.v2_path'), 'reports_path' => Maestrano::with($preset)->param('connec.reports_path')), 'webhook' => array('account' => array('groups_path' => Maestrano::with($preset)->param('webhook.account.groups_path'), 'group_users_path' => Maestrano::with($preset)->param('webhook.account.group_users_path')), 'connec' => array('initialization_path' => Maestrano::with($preset)->param('webhook.connec.initialization_path'), 'notifications_path' => Maestrano::with($preset)->param('webhook.connec.notifications_path'), 'subscriptions' => Maestrano::with($preset)->param('webhook.connec.subscriptions')))); return json_encode($config); }
public function testToEmailWhenVirtual() { Maestrano::configure(array('environment' => 'production', 'sso' => array('creation_mode' => 'virtual'))); $this->assertEquals($this->subject->getVirtualEmail(), $this->subject->toEmail()); }
private function _curlRequest($method, $absUrl, $headers, $params) { $curl = curl_init(); $method = strtoupper($method); $opts = array(); if ($method == 'GET') { $opts[CURLOPT_HTTPGET] = 1; if (count($params) > 0) { $encoded = self::encode($params); $absUrl = "{$absUrl}?{$encoded}"; } } else { if ($method == 'POST') { $opts[CURLOPT_POST] = 1; $opts[CURLOPT_POSTFIELDS] = json_encode($params); } else { if ($method == 'PUT') { $opts[CURLOPT_CUSTOMREQUEST] = "PUT"; $opts[CURLOPT_POSTFIELDS] = json_encode($params); } else { if ($method == 'DELETE') { $opts[CURLOPT_CUSTOMREQUEST] = 'DELETE'; if (count($params) > 0) { $encoded = self::encode($params); $absUrl = "{$absUrl}?{$encoded}"; } } else { throw new Maestrano_Api_Error("Unrecognized method {$method}"); } } } } $absUrl = self::utf8($absUrl); $opts[CURLOPT_URL] = $absUrl; $opts[CURLOPT_RETURNTRANSFER] = true; $opts[CURLOPT_CONNECTTIMEOUT] = 30; $opts[CURLOPT_TIMEOUT] = 80; $opts[CURLOPT_HTTPHEADER] = $headers; if (!Maestrano::param('verify_ssl_certs')) { $opts[CURLOPT_SSL_VERIFYPEER] = false; } curl_setopt_array($curl, $opts); $rbody = curl_exec($curl); if (!defined('CURLE_SSL_CACERT_BADFILE')) { define('CURLE_SSL_CACERT_BADFILE', 77); // constant not defined in PHP } $errno = curl_errno($curl); if ($errno == CURLE_SSL_CACERT || $errno == CURLE_SSL_PEER_CERTIFICATE || $errno == CURLE_SSL_CACERT_BADFILE) { array_push($headers, 'X-Maestrano-Client-Info: {"ca":"using Maestrano-supplied CA bundle"}'); $cert = $this->caBundle(); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_CAINFO, $cert); $rbody = curl_exec($curl); } if ($rbody === false) { $errno = curl_errno($curl); $message = curl_error($curl); curl_close($curl); $this->handleCurlError($errno, $message); } $rcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); return array('body' => $rbody, 'code' => $rcode); }
/** * Return a settings object for php-saml * * @return Maestrano_Saml_Settings */ public function getSamlSettings() { $settings = new Maestrano_Saml_Settings(); // Configure SAML $settings->idpPublicCertificate = Maestrano::param('sso.x509_certificate'); $settings->spIssuer = Maestrano::param('api.id'); $settings->requestedNameIdFormat = Maestrano::param('sso.name_id_format'); $settings->idpSingleSignOnUrl = $this->getIdpUrl(); $settings->spReturnUrl = $this->getConsumeUrl(); return $settings; }