本文整理汇总了PHP中MOXMAN::getAuthManager方法的典型用法代码示例。如果您正苦于以下问题:PHP MOXMAN::getAuthManager方法的具体用法?PHP MOXMAN::getAuthManager怎么用?PHP MOXMAN::getAuthManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MOXMAN
的用法示例。
在下文中一共展示了MOXMAN::getAuthManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processRequest
/**
* Process a request using the specified context.
*
* @param MOXMAN_Http_Context $httpContext Context instance to pass to use for the handler.
*/
public function processRequest(MOXMAN_Http_Context $httpContext)
{
$request = $httpContext->getRequest();
$response = $httpContext->getResponse();
try {
$config = MOXMAN::getConfig();
$allItems = $config->getAll();
$licenseKey = trim($config->get("general.license"));
$installed = !empty($allItems);
$response->disableCache();
$response->setHeader('Content-type', 'application/json');
if ($installed && !$config->get('filesystem.rootpath')) {
throw new MOXMAN_Exception("You must configure filesystem.rootpath.");
}
if ($request->getMethod() != 'POST') {
throw new MOXMAN_Exception("Not a HTTP post request.");
}
if ($installed && !preg_match('/^([0-9A-Z]{4}\\-){7}[0-9A-Z]{4}$/', $licenseKey)) {
throw new MOXMAN_Exception("Invalid license key specified in config.");
}
$authInfo = (object) array("token" => MOXMAN_Http_Csrf::createToken(MOXMAN::getConfig()->get('general.license')), "installed" => $installed, "loggedin" => MOXMAN::getAuthManager()->isAuthenticated(), "loginurl" => $config->get("authenticator.login_page", ""), "standalone" => MOXMAN::getAuthManager()->hasStandalone(), "overwrite_action" => $config->get("filesystem.overwrite_action", ""));
$args = new MOXMAN_Auth_AuthInfoEventArgs();
MOXMAN::getPluginManager()->get("core")->fire("AuthInfo", $args);
foreach ($args->getInfo() as $key => $value) {
$authInfo->{$key} = $value;
}
$response->sendJson($authInfo);
} catch (Exception $e) {
$response->sendJson((object) array("error" => array("code" => $e->getCode(), "message" => $e->getMessage())));
}
}
示例2: add
/**
* Adds a plugin instance by name to the manager.
*
* @param string $name Name of the plugin to add.
* @param MOXMAN_IPlugin $plugin Plugin instance to add.
*/
public function add($name, MOXMAN_IPlugin $plugin)
{
if ($plugin instanceof MOXMAN_Auth_IAuthenticator) {
MOXMAN::getAuthManager()->add($name, $plugin);
}
$this->plugins[$name] = $plugin;
$this->unInitialized[] = $name;
}
示例3: processRequest
/**
* Process a request using the specified context.
*
* @param MOXMAN_Http_Context $httpContext Context instance to pass to use for the handler.
*/
public function processRequest(MOXMAN_Http_Context $httpContext)
{
$config = MOXMAN::getConfig();
$response = $httpContext->getResponse();
$response->disableCache();
$response->setHeader('Content-type', 'text/html');
if (!$config->get("general.debug")) {
$response->sendContent("Debugging not configured, you need to set general.debug to true in config.php file.");
return;
}
$request = $httpContext->getRequest();
if ($request->get("info")) {
phpinfo();
return;
}
$sitepaths = MOXMAN_Util_PathUtils::getSitePaths();
$scriptFilename = $_SERVER["SCRIPT_FILENAME"];
if (realpath($scriptFilename) != $scriptFilename) {
$scriptFilename = $scriptFilename . "<br />(" . realpath($scriptFilename) . ")";
}
if (function_exists("imagecreatefromjpeg")) {
$gdInfo = gd_info();
$outInfo = "Ver:" . $gdInfo["GD Version"];
$outInfo .= " GIF:" . ($gdInfo["GIF Create Support"] ? "Y" : "N");
$outInfo .= " PNG:" . ($gdInfo["PNG Support"] ? "Y" : "N");
$outInfo .= " JPEG:" . ($gdInfo["JPEG Support"] ? "Y" : "N");
} else {
$outInfo = "N/A";
$gdInfo = array();
}
$user = MOXMAN::getAuthManager()->getUser();
$result = array("MOXMAN_ROOT" => MOXMAN_ROOT, "realpath('.')" => realpath("."), "Config.php rootpath" => $config->get("filesystem.rootpath"), "Config.php wwwroot" => $config->get("filesystem.local.wwwroot"), "wwwroot resolve" => $sitepaths["wwwroot"], "wwwroot realpath" => realpath($sitepaths["wwwroot"]), "prefix resolve" => $sitepaths["prefix"], "storage path" => MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $config->get("storage.path")), "storage writable" => is_writable(MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $config->get("storage.path"))), "script filename" => $scriptFilename, "script name" => $_SERVER["SCRIPT_NAME"], "GD" => $outInfo, "memory_limit" => @ini_get("memory_limit"), "upload_max_filesize" => @ini_get("upload_max_filesize"), "post_max_size" => @ini_get("post_max_size"), "file_uploads" => @ini_get("file_uploads") ? "Yes" : "No", "PHP Version" => phpversion(), "Time" => date('Y-m-d H:i:s', time()), "Time UTC" => date('Y-m-d H:i:s', time() - date("Z")), "Authenticated" => MOXMAN::getAuthManager()->isAuthenticated(), "User" => $user ? $user->getName() : "N/A");
$out = "<html><body><table border='1'>";
foreach ($result as $name => $value) {
if ($value === true) {
$value = "True";
} else {
if ($value === false) {
$value = "False";
}
}
$out .= "<tr>";
$out .= "<td>" . $name . " </td><td>" . $value . " </td>";
$out .= "</tr>";
}
$out .= "</table><a href='?action=debug&info=true'>Show phpinfo</a>";
$out .= "</body></html>";
$response->sendContent($out);
}
示例4: execute
/**
* Executes the command logic with the specified RPC parameters.
*
* @param Object $params Command parameters sent from client.
* @return Object Result object to be passed back to client.
*/
public function execute($params)
{
$rootPaths = array();
foreach (MOXMAN::getFileSystemManager()->getFileSystems() as $filesystem) {
$rootFile = $filesystem->getRootFile();
if (!$rootFile->isHidden()) {
// Get root file meta data
$meta = $rootFile->getMetaData();
$meta = $meta->getAll("ui");
// Add show/hide login to meta
$meta["standalone"] = MOXMAN::getAuthManager()->hasStandalone();
// Return name, path and optional meta data
$rootPaths[] = (object) array("name" => $filesystem->getRootName(), "path" => $rootFile->getPublicPath(), "meta" => $meta, "config" => $this->getPublicConfig($rootFile));
}
}
return $rootPaths;
}
示例5: array
{
$config = MOXMAN::getConfig();
$session = MOXMAN_Http_Context::getCurrent()->getSession();
// Check logged in key
$sessionValue = $session->get($config->get("SessionAuthenticator.logged_in_key"), false);
if (!$sessionValue || $sessionValue === "false") {
return false;
}
// Extend config with session prefixed sessions
$sessionConfig = array();
$configPrefix = $config->get("SessionAuthenticator.config_prefix");
if ($configPrefix) {
foreach ($_SESSION as $key => $value) {
if (strpos($key, $configPrefix) === 0) {
$sessionConfig[substr($key, strlen($configPrefix) + 1)] = $value;
}
}
}
// Extend the config with the session config
$config->extend($sessionConfig);
// Replace ${user} with all config items
$key = $config->get("SessionAuthenticator.user_key");
if ($key && isset($_SESSION[$key])) {
$config->replaceVariable("user", $session->get($key));
}
// The user is authenticated so let them though
return true;
}
}
MOXMAN::getAuthManager()->add("SessionAuthenticator", new MOXMAN_SessionAuthenticator_Plugin());
示例6: explode
// Load plugins, needs to be loaded at page level since they might contain globals
$plugins = explode(',', MOXMAN::getConfig()->get("general.plugins"));
foreach ($plugins as $plugin) {
if ($plugin) {
$pluginPath = MOXMAN_ROOT . '/plugins/' . $plugin;
MOXMAN_AutoLoader::addPrefixPath("MOXMAN_" . $plugin, $pluginPath);
$plugin = $pluginPath . "/Plugin.php";
if (file_exists($plugin)) {
require_once $plugin;
}
}
}
// Load core plugin last
require_once MOXMAN_CLASSES . '/Core/Plugin.php';
// Trigger authenticate on all plugins so it can override any config options
try {
MOXMAN::getAuthManager()->isAuthenticated();
} catch (Exception $e) {
// Handle exceptions in authenticators
$httpContext = MOXMAN_Http_Context::getCurrent();
$request = $httpContext->getRequest();
$response = $httpContext->getResponse();
if ($request->get("json")) {
$response->sendJson((object) array("jsonrpc" => "2.0", "error" => array("code" => '200', "message" => $e->getMessage()), "id" => "r0"));
} else {
die($e->getMessage());
}
die;
}
// Initialize all plugins
MOXMAN::getPluginManager()->initAll();
示例7: processRequest
/**
* Process a request using the specified context.
*
* @param MOXMAN_Http_Context $httpContext Context instance to pass to use for the handler.
*/
public function processRequest(MOXMAN_Http_Context $httpContext)
{
$request = $httpContext->getRequest();
$response = $httpContext->getResponse();
$response->disableCache();
$response->setHeader('Content-type', 'application/json');
@set_time_limit(5 * 60);
// 5 minutes execution time
$id = null;
try {
$json = MOXMAN_Util_Json::decode($request->get("json"));
// Check if we should install
if ($json && $json->method != "install") {
$config = MOXMAN::getConfig()->getAll();
if (empty($config) || !isset($config["general.license"])) {
$exception = new MOXMAN_Exception("Installation needed.", MOXMAN_Exception::NEEDS_INSTALLATION);
throw $exception;
}
if (!preg_match('/^([0-9A-Z]{4}\\-){7}[0-9A-Z]{4}$/', trim($config["general.license"]))) {
throw new MOXMAN_Exception("Invalid license: " . $config["general.license"]);
}
}
// Check if the user is authenticated or not
if (!MOXMAN::getAuthManager()->isAuthenticated()) {
if (!isset($json->method) || !preg_match('/^(login|logout|install)$/', $json->method)) {
$exception = new MOXMAN_Exception("Access denied by authenticator(s).", MOXMAN_Exception::NO_ACCESS);
$exception->setData(array("login_url" => MOXMAN::getConfig()->get("authenticator.login_page")));
throw $exception;
}
}
if ($json && isset($json->id) && isset($json->method) && isset($json->params)) {
$id = $json->id;
$params = $json->params;
$result = null;
if (isset($params->access)) {
MOXMAN::getAuthManager()->setClientAuthData($params->access);
}
$plugins = MOXMAN::getPluginManager()->getAll();
foreach ($plugins as $plugin) {
if ($plugin instanceof MOXMAN_ICommandHandler) {
$result = $plugin->execute($json->method, $json->params);
if ($result !== null) {
break;
}
}
}
if ($result === null) {
throw new Exception("Method not found: " . $json->method, -32601);
}
$response->sendJson((object) array("jsonrpc" => "2.0", "result" => $result, "id" => $id));
} else {
throw new Exception("Invalid Request.", -32600);
}
MOXMAN::dispose();
} catch (Exception $e) {
MOXMAN::dispose();
$message = $e->getMessage();
$data = null;
if (MOXMAN::getConfig()->get("general.debug")) {
$message .= "\n\nStacktrace:\n";
$trace = $e->getTrace();
array_shift($trace);
$message .= $e->getFile() . ":" . $e->getLine() . "\n";
foreach ($trace as $item) {
if (isset($item["file"]) && isset($item["line"])) {
$message .= $item["file"] . ":" . $item["line"] . "\n";
}
}
}
if ($e instanceof MOXMAN_Exception && !$data) {
$data = $e->getData();
}
$response->sendJson((object) array("jsonrpc" => "2.0", "error" => array("code" => $e->getCode(), "message" => $message, "data" => $data), "id" => $id));
}
}
示例8: processRequest
/**
* Process a request using the specified context.
*
* @param MOXMAN_Http_Context $httpContext Context instance to pass to use for the handler.
*/
public function processRequest(MOXMAN_Http_Context $httpContext)
{
$tempFilePath = null;
$chunkFilePath = null;
$request = $httpContext->getRequest();
$response = $httpContext->getResponse();
try {
// Check if the user is authenticated or not
if (!MOXMAN::getAuthManager()->isAuthenticated()) {
if (!isset($json->method) || !preg_match('/^(login|logout)$/', $json->method)) {
$exception = new MOXMAN_Exception("Access denied by authenticator(s).", 10);
$exception->setData(array("login_url" => MOXMAN::getConfig()->get("authenticator.login_page")));
throw $exception;
}
}
$file = MOXMAN::getFile($request->get("path"));
$config = $file->getConfig();
if ($config->get('general.demo')) {
throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE);
}
$maxSizeBytes = preg_replace("/[^0-9.]/", "", $config->get("upload.maxsize"));
if (strpos(strtolower($config->get("upload.maxsize")), "k") > 0) {
$maxSizeBytes = round(floatval($maxSizeBytes) * 1024);
}
if (strpos(strtolower($config->get("upload.maxsize")), "m") > 0) {
$maxSizeBytes = round(floatval($maxSizeBytes) * 1024 * 1024);
}
function generateRandomString($length = 10)
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
$filename = generateRandomString() . '.' . MOXMAN_Util_PathUtils::getExtension($request->get("name"));
$id = $request->get("id");
$loaded = intval($request->get("loaded", "0"));
$total = intval($request->get("total", "-1"));
$file = MOXMAN::getFile($file->getPath(), $filename);
// Generate unique id for first chunk
// TODO: We should cleanup orphan ID:s if upload fails etc
if ($loaded == 0) {
$id = uniqid();
}
// Setup path to temp file based on id
$tempFilePath = MOXMAN_Util_PathUtils::combine(MOXMAN_Util_PathUtils::getTempDir(), "mcupload_" . $id . "." . MOXMAN_Util_PathUtils::getExtension($file->getName()));
$chunkFilePath = MOXMAN_Util_PathUtils::combine(MOXMAN_Util_PathUtils::getTempDir(), "mcupload_chunk_" . $id . "." . MOXMAN_Util_PathUtils::getExtension($file->getName()));
if (!$file->canWrite()) {
throw new MOXMAN_Exception("No write access to path: " . $file->getPublicPath(), MOXMAN_Exception::NO_WRITE_ACCESS);
}
if ($total > $maxSizeBytes) {
throw new MOXMAN_Exception("File size to large: " . $file->getPublicPath(), MOXMAN_Exception::FILE_SIZE_TO_LARGE);
}
// Operations on first chunk
if ($loaded == 0) {
// Fire before file action add event
$args = new MOXMAN_Core_FileActionEventArgs("add", $file);
$args->getData()->fileSize = $total;
MOXMAN::getPluginManager()->get("core")->fire("BeforeFileAction", $args);
$file = $args->getFile();
if ($file->exists()) {
if (!$config->get("upload.overwrite") && !$request->get("overwrite")) {
throw new MOXMAN_Exception("Target file exists: " . $file->getPublicPath(), MOXMAN_Exception::FILE_EXISTS);
} else {
MOXMAN::getPluginManager()->get("core")->deleteThumbnail($file);
$file->delete();
}
}
$filter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "upload");
if ($filter->accept($file) !== MOXMAN_Vfs_CombinedFileFilter::ACCEPTED) {
throw new MOXMAN_Exception("Invalid file name for: " . $file->getPublicPath(), MOXMAN_Exception::INVALID_FILE_NAME);
}
}
$blobSize = 0;
$inputFile = $request->getFile("file");
if (!$inputFile) {
throw new MOXMAN_Exception("No input file specified.");
}
if ($loaded === 0) {
// Check if we should mock or not
if (defined('PHPUNIT')) {
if (!copy($inputFile['tmp_name'], $tempFilePath)) {
throw new MOXMAN_Exception("Could not move the uploaded temp file.");
}
} else {
if (!move_uploaded_file($inputFile['tmp_name'], $tempFilePath)) {
throw new MOXMAN_Exception("Could not move the uploaded temp file.");
}
}
$blobSize = filesize($tempFilePath);
} else {
// Check if we should mock or not
//.........这里部分代码省略.........
示例9: login
}
}
if (isset($_SESSION["moxman_authUser"])) {
$user->setName($_SESSION["moxman_authUser"]);
return true;
}
return false;
}
public function login(MOXMAN_Auth_User $user)
{
$config = MOXMAN::getConfig();
foreach ($config->get('basicauthenticator.users') as $userItem) {
if ($userItem["username"] == $user->getName() && $userItem["password"] == $user->getPassword()) {
if ($user->isPersistent()) {
setcookie("moxmanauth", hash("sha256", $userItem["username"] . $userItem["password"] . $config->get('general.license')));
} else {
$_SESSION["moxman_authUser"] = $user->getName();
}
return true;
}
}
return false;
}
public function logout(MOXMAN_Auth_User $user)
{
unset($_SESSION["moxman_authUser"]);
setcookie("moxmanauth", "", time() - 3600);
}
}
MOXMAN::getAuthManager()->add("BasicAuthenticator", new MOXMAN_BasicAuthenticator_Plugin());
示例10: drupal_bootstrap
if (!isset($_SESSION['mc_drupal_auth']) || !$_SESSION['mc_drupal_auth']) {
// Not cached in session check agains API
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$isDrupalAuth = user_access('create page content');
$_SESSION['mc_drupal_auth'] = $isDrupalAuth;
} else {
$isDrupalAuth = $_SESSION['mc_drupal_auth'];
}
// Restore path
chdir($cwd);
/**
* This class handles MoxieManager IPAuthenticator.
*
* @package IpAuthenticator
*/
class MOXMAN_DrupalAuthenticator_Plugin implements MOXMAN_Auth_IAuthenticator
{
public function authenticate(MOXMAN_Auth_User $user)
{
global $isDrupalAuth;
global $user;
$config = MOXMAN::getConfig();
// If authenticated then
if ($isDrupalAuth && isset($user)) {
$config->replaceVariable("user", $user->uid);
}
return $isDrupalAuth;
}
}
MOXMAN::getAuthManager()->add("DrupalAuthenticator", new MOXMAN_DrupalAuthenticator_Plugin());
示例11: pathinfo
<?php
$aPathInfo = pathinfo(__FILE__);
require_once $aPathInfo['dirname'] . '/../../../../inc/header.inc.php';
require_once BX_DIRECTORY_PATH_INC . 'profiles.inc.php';
/**
* This class handles MoxieManager DolphinAuthenticator authentication.
*/
class MOXMAN_DolphinAuthenticator_Plugin implements MOXMAN_Auth_IAuthenticator
{
public function authenticate(MOXMAN_Auth_User $user)
{
$config = MOXMAN::getConfig();
if (!isLogged()) {
return false;
}
$s = getUsername();
$sPath = BX_DIRECTORY_PATH_ROOT . 'media/moxie/files/' . substr($s, 0, 1) . '/' . substr($s, 0, 2) . '/' . substr($s, 0, 3) . '/' . $s;
bx_mkdir_r($sPath);
$config->put('filesystem.rootpath', $sPath);
$config->replaceVariable("user", $s);
$user->setName($s);
return true;
}
}
MOXMAN::getAuthManager()->add("DolphinAuthenticator", new MOXMAN_DolphinAuthenticator_Plugin());
示例12: execute
/**
* Executes the command logic with the specified RPC parameters.
*
* @param Object $params Command parameters sent from client.
* @return Object Result object to be passed back to client.
*/
public function execute($params)
{
MOXMAN::getAuthManager()->logout();
return true;
}
示例13: define
define('_JEXEC', 1);
define('JPATH_BASE', getcwd());
define('DS', DIRECTORY_SEPARATOR);
require_once JPATH_BASE . DS . 'includes' . DS . 'defines.php';
require_once JPATH_BASE . DS . 'includes' . DS . 'framework.php';
chdir(MOXMAN_ROOT);
// This is a really ugly hack, blame Joomla
if (strpos($_SERVER['HTTP_REFERER'], "administrator/") > 1) {
$app = JFactory::getApplication('administrator');
} else {
$app = JFactory::getApplication('site');
}
/**
* This class handles Joomla Authentication.
*/
class MOXMAN_JoomlaAuthenticator_Plugin implements MOXMAN_Auth_IAuthenticator
{
public function authenticate(MOXMAN_Auth_User $user)
{
$config = MOXMAN::getConfig();
$user = JFactory::getUser();
// Not logged in
if ($user->id == 0) {
return false;
}
$config->replaceVariable("user", $user->username);
return true;
}
}
MOXMAN::getAuthManager()->add("JoomlaAuthenticator", new MOXMAN_JoomlaAuthenticator_Plugin());
示例14: Session
$session = new Session();
$session = $session->all();
// Check logged in key
$loggedInKey = $config->get("SymfonyAuthenticator.logged_in_key", "isLoggedIn");
$sessionValue = isset($session[$loggedInKey]) ? $session[$loggedInKey] : false;
if (!$sessionValue || $sessionValue === "false") {
return false;
}
// Extend config with session prefixed sessions
$sessionConfig = array();
$configPrefix = $config->get("SymfonyAuthenticator.config_prefix", "moxiemanager");
if ($configPrefix) {
foreach ($session as $key => $value) {
if (strpos($key, $configPrefix) === 0) {
$sessionConfig[substr($key, strlen($configPrefix) + 1)] = $value;
}
}
}
// Extend the config with the session config
$config->extend($sessionConfig);
// Replace ${user} with all config items
$key = $config->get("SessionAuthenticator.user_key", "user");
if ($key && isset($session[$key])) {
$config->replaceVariable("user", $session[$key]);
$user->setName($session[$key]);
}
return true;
}
}
MOXMAN::getAuthManager()->add("SymfonyAuthenticator", new MOXMAN_SymfonyAuthenticator_Plugin());
示例15: foreach
$authUrl = MOXMAN_Util_PathUtils::toAbsolute(dirname($_SERVER["REQUEST_URI"]) . '/plugins/ExternalAuthenticator', $authUrl);
$request = $httpClient->createRequest($url . $authUrl);
$cookie = '';
foreach ($_COOKIE as $name => $value) {
$cookie .= ($cookie ? '; ' : '') . $name . '=' . $value;
}
$request->setHeader('cookie', $cookie);
$seed = $cookie . uniqid() . time();
$hash = hash_hmac('sha256', $seed, $secretKey);
$response = $request->send(array("seed" => $seed, "hash" => $hash));
$json = json_decode($response->getBody());
if (!$json) {
throw new MOXMAN_Exception("Did not get a proper JSON response from Auth url.");
}
if (isset($json->result)) {
foreach ($json->result as $key => $value) {
$key = str_replace('_', '.', $key);
$config->put($key, $value);
}
return true;
} else {
if (isset($json->error)) {
throw new MOXMAN_Exception($json->error->message . " - " . $json->error->code);
} else {
throw new MOXMAN_Exception("Generic unknown error, did not get a proper JSON response from Auth url.");
}
}
}
}
MOXMAN::getAuthManager()->add("ExternalAuthenticator", new MOXMAN_ExternalAuthenticator_Plugin());