Last active
December 18, 2015 23:09
-
-
Save tristanbes/5859600 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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'] = ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This class handles MoxieManager SymfonyAuthenticator (Symfony < 2.x). | |
* | |
* @author Tristan Bessoussa <[email protected]> | |
*/ | |
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