예제 #1
0
 /**
  * Test the transpose() function.
  */
 public function testTranspose()
 {
     // check bad arrays
     $this->assertFalse(SimpleSAML\Utils\Arrays::transpose(array('1', '2', '3')), 'Invalid two-dimensional array was accepted');
     $this->assertFalse(SimpleSAML\Utils\Arrays::transpose(array('1' => 0, '2' => '0', '3' => array(0))), 'Invalid elements on a two-dimensional array were accepted');
     // check array with numerical keys
     $array = array('key1' => array('value1'), 'key2' => array('value1', 'value2'));
     $transposed = array(array('key1' => 'value1', 'key2' => 'value1'), array('key2' => 'value2'));
     $this->assertEquals($transposed, SimpleSAML\Utils\Arrays::transpose($array), 'Unexpected result of transpose()');
     // check array with string keys
     $array = array('key1' => array('subkey1' => 'value1'), 'key2' => array('subkey1' => 'value1', 'subkey2' => 'value2'));
     $transposed = array('subkey1' => array('key1' => 'value1', 'key2' => 'value1'), 'subkey2' => array('key2' => 'value2'));
     $this->assertEquals($transposed, SimpleSAML\Utils\Arrays::transpose($array), 'Unexpected result of transpose()');
     // check array with no keys in common between sub arrays
     $array = array('key1' => array('subkey1' => 'value1'), 'key2' => array('subkey2' => 'value1', 'subkey3' => 'value2'));
     $transposed = array('subkey1' => array('key1' => 'value1'), 'subkey2' => array('key2' => 'value1'), 'subkey3' => array('key2' => 'value2'));
     $this->assertEquals($transposed, SimpleSAML\Utils\Arrays::transpose($array), 'Unexpected result of transpose()');
 }
SimpleSAML\Utils\Auth::requireAdmin();
$config = SimpleSAML_Configuration::getInstance();
if (!empty($_FILES['xmlfile']['tmp_name'])) {
    $xmldata = file_get_contents($_FILES['xmlfile']['tmp_name']);
} elseif (array_key_exists('xmldata', $_POST)) {
    $xmldata = $_POST['xmldata'];
}
if (!empty($xmldata)) {
    \SimpleSAML\Utils\XML::checkSAMLMessage($xmldata, 'saml-meta');
    $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsString($xmldata);
    /* Get all metadata for the entities. */
    foreach ($entities as &$entity) {
        $entity = array('shib13-sp-remote' => $entity->getMetadata1xSP(), 'shib13-idp-remote' => $entity->getMetadata1xIdP(), 'saml20-sp-remote' => $entity->getMetadata20SP(), 'saml20-idp-remote' => $entity->getMetadata20IdP());
    }
    /* Transpose from $entities[entityid][type] to $output[type][entityid]. */
    $output = SimpleSAML\Utils\Arrays::transpose($entities);
    /* Merge all metadata of each type to a single string which should be
     * added to the corresponding file.
     */
    foreach ($output as $type => &$entities) {
        $text = '';
        foreach ($entities as $entityId => $entityMetadata) {
            if ($entityMetadata === NULL) {
                continue;
            }
            /* Remove the entityDescriptor element because it is unused, and only
             * makes the output harder to read.
             */
            unset($entityMetadata['entityDescriptor']);
            $text .= '$metadata[' . var_export($entityId, TRUE) . '] = ' . var_export($entityMetadata, TRUE) . ";\n";
        }
예제 #3
0
 /**
  * This function retrieves statistics about all memcache server groups.
  *
  * @return array Array with the names of each stat and an array with the value for each server group.
  *
  * @throws Exception If memcache server status couldn't be retrieved.
  */
 public static function getStats()
 {
     $ret = array();
     foreach (self::getMemcacheServers() as $sg) {
         $stats = $sg->getExtendedStats();
         if ($stats === false) {
             throw new Exception('Failed to get memcache server status.');
         }
         $stats = SimpleSAML\Utils\Arrays::transpose($stats);
         $ret = array_merge_recursive($ret, $stats);
     }
     return $ret;
 }
예제 #4
0
 /**
  * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\Arrays::transpose() instead.
  */
 public static function transposeArray($in)
 {
     return SimpleSAML\Utils\Arrays::transpose($in);
 }