From e45fcf43376dd48fd46d232c0dc9e3cfd57ad6f5 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 16 Dec 2009 22:39:01 -0500 Subject: [PATCH] Adding ability set component configuration from component settings for SecurityComponent. --- cake/libs/controller/components/security.php | 15 ++++++++++- .../controller/components/security.test.php | 25 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/components/security.php b/cake/libs/controller/components/security.php index 20de444b9..e8029b6a0 100644 --- a/cake/libs/controller/components/security.php +++ b/cake/libs/controller/components/security.php @@ -168,10 +168,23 @@ class SecurityComponent extends Object { */ var $_action = null; +/** + * Initialize the SecurityComponent + * + * @param object $controller Controller instance for the request + * @param array $settings Settings to set to the component + * @return void + * @access public + */ + function initialize(&$controller, $settings = array()) { + $this->_set($settings); + } + /** * Component startup. All security checking happens here. * * @param object $controller Instantiating controller + * @return void * @access public */ function startup(&$controller) { @@ -342,7 +355,7 @@ class SecurityComponent extends Object { if (strtolower($options['type']) == 'digest') { $out[] = 'qop="auth"'; $out[] = 'nonce="' . uniqid("") . '"'; - $out[] = 'opaque="' . md5($options['realm']).'"'; + $out[] = 'opaque="' . md5($options['realm']) . '"'; } return $auth . ' ' . implode(',', $out); diff --git a/cake/tests/cases/libs/controller/components/security.test.php b/cake/tests/cases/libs/controller/components/security.test.php index e4e17eb39..4f3ddd64f 100644 --- a/cake/tests/cases/libs/controller/components/security.test.php +++ b/cake/tests/cases/libs/controller/components/security.test.php @@ -166,6 +166,31 @@ class SecurityComponentTest extends CakeTestCase { unset($this->Controller); } +/** + * test that initalize can set properties. + * + * @return void + */ + function testInitialize() { + $settings = array( + 'requirePost' => array('edit', 'update'), + 'requireSecure' => array('update_account'), + 'requireGet' => array('index'), + 'validatePost' => false, + 'loginUsers' => array( + 'mark' => 'password' + ), + 'requireLogin' => array('login'), + ); + $this->Controller->Security->initialize($this->Controller, $settings); + $this->assertEqual($this->Controller->Security->requirePost, $settings['requirePost']); + $this->assertEqual($this->Controller->Security->requireSecure, $settings['requireSecure']); + $this->assertEqual($this->Controller->Security->requireGet, $settings['requireGet']); + $this->assertEqual($this->Controller->Security->validatePost, $settings['validatePost']); + $this->assertEqual($this->Controller->Security->loginUsers, $settings['loginUsers']); + $this->assertEqual($this->Controller->Security->requireLogin, $settings['requireLogin']); + } + /** * testStartup method *