Skip to content

Instantly share code, notes, and snippets.

@tristanbes

tristanbes/Plugin.php

Last active Dec 18, 2015
Embed
What would you like to do?
$moxieManagerConfig['authenticator'] = 'SymfonyAuthenticator';
// we go back to the root of the project assuming tiny_mce folder is under web.
// Example value : $path = realpath(dirname(__FILE__) . '/../../../../../../../../config/ProjectConfiguration.class.php');
$moxieManagerConfig['SymfonyAuthenticator.project_configuration_path'] = '';
// Example value 'frontend'
$moxieManagerConfig['SymfonyAuthenticator.application_name'] = '';
// Example value 'prod'
$moxieManagerConfig['SymfonyAuthenticator.application_env'] = '';
// Example value 'ROLE_MOXIEMANAGER'
$moxieManagerConfig['SymfonyAuthenticator.credential'] = '';
<?php
/**
* This class handles MoxieManager SymfonyAuthenticator (Symfony < 2.x).
*
* @author Tristan Bessoussa <tristan.bessoussa@gmail.com>
*/
class MOXMAN_SymfonyAuthenticator_Plugin implements MOXMAN_Auth_IAuthenticator
{
public function authenticate(MOXMAN_Auth_User $user)
{
$config = MOXMAN::getConfig();
if ($config->get('SymfonyAuthenticator.application_name') == '') {
die('You should define a symfony application name in Moxiemanager config file.');
}
if ($config->get('SymfonyAuthenticator.application_env') == '') {
die('You should define a symfony application environement in Moxiemanager config file.');
}
if ($config->get('SymfonyAuthenticator.project_configuration_path') == '') {
die('You should define a symfony project configuration path in Moxiemanager config file.');
}
require_once($config->get('SymfonyAuthenticator.project_configuration_path'));
$configuration = ProjectConfiguration::getApplicationConfiguration(
$config->get('SymfonyAuthenticator.application_name'),
$config->get('SymfonyAuthenticator.application_env'),
false
);
$context = sfContext::createInstance($configuration);
// Is the user authenticated ?
if ($context->getUser()->isAuthenticated()) {
// Do we need a special role to access to the moxiemanager ?
if ($config->get('SymfonyAuthenticator.credential') != '') {
if ($context->getUser()->hasCredential($config->get('SymfonyAuthenticator.credential'))) {
return true;
} else {
return false;
}
}
return true;
}
return false;
}
}
MOXMAN::getAuthManager()->add("SymfonyAuthenticator", new MOXMAN_SymfonyAuthenticator_Plugin());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.