Example #1
0
 /**
  * Constructor for this authentication source.
  *
  * @param array $info  Information about this authentication source.
  * @param array $config  Configuration.
  */
 public function __construct($info, $config)
 {
     assert('is_array($info)');
     assert('is_array($config)');
     /* Call the parent constructor first, as required by the interface. */
     parent::__construct($info, $config);
     $this->users = array();
     /* Validate and parse our configuration. */
     foreach ($config as $userpass => $attributes) {
         if (!is_string($userpass)) {
             throw new Exception('Invalid <username>:<password> for authentication source ' . $this->authId . ': ' . $userpass);
         }
         $userpass = explode(':', $userpass, 2);
         if (count($userpass) !== 2) {
             throw new Exception('Invalid <username>:<password> for authentication source ' . $this->authId . ': ' . $userpass[0]);
         }
         $username = $userpass[0];
         $password = $userpass[1];
         try {
             $attributes = SimpleSAML\Utils\Arrays::normalizeAttributesArray($attributes);
         } catch (Exception $e) {
             throw new Exception('Invalid attributes for user ' . $username . ' in authentication source ' . $this->authId . ': ' . $e->getMessage());
         }
         $this->users[$username . ':' . $password] = $attributes;
     }
 }
Example #2
0
 /**
  * Constructor for this authentication source.
  *
  * @param array $info  Information about this authentication source.
  * @param array $config  Configuration.
  */
 public function __construct($info, $config)
 {
     assert('is_array($info)');
     assert('is_array($config)');
     /* Call the parent constructor first, as required by the interface. */
     parent::__construct($info, $config);
     /* Parse attributes. */
     try {
         $this->attributes = SimpleSAML\Utils\Arrays::normalizeAttributesArray($config);
     } catch (Exception $e) {
         throw new Exception('Invalid attributes for authentication source ' . $this->authId . ': ' . $e->getMessage());
     }
 }
Example #3
0
 /**
  * Constructor for this authentication source.
  *
  * @param array $info  Information about this authentication source.
  * @param array $config  Configuration.
  */
 public function __construct($info, $config)
 {
     assert('is_array($info)');
     assert('is_array($config)');
     /* Call the parent constructor first, as required by the interface. */
     parent::__construct($info, $config);
     $this->users = array();
     if (!($htpasswd = file_get_contents($config['htpasswd_file']))) {
         throw new Exception('Could not read ' . $config['htpasswd_file']);
     }
     $this->users = explode("\n", trim($htpasswd));
     try {
         $this->attributes = SimpleSAML\Utils\Arrays::normalizeAttributesArray($config['static_attributes']);
     } catch (Exception $e) {
         throw new Exception('Invalid static_attributes in authentication source ' . $this->authId . ': ' . $e->getMessage());
     }
 }
Example #4
0
 /**
  * @deprecated This method will be removed in SSP 2.0. Please use
  * SimpleSAML\Utils\Arrays::normalizeAttributesArray() instead.
  */
 public static function parseAttributes($attributes)
 {
     return SimpleSAML\Utils\Arrays::normalizeAttributesArray($attributes);
 }
Example #5
0
 /**
  * Test the normalizeAttributesArray() function.
  */
 public function testNormalizeAttributesArray()
 {
     $attributes = array('key1' => 'value1', 'key2' => array('value2', 'value3'), 'key3' => 'value1');
     $expected = array('key1' => array('value1'), 'key2' => array('value2', 'value3'), 'key3' => array('value1'));
     $this->assertEquals($expected, SimpleSAML\Utils\Arrays::normalizeAttributesArray($attributes), 'Attribute array normalization failed');
 }