Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Context propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jun 7, 2016
1 parent dcfadd3 commit 1e0dc69
Show file tree
Hide file tree
Showing 81 changed files with 1,030 additions and 1,417 deletions.
26 changes: 10 additions & 16 deletions core/src/core/src/pydio/Core/Controller/Controller.php
Expand Up @@ -257,7 +257,7 @@ public static function applyTaskInBackground(Task $task){
$parameters = $task->getParameters();
$task->setStatus(Task::STATUS_RUNNING);
TaskService::getInstance()->updateTask($task);
self::applyActionInBackground($task->getWsId(), $task->getAction(), $parameters, $task->getUserId(), "", $task->getId());
self::applyActionInBackground($task->getContext(), $task->getAction(), $parameters, "", $task->getId());

}

Expand All @@ -279,29 +279,23 @@ public static function executableRequest(ContextInterface $context, $action, $pa
/**
* Launch a command-line version of the framework by passing the actionName & parameters as arguments.
* @static
* @param String $currentRepositoryId
* @param ContextInterface $ctx
* @param String $actionName
* @param array $parameters
* @param string $user
* @param string $statusFile
* @param string $taskId
* @return null|UnixProcess
*/
public static function applyActionInBackground($currentRepositoryId, $actionName, $parameters, $user ="", $statusFile = "", $taskId = null)
public static function applyActionInBackground(ContextInterface $ctx, $actionName, $parameters, $statusFile = "", $taskId = null)
{
$repositoryId = $ctx->getRepositoryId();
$user = $ctx->hasUser() ? $ctx->getUser()->getId() : "shared";

$token = md5(time());
$logDir = AJXP_CACHE_DIR."/cmd_outputs";
if(!is_dir($logDir)) mkdir($logDir, 0755);
$logFile = $logDir."/".$token.".out";
if (empty($user)) {
if(AuthService::usersEnabled() && AuthService::getLoggedUser() !== null) {
$user = AuthService::getLoggedUser()->getId();
}else {
$user = "shared";
}
}


if (Services\AuthService::usersEnabled()) {
$cKey = ConfService::getCoreConf("AJXP_CLI_SECRET_KEY", "conf");
if(empty($cKey)){
Expand All @@ -310,10 +304,10 @@ public static function applyActionInBackground($currentRepositoryId, $actionName
$user = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($token.$cKey), $user, MCRYPT_MODE_ECB));
}
$robustInstallPath = str_replace("/", DIRECTORY_SEPARATOR, AJXP_INSTALL_PATH);
$cmd = ConfService::getCoreConf("CLI_PHP")." ".$robustInstallPath.DIRECTORY_SEPARATOR."cmd.php -u=$user -t=$token -a=$actionName -r=$currentRepositoryId";
$cmd = ConfService::getCoreConf("CLI_PHP")." ".$robustInstallPath.DIRECTORY_SEPARATOR."cmd.php -u=$user -t=$token -a=$actionName -r=$repositoryId";
/* Inserted next 3 lines to quote the command if in windows - rmeske*/
if (PHP_OS == "WIN32" || PHP_OS == "WINNT" || PHP_OS == "Windows") {
$cmd = ConfService::getCoreConf("CLI_PHP")." ".chr(34).$robustInstallPath.DIRECTORY_SEPARATOR."cmd.php".chr(34)." -u=$user -t=$token -a=$actionName -r=$currentRepositoryId";
$cmd = ConfService::getCoreConf("CLI_PHP")." ".chr(34).$robustInstallPath.DIRECTORY_SEPARATOR."cmd.php".chr(34)." -u=$user -t=$token -a=$actionName -r=$repositoryId";
}
if (!empty($statusFile)) {
$cmd .= " -s=".$statusFile;
Expand All @@ -334,9 +328,9 @@ public static function applyActionInBackground($currentRepositoryId, $actionName
}
}

$repoObject = ConfService::getRepositoryById($currentRepositoryId);
$repoObject = $ctx->getRepository();
$clearEnv = false;
if($repoObject->getOption("USE_SESSION_CREDENTIALS")){
if($repoObject->getContextOption($ctx, "USE_SESSION_CREDENTIALS")){
$encodedCreds = AJXP_Safe::getEncodedCredentialString();
if(!empty($encodedCreds)){
putenv("AJXP_SAFE_CREDENTIALS=".$encodedCreds);
Expand Down
17 changes: 10 additions & 7 deletions core/src/core/src/pydio/Core/Controller/XMLWriter.php
Expand Up @@ -22,6 +22,7 @@

use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\IAjxpWrapperProvider;
use Pydio\Core\Model\Context;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Model\RepositoryInterface;
use Pydio\Core\Utils\Utils;
Expand Down Expand Up @@ -512,13 +513,13 @@ public static function getUserXML(ContextInterface $ctx, $userObject = null)
if (!Services\AuthService::usersEnabled()) {
$buffer.="<user id=\"shared\">";
$buffer.="<active_repo id=\"".$currentRepoId."\" write=\"1\" read=\"1\"/>";
$buffer.= XMLWriter::writeRepositoriesData(null);
$buffer.= XMLWriter::writeRepositoriesData($ctx);
$buffer.="</user>";
} else if ($loggedUser != null) {
$lock = $loggedUser->getLock();
$buffer.="<user id=\"".$loggedUser->id."\">";
$buffer.="<active_repo id=\"".$currentRepoId."\" write=\"".($loggedUser->canWrite($currentRepoId)?"1":"0")."\" read=\"".($loggedUser->canRead($currentRepoId)?"1":"0")."\"/>";
$buffer.= XMLWriter::writeRepositoriesData($loggedUser);
$buffer.= XMLWriter::writeRepositoriesData($ctx);
$buffer.="<preferences>";
$preferences = $confDriver->getExposedPreferences($loggedUser);
foreach ($preferences as $prefName => $prefData) {
Expand Down Expand Up @@ -555,11 +556,12 @@ public static function getUserXML(ContextInterface $ctx, $userObject = null)
/**
* Write the repositories access rights in XML format
* @static
* @param AbstractAjxpUser|null $loggedUser * @internal param bool $details
* @param ContextInterface $ctx
* @return string
*/
public static function writeRepositoriesData($loggedUser)
public static function writeRepositoriesData(ContextInterface $ctx)
{
$loggedUser = $ctx->getUser();
$st = "<repositories>";
$streams = ConfService::detectRepositoryStreams(false);

Expand Down Expand Up @@ -653,7 +655,7 @@ public static function repositoryToXML($repoId, $repoObject, $exposed, $streams,
$ownerLabel = null;
if ($repoObject->hasOwner()) {
$uId = $repoObject->getOwner();
if(Services\AuthService::usersEnabled() && Services\AuthService::getLoggedUser()->getId() == $uId){
if($loggedUser != null && $loggedUser->getId() == $uId){
$currentUserIsOwner = true;
}
$label = ConfService::getUserPersonalParameter("USER_DISPLAY_NAME", $uId, "core.conf", $uId);
Expand All @@ -671,12 +673,13 @@ public static function repositoryToXML($repoId, $repoObject, $exposed, $streams,
if (!empty($description)) {
$descTag = '<description>'.Utils::xmlEntities($description, true).'</description>';
}
$ctx = Context::contextWithObjects($loggedUser, $repoObject);
$roleString="";
if($loggedUser != null){
$merged = $loggedUser->mergedRole;
$params = array();
foreach($exposed as $exposed_prop){
$metaOptions = $repoObject->getOption("META_SOURCES");
$metaOptions = $repoObject->getContextOption($ctx, "META_SOURCES");
if(!isSet($metaOptions[$exposed_prop["PLUGIN_ID"]])){
continue;
}
Expand All @@ -696,7 +699,7 @@ public static function repositoryToXML($repoId, $repoObject, $exposed, $streams,
$roleString.= ' hasMask="true" ';
}
}
return "<repo access_type=\"".$repoObject->accessType."\" id=\"".$repoId."\"$statusString $streamString $slugString $isSharedString $roleString><label>".TextEncoder::toUTF8(Utils::xmlEntities($repoObject->getDisplay()))."</label>".$descTag.$repoObject->getClientSettings()."</repo>";
return "<repo access_type=\"".$repoObject->accessType."\" id=\"".$repoId."\"$statusString $streamString $slugString $isSharedString $roleString><label>".TextEncoder::toUTF8(Utils::xmlEntities($repoObject->getDisplay()))."</label>".$descTag.$repoObject->getClientSettings($ctx)."</repo>";

}

Expand Down
18 changes: 17 additions & 1 deletion core/src/core/src/pydio/Core/Model/RepositoryInterface.php
Expand Up @@ -111,9 +111,10 @@ public function setSlug($slug = null);

/**
* Get the <client_settings> content of the manifest.xml
* @param ContextInterface $ctx
* @return \DOMElement|\DOMNodeList|string
*/
public function getClientSettings();
public function getClientSettings(ContextInterface $ctx);

/**
* Add options
Expand All @@ -133,6 +134,21 @@ public function addOption($oName, $oValue);
*/
public function getOption($oName, $safe = false, $resolveUser = null);

/**
* @param ContextInterface $ctx
* @param string $oName
* @return mixed
* @throws \Pydio\Core\Exception\PydioException
*/
public function getContextOption(ContextInterface $ctx, $oName);

/**
* @param string $oName
* @return mixed|string
* @throws \Exception
*/
public function getSafeOption($oName);

/**
* Get the options that already have a value
* @return array
Expand Down
12 changes: 1 addition & 11 deletions core/src/core/src/pydio/Core/Model/UserInterface.php
Expand Up @@ -239,17 +239,7 @@ public function getMergedRole();
* @return AJXP_Role
*/
public function getPersonalRole();

/**
* @param bool $resolveAsParent
*/
public function setResolveAsParent($resolveAsParent);

/**
* @return bool
*/
public function getResolveAsParent();


/**
* @return bool
* @throws \Exception
Expand Down
Expand Up @@ -234,7 +234,7 @@ private function initRepositoryPlugins($ctx){
$plugInstance = $this->getPluginByTypeName("access", $accessType);

// TRIGGER BEFORE INIT META
$metaSources = $repository->getOption("META_SOURCES");
$metaSources = $repository->getContextOption($ctx, "META_SOURCES");
if (isSet($metaSources) && is_array($metaSources) && count($metaSources)) {
$keys = array_keys($metaSources);
foreach ($keys as $plugId) {
Expand Down Expand Up @@ -271,7 +271,7 @@ private function initRepositoryPlugins($ctx){
$this->setPluginUniqueActiveForType("access", $accessType);

// TRIGGER INIT META
$metaSources = $repository->getOption("META_SOURCES");
$metaSources = $repository->getContextOption($ctx, "META_SOURCES");
if (isSet($metaSources) && is_array($metaSources) && count($metaSources)) {
$keys = array_keys($metaSources);
foreach ($keys as $plugId) {
Expand Down
54 changes: 2 additions & 52 deletions core/src/core/src/pydio/Core/Services/AuthService.php
Expand Up @@ -225,36 +225,7 @@ public static function clearRememberCookie()
setcookie("AjaXplorer-remember", "", time()-3600, null, null, (isSet($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"]) == "on"), true);
}
}

public static function logTemporaryUser($parentUserId, $temporaryUserId)
{
$parentUserId = self::filterUserSensitivity($parentUserId);
$temporaryUserId = self::filterUserSensitivity($temporaryUserId);
$confDriver = ConfService::getConfStorageImpl();
$parentUser = $confDriver->createUserObject($parentUserId);
$temporaryUser = $confDriver->createUserObject($temporaryUserId);
$temporaryUser->mergedRole = $parentUser->mergedRole;
$temporaryUser->rights = $parentUser->rights;
$temporaryUser->setGroupPath($parentUser->getGroupPath());
$temporaryUser->setParent($parentUserId);
$temporaryUser->setResolveAsParent(true);
AJXP_Logger::info(__CLASS__,"Log in", array("temporary user" => $temporaryUserId, "owner" => $parentUserId));
self::updateUser($temporaryUser);
}

public static function clearTemporaryUser($temporaryUserId)
{
AJXP_Logger::info(__CLASS__,"Log out", array("temporary user" => $temporaryUserId));
if (isSet($_SESSION["AJXP_USER"]) || isSet(self::$currentUser)) {
AJXP_Logger::info(__CLASS__, "Log Out", "");
unset($_SESSION["AJXP_USER"]);
if(isSet(self::$currentUser)) unset(self::$currentUser);
if (ConfService::getCoreConf("SESSION_SET_CREDENTIALS", "auth")) {
AJXP_Safe::clearCredentials();
}
}
}


/**
* Log the user from its credentials
* @static
Expand Down Expand Up @@ -1137,28 +1108,7 @@ public static function filterPluginParameters($pluginId, $params, ContextInterfa
}
return $params;
}

/**
* @param String $pluginId
* @param Repository $repository
* @param String $optionName
* @param bool $safe
* @return Mixed
*/
public static function getFilteredRepositoryOption($pluginId, $repository, $optionName, $safe = false){
$logged = self::getLoggedUser();
$test = null;
if($logged != null){
$test = $logged->mergedRole->filterParameterValue($pluginId, $optionName, $repository->getId(), null);
if(!empty($test) && !$safe) $test = VarsFilter::filter($test);
}
if(empty($test)){
return $repository->getOption($optionName, $safe);
}else{
return $test;
}
}


/**
* @param string $parentUserId
* @return AJXP_Role
Expand Down
5 changes: 3 additions & 2 deletions core/src/core/src/pydio/Core/Services/ConfService.php
Expand Up @@ -1400,8 +1400,9 @@ public static function getCoreConf($varName, $coreType = "ajaxplorer")
$coreP = PluginsService::getInstance()->findPlugin("core", $coreType);
if($coreP === false) return null;
$confs = $coreP->getConfigs();
$confs = AuthService::filterPluginParameters("core.".$coreType, $confs, Context::fromGlobalServices());
return (isSet($confs[$varName]) ? VarsFilter::filter($confs[$varName]) : null);
$ctx = Context::fromGlobalServices();
$confs = AuthService::filterPluginParameters("core.".$coreType, $confs, $ctx);
return (isSet($confs[$varName]) ? VarsFilter::filter($confs[$varName], $ctx) : null);
}

/**
Expand Down
7 changes: 4 additions & 3 deletions core/src/core/src/pydio/Core/Utils/Utils.php
Expand Up @@ -22,6 +22,7 @@

use Psr\Http\Message\UploadedFileInterface;
use Pydio\Access\Core\Model\Repository;
use Pydio\Core\Model\Context;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\AuthService;
use Pydio\Core\Services\ConfService;
Expand Down Expand Up @@ -1396,7 +1397,7 @@ public static function isStream($path)
*/
public static function loadSerialFile($filePath, $skipCheck = false, $format="ser")
{
$filePath = VarsFilter::filter($filePath);
$filePath = VarsFilter::filter($filePath, Context::fromGlobalServices());
$result = array();
if ($skipCheck) {
$fileLines = @file($filePath);
Expand Down Expand Up @@ -1430,7 +1431,7 @@ public static function saveSerialFile($filePath, $value, $createDir = true, $sil
if(!in_array($format, array("ser", "json"))){
throw new \Exception("Unsupported serialization format: ".$format);
}
$filePath = VarsFilter::filter($filePath);
$filePath = VarsFilter::filter($filePath, Context::fromGlobalServices());
if ($createDir && !is_dir(dirname($filePath))) {
@mkdir(dirname($filePath), 0755, true);
if (!is_dir(dirname($filePath))) {
Expand Down Expand Up @@ -1847,7 +1848,7 @@ public static function cleanDibiDriverParameters($params)
}
foreach ($params as $k => $v) {
$explode = explode("_", $k, 2);
$params[array_pop($explode)] = VarsFilter::filter($v);
$params[array_pop($explode)] = VarsFilter::filter($v, Context::fromGlobalServices());
unset($params[$k]);
}
}
Expand Down

0 comments on commit 1e0dc69

Please sign in to comment.