예제 #1
0
 public static function getPresentationRequestBody()
 {
     $requestBody = json_decode(file_get_contents('php://input'), true);
     // No presentation content in the request body
     if (!$requestBody['presentation'] || empty($requestBody['presentation'])) {
         Response::error(400, "400 No Content.");
     }
     return $requestBody;
 }
 private function _loadConfig($configKey)
 {
     $this->config = file_get_contents(Config::get('auth')[$configKey]);
     // Sanity
     if ($this->config === false) {
         Response::error(404, 'Not Found: MySQL config [' . $configKey . ']');
     }
     // DB details
     return json_decode($this->config, true);
 }
 public function getTableDump($table_name, $top)
 {
     if ($this->dataporten->isSuperAdmin() && $this->dataporten->hasOauthScopeAdmin()) {
         return $this->relaySQLConnection->query("SELECT TOP({$top}) * FROM {$table_name}");
     }
     // Else
     Response::error(401, 'Unauthorized!');
 }
 /**
  * Prevent orgAdmin to request data for other orgs than what he belongs to.
  *
  * @param $orgName
  */
 function verifyOrgAccess($orgName)
 {
     // If NOT superadmin AND requested org data is not for home org
     if (!$this->dataporten->isSuperAdmin() && strcasecmp($orgName, $this->dataporten->userOrg()) !== 0) {
         Response::error(401, '401 Unauthorized (request mismatch org/user). ');
     }
 }
 private function getConfig()
 {
     $this->config = file_get_contents(Config::get('auth')['relay_mongo']);
     // Sanity
     if ($this->config === false) {
         Response::error(404, 'Not Found: MongoDB config.');
     }
     // Connect username and pass
     return json_decode($this->config, true);
 }
 /**
  * Gets the feide username (if present) from the Gatekeeper via HTTP_X_DATAPORTEN_USERID_SEC.
  *
  * It should only return a single string, 'feide:user@org.no', but future development might introduce
  * a comma-separated or array representation of more than one username
  * (e.g. "openid:user@org.no, feide:user@org.no")
  *
  * This function takes care of all of these cases.
  */
 private function _getFeideUsername()
 {
     $userIdSec = NULL;
     // Get the username(s)
     $userid = $_SERVER["HTTP_X_DATAPORTEN_USERID_SEC"];
     // Future proofing...
     if (!is_array($userid)) {
         // If not already an array, make it so. If it is not a comma separated list, we'll get a single array item.
         $userid = explode(',', $userid);
     }
     // Fish for a Feide username
     foreach ($userid as $key => $value) {
         if (strpos($value, 'feide:') !== false) {
             $value = explode(':', $value);
             $userIdSec = $value[1];
         }
     }
     // No Feide...
     if (!isset($userIdSec)) {
         Response::error(401, 'Unauthorized (user not found)');
     }
     // '*****@*****.**'
     return $userIdSec;
 }
예제 #7
0
/**
 * Prevent orgAdmin to request data for other orgs than what s/he belongs to.
 *
 * Also check that the user is member of the MediasiteAdmin group.
 *
 * @param      $orgName
 * @param null $userName
 */
function verifyOrgAndUserAccess($orgName, $userName = NULL)
{
    global $dataporten;
    // Restrictions apply, unless you're superadmin...
    if (!$dataporten->isSuperAdmin()) {
        // If requested org data is not for home org
        if (strcasecmp($orgName, $dataporten->userOrg()) !== 0) {
            Response::error(401, '401 Unauthorized (request mismatch org/user). ');
        }
        // If request involves a user account
        if (isset($userName)) {
            // Must be user from home org
            if (!strstr($userName, $orgName)) {
                Response::error(401, '401 Unauthorized (request mismatch org/user). ');
            }
        }
        if (!$dataporten->isOrgAdmin()) {
            Response::error(401, '401 Unauthorized (user is not member of the RelayAdmin group). ');
        }
    }
}
 /**
  * @return PDO
  */
 private function getConnection()
 {
     if (!is_null($this->connection)) {
         return $this->connection;
     }
     $connection = NULL;
     $host = $this->config['host'];
     $db = $this->config['db'];
     $user = $this->config['user'];
     $pass = $this->config['pass'];
     try {
         //$connection = new PDO("mssql:host=$host;dbname=$db;charset=UTF8", $user, $pass);
         $connection = new PDO("dblib:host={$host};dbname={$db};charset=UTF8", $user, $pass);
         //$connection = new PDO("sqlsrv:Server=$host;Database=$db", $user, $pass);
         //odbc:DRIVER=FreeTDS;SERVERNAME=mssql;DATABASE=
         $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         Utils::log("DB CONNECTED");
         return $connection;
     } catch (PDOException $e) {
         Response::error(500, 'DB connection failed (SQL): ' . $e->getMessage());
     }
 }