/**
  * Stores the configuration. Calls the parent configuration first,
  * then does additional operations.
  * 
  * @param object Properties $configuration
  * @return object
  * @access public
  * @since 3/24/05
  */
 function assignConfiguration(Properties $configuration)
 {
     // Set the configuration values to our custom values.
     $configuration->addProperty('authentication_table', 'auth_visitor');
     $configuration->addProperty('username_field', 'email');
     $configuration->addProperty('password_field', 'password');
     $propertiesFields = array('name' => 'display_name', 'email' => 'email');
     $configuration->addProperty('properties_fields', $propertiesFields);
     try {
         ArgumentValidator::validate($configuration->getProperty('email_from_name'), NonzeroLengthStringValidatorRule::getRule());
     } catch (InvalidArgumentException $e) {
         throw new ConfigurationErrorException("'email_from_name' must be a string. " . $e->getMessage());
     }
     try {
         ArgumentValidator::validate($configuration->getProperty('email_from_address'), RegexValidatorRule::getRule('/^.+@.+$/'));
     } catch (InvalidArgumentException $e) {
         throw new ConfigurationErrorException("'email_from_address' must be an email address. " . $e->getMessage());
     }
     try {
         ArgumentValidator::validate($configuration->getProperty('domain_blacklist'), OptionalRule::getRule(ArrayValidatorRuleWithRule::getRule(NonzeroLengthStringValidatorRule::getRule())));
         ArgumentValidator::validate($configuration->getProperty('domain_whitelist'), OptionalRule::getRule(ArrayValidatorRuleWithRule::getRule(NonzeroLengthStringValidatorRule::getRule())));
     } catch (InvalidArgumentException $e) {
         throw new ConfigurationErrorException("'domain_blacklist' and 'domain_whitelist' if specified must be arrays of domain name strings. " . $e->getMessage());
     }
     parent::assignConfiguration($configuration);
 }
Example #2
0
 /**
  * Run the update
  * 
  * @return boolean
  * @access public
  * @since 3/24/08
  */
 function runUpdate($dbIndex)
 {
     $prepStatus = new StatusStars("Preparing Migration");
     $prepStatus->initializeStatistics(3);
     // Configure the original Hierarchy and AZ services
     $context = new OsidContext();
     $configuration = new ConfigurationProperties();
     $configuration->addProperty('database_index', $dbIndex);
     $configuration->addProperty('database_name', $_REQUEST['db_name']);
     $configuration->addProperty('harmoni_db_name', 'migration_db');
     Services::startManagerAsService("IdManager", $context, $configuration);
     Services::startManagerAsService("HierarchyManager", $context, $configuration);
     Services::startManagerAsService("AuthorizationManager", $context, $configuration);
     // Agent Manager
     $configuration = new ConfigurationProperties();
     // default agent Flavor is one that can be editted
     $agentFlavor = "HarmoniEditableAgent";
     $agentHierarchyId = "edu.middlebury.authorization.hierarchy";
     $configuration->addProperty('hierarchy_id', $agentHierarchyId);
     $configuration->addProperty('defaultAgentFlavor', $agentFlavor);
     $configuration->addProperty('database_index', $dbIndex);
     $configuration->addProperty('database_name', $_REQUEST['db_name']);
     Services::startManagerAsService("AgentManager", $context, $configuration);
     // :: Set up PropertyManager ::
     //the property manager operates in the same context as the AgentManager and is more or less an adjunct to it
     $configuration->addProperty('database_index', $dbIndex);
     $configuration->addProperty('database_name', $_REQUEST['db_name']);
     Services::startManagerAsService("PropertyManager", $context, $configuration);
     // :: Start the AuthenticationManager OSID Impl.
     $configuration = new ConfigurationProperties();
     $tokenCollectors = array(serialize(new Type("Authentication", "edu.middlebury.harmoni", "Harmoni DB")) => new FormActionNamePassTokenCollector('does not exist'));
     $configuration->addProperty('token_collectors', $tokenCollectors);
     Services::startManagerAsService("AuthenticationManager", $context, $configuration);
     // :: Start and configure the AuthenticationMethodManager
     $configuration = new ConfigurationProperties();
     // set up a Database Authentication Method
     require_once HARMONI . "/oki2/agentmanagement/AuthNMethods/SQLDatabaseAuthNMethod.class.php";
     require_once HARMONI . "/oki2/agentmanagement/AuthNMethods/SQLDatabaseMD5UsernamePasswordAuthNTokens.class.php";
     $dbAuthType = new Type("Authentication", "edu.middlebury.harmoni", "Harmoni DB");
     $dbMethodConfiguration = new ConfigurationProperties();
     $dbMethodConfiguration->addProperty('tokens_class', 'SQLDatabaseMD5UsernamePasswordAuthNTokens');
     $dbMethodConfiguration->addProperty('database_id', $dbIndex);
     $dbMethodConfiguration->addProperty('authentication_table', 'auth_db_user');
     $dbMethodConfiguration->addProperty('username_field', 'username');
     $dbMethodConfiguration->addProperty('password_field', 'password');
     $propertiesFields = array('username' => 'username');
     $dbMethodConfiguration->addProperty('properties_fields', $propertiesFields);
     $dbAuthNMethod = new SQLDatabaseAuthNMethod();
     $dbAuthNMethod->assignConfiguration($dbMethodConfiguration);
     $configuration->addProperty($dbAuthType, $dbAuthNMethod);
     Services::startManagerAsService("AuthNMethodManager", $context, $configuration);
     // :: Agent-Token Mapping Manager ::
     $configuration = new ConfigurationProperties();
     $configuration->addProperty('database_id', $dbIndex);
     $configuration->addProperty('harmoni_db_name', 'migration_db');
     Services::startManagerAsService("AgentTokenMappingManager", $context, $configuration);
     $prepStatus->updateStatistics();
     $dbc = Services::getService("DatabaseManager");
     try {
         /*********************************************************
          * Check for the old tables. They must exist for us to run
          *********************************************************/
         $azTables = array('az_authorization', 'az_function', 'hierarchy', 'j_node_node', 'node', 'node_ancestry');
         // Check for old tables
         $tables = $dbc->getTableList($dbIndex);
         foreach ($azTables as $table) {
             if (!in_array($table, $tables)) {
                 throw new Exception("Old AZ table, {$table}, is missing. Can not run Update.");
             }
         }
         /*********************************************************
          * Create the new tables
          *********************************************************/
         $type = $dbc->getDatabaseType($dbIndex);
         switch ($type) {
             case MYSQL:
                 SQLUtils::runSQLfile(HARMONI_BASE . "/SQL/MySQL/AuthZ2.sql", $dbIndex);
                 break;
             case POSTGRESQL:
                 SQLUtils::runSQLfile(HARMONI_BASE . "/SQL/PostgreSQL/AuthZ2.sql", $dbIndex);
                 break;
             case ORACLE:
                 SQLUtils::runSQLfile(HARMONI_BASE . "/SQL/PostgreSQL/AuthZ2.sql", $dbIndex);
                 break;
             default:
                 throw new Exception("Database schemas are not defined for specified database type.");
         }
         /*********************************************************
          * Hierarchy
          *********************************************************/
         $hierarchyMgr1 = Services::getService("Hierarchy");
         if (get_class($hierarchyMgr1) == "AuthZ2_HierarchyManager") {
             throw new OperationFailedException("Original HierarchyManager not configured.");
         }
         $hierarchyMgr2 = new AuthZ2_HierarchyManager();
         $azMgr2 = new AuthZ2_AuthorizationManager();
         $azMgr2->setHierarchyManager($hierarchyMgr2);
         $hierarchyMgr2->assignConfiguration($hierarchyMgr1->_configuration);
         /*********************************************************
          * Authorization
          *********************************************************/
         $azMgr1 = Services::getService("AuthZ");
         if (get_class($hierarchyMgr1) == "AuthZ2_AuthorizationManager") {
             throw new OperationFailedException("Original HierarchyManager not configured.");
         }
         $azMgr2->assignConfiguration($azMgr1->_configuration);
         $prepStatus->updateStatistics();
         /*********************************************************
          * Hierarchies
          *********************************************************/
         $hierarchies = $hierarchyMgr1->getHierarchies();
         $prepStatus->updateStatistics();
         while ($hierarchies->hasNext()) {
             $hierarchy = $hierarchies->next();
             try {
                 $newHierarchy = $hierarchyMgr2->getHierarchy($hierarchy->getId());
             } catch (UnknownIdException $e) {
                 $newHierarchy = $hierarchyMgr2->createHierarchy($hierarchy->getDisplayName(), array(), $hierarchy->getDescription(), $hierarchy->allowsMultipleParents(), $hierarchy->allowsRecursion(), $hierarchy->getId());
             }
             $query = new SelectQuery();
             $query->addTable("node");
             $query->addColumn("COUNT(*)", "num");
             $query->addWhereEqual("fk_hierarchy", $hierarchy->getId()->getIdString());
             $dbc = Services::getService("DatabaseManager");
             $result = $dbc->query($query);
             $this->nodeStatus = new StatusStars("Migrating nodes in the '" . $hierarchy->getDisplayName() . "' Hierarchy.");
             $this->nodeStatus->initializeStatistics($result->field("num"));
             // Add all of the nodes
             $nodes = $hierarchy->getRootNodes();
             while ($nodes->hasNext()) {
                 $this->addNode($newHierarchy, $nodes->next());
             }
         }
         /*********************************************************
          * Authorizations
          *********************************************************/
         $azMgr1 = Services::getService("AuthZ");
         if (get_class($hierarchyMgr1) == "AuthZ2_AuthorizationManager") {
             throw new OperationFailedException("Original HierarchyManager not configured.");
         }
         // Add all of the Authorization functions
         $functionTypes = $azMgr1->getFunctionTypes();
         while ($functionTypes->hasNext()) {
             $oldFunctions = $azMgr1->getFunctions($functionTypes->next());
             while ($oldFunctions->hasNext()) {
                 $oldFunction = $oldFunctions->next();
                 // Get or create the function
                 try {
                     $newFunction = $azMgr2->getFunction($oldFunction->getId());
                 } catch (UnknownIdException $e) {
                     $newFunction = $azMgr2->createFunction($oldFunction->getId(), $oldFunction->getReferenceName(), $oldFunction->getDescription(), $oldFunction->getFunctionType(), $oldFunction->getQualifierHierarchyId());
                 }
                 // Get all authorizations for this function.
                 $oldAZs = $azMgr1->getExplicitAZs(null, $oldFunction->getId(), null, false);
                 $status = new StatusStars("Migrating '" . $newFunction->getReferenceName() . "' Authorizations (" . $oldAZs->count() . ")");
                 $status->initializeStatistics($oldAZs->count());
                 while ($oldAZs->hasNext()) {
                     $oldAZ = $oldAZs->next();
                     $status->updateStatistics();
                     try {
                         $oldQualifier = $oldAZ->getQualifier();
                     } catch (UnknownIdException $e) {
                         // continue if the qualifier no longer exists.
                         continue;
                     }
                     // Add the new authorization
                     try {
                         $newAZ = $azMgr2->createAuthorization($oldAZ->getAgentId(), $oldAZ->getFunction()->getId(), $oldQualifier->getId());
                         if ($oldAZ->getExpirationDate()) {
                             $newAZ->updateExpirationDate($oldAZ->getExpirationDate());
                         }
                         if ($oldAZ->getEffectiveDate()) {
                             $newAZ->updateEffectiveDate($oldAZ->getEffectiveDate());
                         }
                     } catch (OperationFailedException $e) {
                     }
                 }
             }
         }
     } catch (Exception $e) {
         printpre($e->getMessage());
         HarmoniErrorHandler::printDebugBacktrace($e->getTrace());
         printpre("An error has occurred. Removing new tables.");
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_implicit_az');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_explicit_az');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_node_ancestry');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_j_node_node');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_function');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_function_type');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_node');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_node_type');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_hierarchy');
         } catch (DatabaseException $e) {
         }
         $query = new GenericSQLQuery('DROP TABLE az2_implicit_az, az2_explicit_az, az2_function, az2_function_type, az2_node_ancestry, az2_j_node_node, az2_node, az2_node_type,  az2_hierarchy;');
         $dbc->query($query, $dbIndex);
         return false;
     }
     /*********************************************************
      * If we have successfully gotten this far, drop the old 
      * hierarchy and AuthZ tables to prevent confusion.
      *********************************************************/
     $query = new GenericSQLQuery('DROP TABLE az_authorization, az_function, hierarchy, j_node_node, node, node_ancestry;');
     $dbc->query($query, $dbIndex);
     print "Success!";
     return true;
 }
Services::startManagerAsService("AuthenticationManager", $context, $configuration);
// :: Start and configure the AuthenticationMethodManager
$configuration = new ConfigurationProperties();
// set up a Database Authentication Method
require_once HARMONI . "/oki2/agentmanagement/AuthNMethods/SQLDatabaseAuthNMethod.class.php";
require_once HARMONI . "/oki2/agentmanagement/AuthNMethods/SQLDatabaseMD5UsernamePasswordAuthNTokens.class.php";
$dbAuthType = new Type("Authentication", "edu.middlebury.harmoni", "Harmoni DB");
$dbMethodConfiguration = new ConfigurationProperties();
$dbMethodConfiguration->addProperty('tokens_class', $arg0 = 'SQLDatabaseMD5UsernamePasswordAuthNTokens');
$dbMethodConfiguration->addProperty('database_id', $dbID);
$dbMethodConfiguration->addProperty('authentication_table', $arg2 = 'auth_db_user');
$dbMethodConfiguration->addProperty('username_field', $arg3 = 'username');
$dbMethodConfiguration->addProperty('password_field', $arg4 = 'password');
$propertiesFields = array('username' => 'username');
$dbMethodConfiguration->addProperty('properties_fields', $propertiesFields);
$dbAuthNMethod = new SQLDatabaseAuthNMethod();
$dbAuthNMethod->assignConfiguration($dbMethodConfiguration);
unset($arg0, $arg1, $arg2, $arg3, $arg4, $propertiesFields, $dbMethodConfiguration);
$configuration->addProperty($dbAuthType, $dbAuthNMethod);
// set up LDAPAuthentication Method
//  		require_once(HARMONI."/oki2/agentmanagement/AuthNMethods/LDAPAuthNMethod.class.php");
//  		require_once(HARMONI."/oki2/agentmanagement/AuthNMethods/LDAPAuthNTokens.class.php");
//  		$ldapAuthType = new Type ("Authentication", "edu.middlebury.harmoni", "Middlebury LDAP");
//  		$ldapConfiguration = new ConfigurationProperties;
//  		$ldapConfiguration->addProperty('tokens_class', $arg0 = 'LDAPAuthNTokens');
//  		$ldapConfiguration->addProperty("LDAPHost", $arg1 = "ad.middlebury.edu");
//  		$ldapConfiguration->addProperty("UserBaseDN", $arg2 = "cn=users,dc=middlebury,dc=edu");
//  		$ldapConfiguration->addProperty("ClassesBaseDN", $arg2a = "ou=classes,ou=groups,dc=middlebury,dc=edu");
// 			$ldapConfiguration->addProperty("ClassesBaseDN", $arg2a = "ou=classes,ou=groups,dc=middlebury,dc=edu");
//  		$ldapConfiguration->addProperty("GroupBaseDN", $arg3 = "ou=groups,dc=middlebury,dc=edu");
//  		$ldapConfiguration->addProperty("bindDN", $arg4 = "juser");
 *				"visitors"
 *			);
 *
 * USAGE: Copy this file to authentication-db.conf.php to set custom values.
 *
 * @package segue.config
 * 
 * @copyright Copyright © 2005, Middlebury College
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
 */
require_once HARMONI . "/oki2/agentmanagement/AuthNMethods/SQLDatabaseAuthNMethod.class.php";
require_once HARMONI . "/oki2/agentmanagement/AuthNMethods/SQLDatabaseMD5UsernamePasswordAuthNTokens.class.php";
/*********************************************************
 * Create and configure the authentication method
 *********************************************************/
$authNMethod = new SQLDatabaseAuthNMethod();
$configuration = new ConfigurationProperties();
$configuration->addProperty('tokens_class', 'SQLDatabaseMD5UsernamePasswordAuthNTokens');
$configuration->addProperty('database_id', $dbID);
$configuration->addProperty('authentication_table', 'auth_db_user');
$configuration->addProperty('username_field', 'username');
$configuration->addProperty('password_field', 'password');
$propertiesFields = array('username' => 'username');
$configuration->addProperty('properties_fields', $propertiesFields);
$authNMethod->assignConfiguration($configuration);
/*********************************************************
 * Enable the authentication method
 *********************************************************/
// Define a unique Type for this method
$type = new Type("Authentication", "edu.middlebury.harmoni", "Harmoni DB");
// Add the method to our AuthenticationMethodManagerConfiguration