Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow auth adapters to return a single value instead of arrays

  • Loading branch information...
commit 2110acde275b1e1e70987a626bcd596d0e373c78 1 parent 73a07d8
@d1rk authored
View
11 security/Auth.php
@@ -150,16 +150,11 @@ public static function check($name, $credentials = null, array $options = array(
}
if (($credentials) && $data = $self::adapter($name)->check($credentials, $options)) {
- if ($options['persist']) {
- foreach ($data as $key => $value) {
- if (!in_array($key, $options['persist'])) {
- unset($data[$key]);
- }
- }
- } else {
+ if ($options['persist'] && is_array($data)) {
+ $data = array_intersect_key($data, array_fill_keys($options['persist'], true));
+ } elseif (is_array($data)) {
unset($data['password']);
}
-
return ($options['writeSession']) ? $self::set($name, $data) : $data;
}
return false;
View
22 tests/cases/security/AuthTest.php
@@ -125,6 +125,28 @@ public function testAuthPersist() {
$result = Auth::check('test', $user, array('success' => true, 'checkSession' => false));
$this->assertEqual($expected, $result);
$this->assertEqual($expected, Session::read('test'));
+
+ Auth::reset();
+
+ Auth::config(array(
+ 'test' => array(
+ 'adapter' => $this->_classes['mockAuthAdapter'],
+ )
+ ));
+
+ $user = array(
+ 'id' => '123',
+ 'username' => 'foobar',
+ 'password' => 'not!important',
+ 'email' => 'foo@bar.com',
+ 'insuranceNumer' => 1234567
+ );
+
+ $expected = 123;
+
+ $result = Auth::check('test', $user, array('keyOnly' => true, 'checkSession' => false));
+ $this->assertEqual($expected, $result);
+ $this->assertEqual($expected, Session::read('test'));
}
}
View
8 tests/mocks/security/auth/adapter/MockAuthAdapter.php
@@ -11,7 +11,13 @@
class MockAuthAdapter extends \lithium\core\Object {
public function check($credentials, array $options = array()) {
- return isset($options['success']) ? $credentials : false;
+ switch (true) {
+ case isset($options['success']):
+ return $credentials;
+ case isset($options['keyOnly']):
+ return $credentials['id'];
+ }
+ return false;
}
public function set($data, array $options = array()) {
Please sign in to comment.
Something went wrong with that request. Please try again.