示例#1
0
function __start_test()
{
    $dbh = StorageManager::getInstance()->getHandler(SQL_DAOHANDLER);
    // Drop tables
    try {
        $dbh->send('DROP TABLE `eyeosuserworkgroupassignation`');
    } catch (PDOException $e) {
    }
    try {
        $dbh->send('DROP TABLE `eyeosworkgroup`');
    } catch (PDOException $e) {
    }
    try {
        $dbh->send('DROP TABLE `eyeosprincipalgroupassignation`');
    } catch (PDOException $e) {
    }
    try {
        $dbh->send('DROP TABLE `eyeosuser`');
    } catch (PDOException $e) {
    }
    try {
        $dbh->send('DROP TABLE `eyeosgroup`');
    } catch (PDOException $e) {
    }
    // Create tables with initial content
    $initSqlScript = file_get_contents('./extras/EyeosUMSQL/EyeosUMSQL.sql');
    $dbh->send($initSqlScript);
    // Here we're using a test AuthConfiguration using FakeEyeosLoginModule, that allows to login
    // as root even without root user in the database so we can create... a real user root for
    // the rest of the tests :)
    // (the UM service is not accessible for writing by anyone, only root, members of "admin" or
    // "um" system groups)
    $originalConf = AuthConfiguration::getConfiguration();
    AuthConfiguration::setConfiguration(new XMLAuthConfiguration('./tests/system/conf/services/UM/AuthConfigurations/init_tests.xml'));
    // We need a valid login context to create test principals
    $myUManager = UMManager::getInstance();
    $subject = new Subject();
    $loginContext = new LoginContext('root', $subject);
    $subject->getPrivateCredentials()->append(new FakeEyeosCredential('root', 'root'));
    $loginContext->login();
    // Create "login" process
    $procManager = ProcManager::getInstance();
    $myProcess = new Process('login');
    $procManager->execute($myProcess);
    $procManager->setProcessLoginContext($myProcess->getPid(), $loginContext);
    // Delete pre-existing users because we need to create users in a clean way,
    // to trigger any action that is supposed to take place on user creation
    // (folder creation, default configuration files, etc.)
    try {
        $john = $myUManager->getUserByName('john');
        $myUManager->deletePrincipal($john);
    } catch (EyeNoSuchUserException $e) {
    }
    try {
        $root = $myUManager->getUserByName('root');
        $myUManager->deletePrincipal($root);
    } catch (EyeNoSuchUserException $e) {
    }
    // Create root
    $group = $myUManager->getGroupByName('root');
    $user = $myUManager->getNewUserInstance();
    $user->setName('root');
    $user->setPassword('root', true);
    $user->setPrimaryGroupId($group->getId());
    $myUManager->createUser($user);
    // Create john
    $group = $myUManager->getGroupByName(SERVICE_UM_DEFAULTUSERSGROUP);
    $user = $myUManager->getNewUserInstance();
    $user->setName('john');
    $user->setPassword('john', true);
    $user->setPrimaryGroupId($group->getId());
    $myUManager->createUser($user);
    // Now switch to a real authentication with root
    AuthConfiguration::setConfiguration($originalConf);
    $subject = new Subject();
    $loginContext = new LoginContext('init', $subject);
    $subject->getPrivateCredentials()->append(new EyeosPasswordCredential('root', 'root'));
    $loginContext->login();
    $procManager = ProcManager::getInstance();
    $procManager->setProcessLoginContext($myProcess->getPid(), $loginContext);
}
示例#2
0
 /**
  * Initialize the UM service by loading all necessary classes.
  * @see bottom of this file
  */
 public static function init()
 {
     //load AuthConfigurations classes
     $dir = new DirectoryIterator(SERVICE_UM_AUTHCONFIGURATIONS_PATH);
     foreach ($dir as $file) {
         if ($file->isFile()) {
             require SERVICE_UM_AUTHCONFIGURATIONS_PATH . '/' . $file;
         }
     }
     //load Credentials classes
     $dir = new DirectoryIterator(SERVICE_UM_CREDENTIALS_PATH);
     foreach ($dir as $file) {
         if ($file->isFile()) {
             require_once SERVICE_UM_CREDENTIALS_PATH . '/' . $file;
         }
     }
     //load LoginModules classes
     $dir = new DirectoryIterator(SERVICE_UM_LOGINMODULES_PATH);
     foreach ($dir as $file) {
         if ($file->isFile()) {
             require_once SERVICE_UM_LOGINMODULES_PATH . '/' . $file;
         }
     }
     //load Principals classes
     $dir = new DirectoryIterator(SERVICE_UM_PRINCIPALS_PATH);
     foreach ($dir as $file) {
         if ($file->isFile()) {
             require SERVICE_UM_PRINCIPALS_PATH . '/' . $file;
         }
     }
     //load PrincipalsManagers classes
     $dir = new DirectoryIterator(SERVICE_UM_PRINCIPALSMANAGERS_PATH);
     foreach ($dir as $file) {
         if ($file->isFile()) {
             require SERVICE_UM_PRINCIPALSMANAGERS_PATH . '/' . $file;
         }
     }
     $config = new XMLAuthConfiguration(SERVICE_UM_AUTHCONFIGURATION_DEFAULTCONF_PATH);
     AuthConfiguration::setConfiguration($config);
     $logger = Logger::getLogger('system.services.UM.UMManager');
     if ($logger->isDebugEnabled()) {
         $logger->debug('UM service initiliazed with configuration ' . SERVICE_UM_AUTHCONFIGURATION_DEFAULTCONF_PATH);
     }
 }