diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown
index e4fa8921a28f0f6f1934af3a2d412914bbd9333c..3ef1a25616de0246337f558744390bc51c1b9238 100644
--- a/CHANGELOG.markdown
+++ b/CHANGELOG.markdown
@@ -1,3 +1,14 @@
+Update as of 8/15/2012
+======================
+* Refactored ACL functionality:
+  * Implementation is not bound to backend area anymore and moved to `Mage_Core` module
+  * Covered backwards-incompatible changes with additional migration tool (`dev/tools/migration/Acl`)
+* Implemented "move" layout directive and slightly modified behavior of "remove"
+* A failure in DB cleanup by integration testing framework is articulated more clearly by throwing `Magento_Exception`
+* Fixed security vulnerability of exploiting Magento "cookie restriction" feature
+* Fixed caching mechanism of loading modules declaration to not cause additional performance overhead
+* Adjusted include path in unit tests to use the original include path at the end, rather than at the beginning
+
 Update as of 8/9/2012
 =====================
 * Improvements:
diff --git a/app/code/core/Mage/Adminhtml/Block/Cache/Notifications.php b/app/code/core/Mage/Adminhtml/Block/Cache/Notifications.php
index ffc0b7c15ed56e3dbac73cb0c6ef87ece3ee9ed2..abf47e545fd06d05a7ba0bfcb884b685fd46f14a 100644
--- a/app/code/core/Mage/Adminhtml/Block/Cache/Notifications.php
+++ b/app/code/core/Mage/Adminhtml/Block/Cache/Notifications.php
@@ -58,7 +58,7 @@ class Mage_Adminhtml_Block_Cache_Notifications extends Mage_Adminhtml_Block_Temp
      */
     protected function _toHtml()
     {
-        if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::cache')) {
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::cache')) {
             return parent::_toHtml();
         }
         return '';
diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php
index d59e035653a47122f87512eae14eb29de0fded4f..27fa1d50a530bc7156ea5e67dd81dbef41439c6d 100644
--- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php
+++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php
@@ -99,7 +99,7 @@ class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes extends Mage_Admi
 
             // Add new attribute button if it is not an image tab
             if (!$form->getElement('media_gallery')
-                && Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Catalog::attributes_attributes')
+                && Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Catalog::attributes_attributes')
             ) {
                 $headerBar = $this->getLayout()->createBlock('Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes_Create');
 
diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php
index 6962d1cd6fdd847875e20b281b7a572e613d3473..22ea61a87c20be96fa157efbfecfc10cc85abede 100644
--- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php
+++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php
@@ -146,7 +146,7 @@ class Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs extends Mage_Adminhtml_Bloc
 
             if( $this->getRequest()->getParam('id', false) ) {
                 if (Mage::helper('Mage_Catalog_Helper_Data')->isModuleEnabled('Mage_Review')) {
-                    if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Review::reviews_ratings')){
+                    if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Review::reviews_ratings')){
                         $this->addTab('reviews', array(
                             'label' => Mage::helper('Mage_Catalog_Helper_Data')->__('Product Reviews'),
                             'url'   => $this->getUrl('*/*/reviews', array('_current' => true)),
@@ -155,7 +155,7 @@ class Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs extends Mage_Adminhtml_Bloc
                     }
                 }
                 if (Mage::helper('Mage_Catalog_Helper_Data')->isModuleEnabled('Mage_Tag')) {
-                    if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Tag::tag')){
+                    if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Tag::tag')){
                         $this->addTab('tags', array(
                          'label'     => Mage::helper('Mage_Catalog_Helper_Data')->__('Product Tags'),
                          'url'   => $this->getUrl('*/*/tagGrid', array('_current' => true)),
diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php
index b1e05d1488e6658db353af8996ed86930a0db5cc..6af8c9ec4b9447610d9d676b4b80f17e5f5a94cd 100644
--- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php
+++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php
@@ -301,7 +301,7 @@ class Mage_Adminhtml_Block_Catalog_Product_Grid extends Mage_Adminhtml_Block_Wid
              )
         ));
 
-        if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Catalog::update_attributes')){
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Catalog::update_attributes')){
             $this->getMassactionBlock()->addItem('attributes', array(
                 'label' => Mage::helper('Mage_Catalog_Helper_Data')->__('Update Attributes'),
                 'url'   => $this->getUrl('*/catalog_product_action_attribute/edit', array('_current'=>true))
diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page.php
index 6827bd3d05abe442668adc26f937e48e105ee668..027a5314d6c4a059c8d402bb961d8b231fc75094 100644
--- a/app/code/core/Mage/Adminhtml/Block/Cms/Page.php
+++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page.php
@@ -61,7 +61,7 @@ class Mage_Adminhtml_Block_Cms_Page extends Mage_Adminhtml_Block_Widget_Grid_Con
      */
     protected function _isAllowedAction($resourceId)
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($resourceId);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($resourceId);
     }
 
 }
diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php
index b90cfdc7e0696b29aee551770677fa35b38ea39f..b57d0095c88b6483e03ff2fec9bb85c894b78460 100644
--- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php
+++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php
@@ -86,7 +86,7 @@ class Mage_Adminhtml_Block_Cms_Page_Edit extends Mage_Adminhtml_Block_Widget_For
      */
     protected function _isAllowedAction($resourceId)
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($resourceId);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($resourceId);
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php
index c313a8fa69f2bf5d64a6ec501552827d8f679850..19512a04438c819f0deb66678d97294c5ec3c518 100644
--- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php
+++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php
@@ -148,6 +148,6 @@ class Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Content
      */
     protected function _isAllowedAction($resourceId)
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($resourceId);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($resourceId);
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php
index b8c103fbbccd2a372b02580ac2c8221996ebced8..06411eb16d6d8a2b39cee99c101a3ecc5e4d5b21 100644
--- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php
+++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php
@@ -181,6 +181,6 @@ class Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Design
      */
     protected function _isAllowedAction($resourceId)
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($resourceId);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($resourceId);
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php
index f769783d582fc76a5dcb7d973ae9d129a587b21a..a484591bb72ef40900e0c9746c316823a147345b 100644
--- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php
+++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php
@@ -172,6 +172,6 @@ class Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Main
      */
     protected function _isAllowedAction($resourceId)
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($resourceId);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($resourceId);
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php
index 0a0fee0a70be101e3ae5ce9dec1d5c61506cb6da..60c0431c803f2887d19249d5cad44eb52b3b3bb0 100644
--- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php
+++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php
@@ -130,6 +130,6 @@ class Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Meta
      */
     protected function _isAllowedAction($resourceId)
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($resourceId);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($resourceId);
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit.php
index 925ca5a63061028f06d0ece5bcce7fce8ed42d89..f1219490e98afd5066f8f778b3fca4a34cd256f4 100644
--- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit.php
+++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit.php
@@ -39,7 +39,7 @@ class Mage_Adminhtml_Block_Customer_Edit extends Mage_Adminhtml_Block_Widget_For
         $this->_controller = 'customer';
 
         if ($this->getCustomerId() &&
-            Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::create')) {
+            Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::create')) {
             $this->_addButton('order', array(
                 'label' => Mage::helper('Mage_Customer_Helper_Data')->__('Create Order'),
                 'onclick' => 'setLocation(\'' . $this->getCreateOrderUrl() . '\')',
diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php
index bc01c9afb9775115294c0b2692691c5f76228c3c..db6cef48a92ed57799ae6ff31a8d674e413bbed1 100644
--- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php
+++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php
@@ -44,15 +44,17 @@ class Mage_Adminhtml_Block_Customer_Edit_Tabs extends Mage_Adminhtml_Block_Widge
 
     protected function _beforeToHtml()
     {
-/*
-        if (Mage::registry('current_customer')->getId()) {
-            $this->addTab('view', array(
-                'label'     => Mage::helper('Mage_Customer_Helper_Data')->__('Customer View'),
-                'content'   => $this->getLayout()->createBlock('Mage_Adminhtml_Block_Customer_Edit_Tab_View')->toHtml(),
-                'active'    => true
-            ));
-        }
-*/
+        Magento_Profiler::start('customer/tabs');
+
+        /*
+                if (Mage::registry('current_customer')->getId()) {
+                    $this->addTab('view', array(
+                        'label'     => Mage::helper('Mage_Customer_Helper_Data')->__('Customer View'),
+                        'content'   => $this->getLayout()->createBlock('Mage_Adminhtml_Block_Customer_Edit_Tab_View')->toHtml(),
+                        'active'    => true
+                    ));
+                }
+        */
         $this->addTab('account', array(
             'label'     => Mage::helper('Mage_Customer_Helper_Data')->__('Account Information'),
             'content'   => $this->getLayout()
@@ -71,7 +73,7 @@ class Mage_Adminhtml_Block_Customer_Edit_Tabs extends Mage_Adminhtml_Block_Widge
 
         if (Mage::registry('current_customer')->getId()) {
 
-            if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::actions_view')) {
+            if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::actions_view')) {
                 $this->addTab('orders', array(
                     'label'     => Mage::helper('Mage_Customer_Helper_Data')->__('Orders'),
                     'class'     => 'ajax',
@@ -91,7 +93,7 @@ class Mage_Adminhtml_Block_Customer_Edit_Tabs extends Mage_Adminhtml_Block_Widge
                 'url'       => $this->getUrl('*/*/wishlist', array('_current' => true)),
             ));
 
-            if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Newsletter::subscriber')) {
+            if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Newsletter::subscriber')) {
                 $this->addTab('newsletter', array(
                     'label'     => Mage::helper('Mage_Customer_Helper_Data')->__('Newsletter'),
                     'content'   => $this->getLayout()
@@ -99,7 +101,7 @@ class Mage_Adminhtml_Block_Customer_Edit_Tabs extends Mage_Adminhtml_Block_Widge
                 ));
             }
 
-            if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Review::reviews_ratings')) {
+            if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Review::reviews_ratings')) {
                 $this->addTab('reviews', array(
                     'label'     => Mage::helper('Mage_Customer_Helper_Data')->__('Product Reviews'),
                     'class'     => 'ajax',
@@ -107,7 +109,7 @@ class Mage_Adminhtml_Block_Customer_Edit_Tabs extends Mage_Adminhtml_Block_Widge
                 ));
             }
 
-            if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Tag::tag')) {
+            if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Tag::tag')) {
                 $this->addTab('tags', array(
                     'label'     => Mage::helper('Mage_Customer_Helper_Data')->__('Product Tags'),
                     'class'     => 'ajax',
diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php
index 1853da19aaa6abfcd253c14d37235f4dcfa2fadd..bcd08de6f5105d9f9f98b0f5c1208c3c5cf833bc 100644
--- a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php
+++ b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php
@@ -160,7 +160,7 @@ class Mage_Adminhtml_Block_Customer_Online_Grid extends Mage_Adminhtml_Block_Wid
      */
     public function getRowUrl($row)
     {
-        return (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Customer::manage') && $row->getCustomerId())
+        return (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Customer::manage') && $row->getCustomerId())
             ? $this->getUrl('*/customer/edit', array('id' => $row->getCustomerId())) : '';
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/Block/Notification/Survey.php b/app/code/core/Mage/Adminhtml/Block/Notification/Survey.php
index 69f0bd17626fc4a849dee82a20191d221b6eb5c4..13eea1a92f78fa1eff4d478ab5fab5829605c94f 100644
--- a/app/code/core/Mage/Adminhtml/Block/Notification/Survey.php
+++ b/app/code/core/Mage/Adminhtml/Block/Notification/Survey.php
@@ -43,7 +43,8 @@ class Mage_Adminhtml_Block_Notification_Survey extends Mage_Adminhtml_Block_Temp
         $adminSession = Mage::getSingleton('Mage_Backend_Model_Auth_Session');
         $seconds = intval(date('s', time()));
         if ($adminSession->getHideSurveyQuestion()
-            || !$adminSession->isAllowed(Mage_Backend_Model_Acl_Config::ACL_RESOURCE_ALL)
+            || !Mage::getSingleton('Mage_Core_Model_Authorization')
+                ->isAllowed(Mage_Backend_Model_Acl_Config::ACL_RESOURCE_ALL)
             || Mage_AdminNotification_Model_Survey::isSurveyViewed()
             || !Mage_AdminNotification_Model_Survey::isSurveyUrlValid())
         {
diff --git a/app/code/core/Mage/Adminhtml/Block/Notification/Window.php b/app/code/core/Mage/Adminhtml/Block/Notification/Window.php
index a1b8641f981e87b6b209976a617891c56d8514dd..bd253f162aefd8cab58e565258b197f825797bd5 100644
--- a/app/code/core/Mage/Adminhtml/Block/Notification/Window.php
+++ b/app/code/core/Mage/Adminhtml/Block/Notification/Window.php
@@ -105,11 +105,6 @@ class Mage_Adminhtml_Block_Notification_Window extends Mage_Adminhtml_Block_Noti
             return false;
         }
 
-        if (!$this->_isAllowed()) {
-            $this->_available = false;
-            return false;
-        }
-
         if (is_null($this->_available)) {
             $this->_available = $this->isShow();
         }
@@ -163,16 +158,4 @@ class Mage_Adminhtml_Block_Notification_Window extends Mage_Adminhtml_Block_Noti
     {
         return strtolower(str_replace('SEVERITY_', '', $this->getNoticeSeverity()));
     }
-
-    /**
-     * Check if current block allowed in ACL
-     *
-     * @param string $resourcePath
-     * @return bool
-     */
-    protected function _isAllowed()
-    {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')
-            ->isAllowed('Mage_AdminNotification::show_toolbar');
-    }
 }
diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo/Grid.php
index 9f0e120df8979ba8d2fdf76a95e54c3b904c952b..7579cd3e99050e9eb2d8eacf5978d53ad3f97f0a 100644
--- a/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo/Grid.php
+++ b/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo/Grid.php
@@ -144,7 +144,7 @@ class Mage_Adminhtml_Block_Sales_Creditmemo_Grid extends Mage_Adminhtml_Block_Wi
 
     public function getRowUrl($row)
     {
-        if (!Mage::getSingleton('Mage_Backend_Model_Auth_Session')
+        if (!Mage::getSingleton('Mage_Core_Model_Authorization')
             ->isAllowed(Mage_Backend_Model_Acl_Config::ACL_RESOURCE_ALL)
         ) {
             return false;
diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php
index 11bba3e79f8a42af8aa8f74558c742c1ff184e94..92c79d40cd47a6047e265b0a79ca63a4a5b6795a 100644
--- a/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php
+++ b/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php
@@ -145,7 +145,7 @@ class Mage_Adminhtml_Block_Sales_Invoice_Grid extends Mage_Adminhtml_Block_Widge
 
     public function getRowUrl($row)
     {
-        if (!Mage::getSingleton('Mage_Backend_Model_Auth_Session')
+        if (!Mage::getSingleton('Mage_Core_Model_Authorization')
             ->isAllowed(Mage_Backend_Model_Acl_Config::ACL_RESOURCE_ALL)
         ) {
             return false;
diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php
index d4511a3c948368ab919add1af7f9826f66de1133..9a54ef7c49889e87ed741d61a22c7cbce5134359 100644
--- a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php
+++ b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php
@@ -486,7 +486,7 @@ class  Mage_Adminhtml_Block_Sales_Items_Abstract extends Mage_Adminhtml_Block_Te
 
     public function canCapture()
     {
-        if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::capture')) {
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::capture')) {
             return $this->getInvoice()->canCapture();
         }
         return false;
diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order.php
index 4e69ae3a1f2ad8c89c1141a68420ccef8bf4a5ba..487ad3c62015dcb309c3091fb7c6575d89b8604a 100644
--- a/app/code/core/Mage/Adminhtml/Block/Sales/Order.php
+++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order.php
@@ -40,7 +40,7 @@ class Mage_Adminhtml_Block_Sales_Order extends Mage_Adminhtml_Block_Widget_Grid_
         $this->_headerText = Mage::helper('Mage_Sales_Helper_Data')->__('Orders');
         $this->_addButtonLabel = Mage::helper('Mage_Sales_Helper_Data')->__('Create New Order');
         parent::__construct();
-        if (!Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::create')) {
+        if (!Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::create')) {
             $this->_removeButton('add');
         }
     }
diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php
index eca52226a3a616d2e3e680f242eda8a1813bc037..0672e14faa74c7667dfd9135f59f4fe36cafe09e 100644
--- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php
+++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php
@@ -229,6 +229,6 @@ class Mage_Adminhtml_Block_Sales_Order_Creditmemo_View extends Mage_Adminhtml_Bl
      */
     public function _isAllowedAction($resourceId)
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($resourceId);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($resourceId);
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
index 86281a96448bbb75e0bcb37a9c7fe78d7383d3a6..cc5917ab493abedf9ec85e883f93f6203d0334e6 100644
--- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
+++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
@@ -120,7 +120,7 @@ class Mage_Adminhtml_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_
             'options' => Mage::getSingleton('Mage_Sales_Model_Order_Config')->getStatuses(),
         ));
 
-        if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::actions_view')) {
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::actions_view')) {
             $this->addColumn('action',
                 array(
                     'header'    => Mage::helper('Mage_Sales_Helper_Data')->__('Action'),
@@ -154,21 +154,21 @@ class Mage_Adminhtml_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_
         $this->getMassactionBlock()->setFormFieldName('order_ids');
         $this->getMassactionBlock()->setUseSelectAll(false);
 
-        if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::cancel')) {
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::cancel')) {
             $this->getMassactionBlock()->addItem('cancel_order', array(
                  'label'=> Mage::helper('Mage_Sales_Helper_Data')->__('Cancel'),
                  'url'  => $this->getUrl('*/sales_order/massCancel'),
             ));
         }
 
-        if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::hold')) {
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::hold')) {
             $this->getMassactionBlock()->addItem('hold_order', array(
                  'label'=> Mage::helper('Mage_Sales_Helper_Data')->__('Hold'),
                  'url'  => $this->getUrl('*/sales_order/massHold'),
             ));
         }
 
-        if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::unhold')) {
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::unhold')) {
             $this->getMassactionBlock()->addItem('unhold_order', array(
                  'label'=> Mage::helper('Mage_Sales_Helper_Data')->__('Unhold'),
                  'url'  => $this->getUrl('*/sales_order/massUnhold'),
@@ -205,7 +205,7 @@ class Mage_Adminhtml_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_
 
     public function getRowUrl($row)
     {
-        if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::actions_view')) {
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::actions_view')) {
             return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId()));
         }
         return false;
diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Items.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Items.php
index 18544652eb4054f60d483f9b707d2ba6b057742a..16b4b14951821f7771d2103e86d0036552f77574 100644
--- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Items.php
+++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Items.php
@@ -194,7 +194,7 @@ class Mage_Adminhtml_Block_Sales_Order_Invoice_Create_Items extends Mage_Adminht
      */
     public function isCaptureAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::capture');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::capture');
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php
index 72351ebedab637abcb7d196fa235e09ea4f76c46..3049d74fd084e76c3f5f54816bdc21e4efae5a1d 100644
--- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php
+++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php
@@ -207,6 +207,6 @@ class Mage_Adminhtml_Block_Sales_Order_Invoice_View extends Mage_Adminhtml_Block
      */
     protected function _isAllowedAction($resourceId)
     {
-        return $this->_session->isAllowed($resourceId);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($resourceId);
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php
index 7622144c62c592e518c863f733de9acbbb6180cb..702546e09e570beaeae5a3e71b7e5e011358c95e 100644
--- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php
+++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php
@@ -48,7 +48,7 @@ class Mage_Adminhtml_Block_Sales_Order_Shipment_View extends Mage_Adminhtml_Bloc
             return;
         }
 
-        if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::emails')) {
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::emails')) {
             $this->_updateButton('save', 'label', Mage::helper('Mage_Sales_Helper_Data')->__('Send Tracking Information'));
             $this->_updateButton('save',
                 'onclick', "deleteConfirm('"
diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php
index 2cd03218eaddf15a0df2d3996e576f267bdcac84..034c7ced525b15bdb531034ecc0735b3fa0712e5 100644
--- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php
+++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php
@@ -278,7 +278,7 @@ class Mage_Adminhtml_Block_Sales_Order_View extends Mage_Adminhtml_Block_Widget_
 
     protected function _isAllowedAction($resourceId)
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($resourceId);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($resourceId);
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php
index a5a1a18475129f4f6f25215c60a6f4e80aaf804e..61e87acaa6528c9be6c0991d415130edc009e5e8 100644
--- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php
+++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php
@@ -70,7 +70,7 @@ class Mage_Adminhtml_Block_Sales_Order_View_History extends Mage_Adminhtml_Block
 
     public function canAddComment()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::comment') &&
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::comment') &&
                $this->getOrder()->canComment();
     }
 
diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Transactions.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Transactions.php
index 04d80a76047874a19282c6d54f99e58482ad3a20..e558d5a6ec98c4c12158c118a77c85a6bd6a6aff 100644
--- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Transactions.php
+++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Transactions.php
@@ -93,6 +93,6 @@ class Mage_Adminhtml_Block_Sales_Order_View_Tab_Transactions
      */
     public function isHidden()
     {
-        return !Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::transactions_fetch');
+        return !Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::transactions_fetch');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Shipment/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Shipment/Grid.php
index 5b5b8cb0ad24ac95c09a84ea70df29a0f6368003..2a6f1480da532b3debae1def21274cccd5ed1797 100644
--- a/app/code/core/Mage/Adminhtml/Block/Sales/Shipment/Grid.php
+++ b/app/code/core/Mage/Adminhtml/Block/Sales/Shipment/Grid.php
@@ -139,7 +139,7 @@ class Mage_Adminhtml_Block_Sales_Shipment_Grid extends Mage_Adminhtml_Block_Widg
      */
     public function getRowUrl($row)
     {
-        if (!Mage::getSingleton('Mage_Backend_Model_Auth_Session')
+        if (!Mage::getSingleton('Mage_Core_Model_Authorization')
             ->isAllowed(Mage_Backend_Model_Acl_Config::ACL_RESOURCE_ALL)
         ) {
             return false;
diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php
index b2aaab310f1268255a2592ad8d541c26796c351d..2ba5da7b01f016d46244d58f096d4a04f219645e 100644
--- a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php
+++ b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php
@@ -60,7 +60,7 @@ class Mage_Adminhtml_Block_Sales_Transactions_Detail extends Mage_Adminhtml_Bloc
             'class'   => 'back'
         ));
 
-        if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::transactions_fetch')
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::transactions_fetch')
             && $this->_txn->getOrderPaymentObject()->getMethodInstance()->canFetchTransactionInfo()) {
             $fetchUrl = $this->getUrl('*/*/fetch' , array('_current' => true));
             $this->_addButton('fetch', array(
diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Tabs.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Tabs.php
index e9896c914a106e7a11872a5f86f3c844900d0f24..1cc46e41f3d5f5f966e9dde6dd61a29699a24059 100644
--- a/app/code/core/Mage/Adminhtml/Block/System/Config/Tabs.php
+++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Tabs.php
@@ -327,7 +327,7 @@ class Mage_Adminhtml_Block_System_Config_Tabs extends Mage_Adminhtml_Block_Widge
         }
 
         if (!$permissions) {
-            $permissions = Mage::getSingleton('Mage_Backend_Model_Auth_Session');
+            $permissions = Mage::getSingleton('Mage_Core_Model_Authorization');
         }
 
         $showTab = false;
diff --git a/app/code/core/Mage/Adminhtml/Controller/Action.php b/app/code/core/Mage/Adminhtml/Controller/Action.php
index 54ebd7176009428461b72e57c25ce28cfcf4e86f..85a9782a2def753344ea7422f7c4807792626fb0 100644
--- a/app/code/core/Mage/Adminhtml/Controller/Action.php
+++ b/app/code/core/Mage/Adminhtml/Controller/Action.php
@@ -42,6 +42,27 @@ class Mage_Adminhtml_Controller_Action extends Mage_Backend_Controller_ActionAbs
      */
     protected $_currentArea = 'adminhtml';
 
+    /**
+     * @var Mage_Core_Model_Translate
+     */
+    protected $_translator;
+
+    /**
+     * Constructor
+     *
+     * @param Zend_Controller_Request_Abstract $request
+     * @param Zend_Controller_Response_Abstract $response
+     * @param array $invokeArgs
+     */
+    public function __construct(Zend_Controller_Request_Abstract $request,
+                                Zend_Controller_Response_Abstract $response,
+                                array $invokeArgs = array()
+    ) {
+        parent::__construct($request, $response, $invokeArgs);
+
+        $this->_translator = isset($invokeArgs['translator']) ? $invokeArgs['translator'] : $this->_getTranslator();
+    }
+
     /**
      * Translate a phrase
      *
@@ -52,7 +73,20 @@ class Mage_Adminhtml_Controller_Action extends Mage_Backend_Controller_ActionAbs
         $args = func_get_args();
         $expr = new Mage_Core_Model_Translate_Expr(array_shift($args), $this->getUsedModuleName());
         array_unshift($args, $expr);
-        return Mage::app()->getTranslator()->translate($args);
+        return $this->_getTranslator()->translate($args);
+    }
+
+    /**
+     * Get translator model
+     *
+     * @return Mage_Core_Model_Translate
+     */
+    protected function _getTranslator()
+    {
+        if (null === $this->_translator) {
+            $this->_translator = Mage::app()->getTranslator();
+        }
+        return $this->_translator;
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/Controller/Sales/Creditmemo.php b/app/code/core/Mage/Adminhtml/Controller/Sales/Creditmemo.php
index 74d04c84d3af44825b56919d0e28a6b7592eeeff..8c31adc695857c9c47a691e3e3425e3e54abd60d 100644
--- a/app/code/core/Mage/Adminhtml/Controller/Sales/Creditmemo.php
+++ b/app/code/core/Mage/Adminhtml/Controller/Sales/Creditmemo.php
@@ -136,6 +136,6 @@ class Mage_Adminhtml_Controller_Sales_Creditmemo extends Mage_Adminhtml_Controll
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::sales_creditmemo');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::sales_creditmemo');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php b/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php
index 2d2f50725ee160105d7e1bbc1394e0dcaae433d3..c89f8e08ea37e3d5712fe5cd57a1ad01669bb414 100644
--- a/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php
+++ b/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php
@@ -148,7 +148,7 @@ class Mage_Adminhtml_Controller_Sales_Invoice extends Mage_Adminhtml_Controller_
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::sales_invoice');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::sales_invoice');
     }
 
 }
diff --git a/app/code/core/Mage/Adminhtml/Controller/Sales/Shipment.php b/app/code/core/Mage/Adminhtml/Controller/Sales/Shipment.php
index f9719af0ee0b53ed6b3490d35b356099ba8b3e7f..e9803ca0b165df3a71343adf8b6b85da70a97486 100644
--- a/app/code/core/Mage/Adminhtml/Controller/Sales/Shipment.php
+++ b/app/code/core/Mage/Adminhtml/Controller/Sales/Shipment.php
@@ -114,6 +114,6 @@ class Mage_Adminhtml_Controller_Sales_Shipment extends Mage_Adminhtml_Controller
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::shipment');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::shipment');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php b/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php
index 21e88f16fe96f14423674136bf0bf7c9dbbf7982..c05302bac191705458e35bb2ca6bd73205f3f1d0 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php
@@ -212,6 +212,6 @@ class Mage_Adminhtml_Api_RoleController extends Mage_Adminhtml_Controller_Action
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Api::roles');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Api::roles');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php b/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php
index d4bcfe560102b7ddbe92316165a60ad32e3ee861..07f515e6460025a7451953979faf0652ab18bb7e 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php
@@ -184,7 +184,7 @@ class Mage_Adminhtml_Api_UserController extends Mage_Adminhtml_Controller_Action
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Api::users');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Api::users');
     }
 
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/CacheController.php b/app/code/core/Mage/Adminhtml/controllers/CacheController.php
index ba3f027146e7a79c225b62985ef5fe21bc226bab..4f8273bd2f7de91e829e132faa7b95e0c421d600 100644
--- a/app/code/core/Mage/Adminhtml/controllers/CacheController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/CacheController.php
@@ -190,6 +190,6 @@ class Mage_Adminhtml_CacheController extends Mage_Adminhtml_Controller_Action
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::cache');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::cache');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php
index 02c3f196f260797412ada81c34f8c8df702998a6..d4e7439ed7f438f31aa22f26f363632ec1c42c8f 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php
@@ -509,6 +509,6 @@ class Mage_Adminhtml_Catalog_CategoryController extends Mage_Adminhtml_Controlle
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Catalog::categories');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Catalog::categories');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php
index f34b6481914327d8a0a86b6f24dc2d5a80661749..1bf140d33db6c869aac3178a059a2d4b8f796cf7 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php
@@ -216,7 +216,7 @@ class Mage_Adminhtml_Catalog_Product_Action_AttributeController extends Mage_Adm
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Catalog::update_attributes');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Catalog::update_attributes');
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php
index 40aeffa9c1ce2a29d857fb82fbb988b7ee9c006e..dfd09d36c3e3c47ee1d693534927a21d3f85d703 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php
@@ -401,6 +401,6 @@ class Mage_Adminhtml_Catalog_Product_AttributeController extends Mage_Adminhtml_
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Catalog::attributes_attributes');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Catalog::attributes_attributes');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php
index e07f15e71c7302c99755848869381b99214e442e..fae60b9d6936efcd2e541f7aad979a25345d7299 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php
@@ -78,6 +78,6 @@ class Mage_Adminhtml_Catalog_Product_GalleryController extends Mage_Adminhtml_Co
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Catalog::products');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Catalog::products');
     }
 } // Class Mage_Adminhtml_Catalog_Product_GalleryController End
diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GroupController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GroupController.php
index 800b12a711a8b0eaf06d2b16395c55b45c16fe68..57dc66c5a089f308b0533d52e007bab57101fc17 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GroupController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GroupController.php
@@ -46,6 +46,6 @@ class Mage_Adminhtml_Catalog_Product_GroupController extends Mage_Adminhtml_Cont
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Catalog::products');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Catalog::products');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php
index 31011e9f8f99c7d26dd08effa01a9fab9be6adc5..0e0d74dfed0a404f1558d95c6903f36fbbd80943 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php
@@ -381,10 +381,10 @@ class Mage_Adminhtml_Catalog_Product_ReviewController extends Mage_Adminhtml_Con
     {
         switch ($this->getRequest()->getActionName()) {
             case 'pending':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Review::pending');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Review::pending');
                 break;
             default:
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Review::reviews_all');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Review::reviews_all');
                 break;
         }
     }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php
index ddc7fa36b010254cfd4c9fe795424feba3b10c89..658d1d7de9e76d7da600dd3cf0768caa3872f60d 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php
@@ -226,7 +226,7 @@ class Mage_Adminhtml_Catalog_Product_SetController extends Mage_Adminhtml_Contro
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Catalog::sets');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Catalog::sets');
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php
index d746a216cbe5a1512ea830f3ec946f4f78d856c6..38e1ec2370f7c223f1250723456db888ca1c8f49 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php
@@ -1075,7 +1075,7 @@ class Mage_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Controller
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Catalog::products');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Catalog::products');
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php
index ad90e074a4bb16b85f484c93e463dca260c561fd..58c86a7a44e1a0c988badd301f8122eff446c608 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php
@@ -190,6 +190,6 @@ class Mage_Adminhtml_Catalog_SearchController extends Mage_Adminhtml_Controller_
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_CatalogSearch::search');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_CatalogSearch::search');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Checkout/AgreementController.php b/app/code/core/Mage/Adminhtml/controllers/Checkout/AgreementController.php
index 2660d1f7b6c976eba6896cda761135e6b1c0fab3..85a94037e00f0176fc5b8b8381ba16119dfe2de8 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Checkout/AgreementController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Checkout/AgreementController.php
@@ -162,6 +162,6 @@ class Mage_Adminhtml_Checkout_AgreementController extends Mage_Adminhtml_Control
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Checkout::checkoutagreement');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Checkout::checkoutagreement');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Cms/BlockController.php b/app/code/core/Mage/Adminhtml/controllers/Cms/BlockController.php
index 2964bc0aa22c1c71971ab9e1b18aea89313c1c42..2df2e1d1a8e822bb8be3af0419eede2e16a250d2 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Cms/BlockController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Cms/BlockController.php
@@ -200,6 +200,6 @@ class Mage_Adminhtml_Cms_BlockController extends Mage_Adminhtml_Controller_Actio
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Cms::block');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Cms::block');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php b/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php
index d3aab7a52c674c09ce1641e643d3de9acae6ad5c..3c8a0695144a97d39a89436779636a4002e8ee03 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php
@@ -225,13 +225,13 @@ class Mage_Adminhtml_Cms_PageController extends Mage_Adminhtml_Controller_Action
         switch ($this->getRequest()->getActionName()) {
             case 'new':
             case 'save':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Cms::save');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Cms::save');
                 break;
             case 'delete':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Cms::page_delete');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Cms::page_delete');
                 break;
             default:
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Cms::page');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Cms::page');
                 break;
         }
     }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php b/app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php
index 21b14837e8407ce80ad8231214158bb86b2869b4..fc15d442c9e3b6840fcda62762ffbde579d6dd89 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php
@@ -229,6 +229,6 @@ class Mage_Adminhtml_Cms_Wysiwyg_ImagesController extends Mage_Adminhtml_Control
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Cms::media_gallery');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Cms::media_gallery');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Cart/Product/Composite/CartController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Cart/Product/Composite/CartController.php
index f8775bafc20ee11536f23d0e1a61d485ff8c82ca..47747792c80e91ce2c7a78c3d479ffd19d4bc1ad 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Customer/Cart/Product/Composite/CartController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Cart/Product/Composite/CartController.php
@@ -155,6 +155,6 @@ class Mage_Adminhtml_Customer_Cart_Product_Composite_CartController extends Mage
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Customer::manage');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Customer::manage');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php
index decb55ae780bd0773df19561f164edc666355283..a6f5fb33249959af5f6d2ef152d357fe4fff622d 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php
@@ -154,6 +154,6 @@ class Mage_Adminhtml_Customer_GroupController extends Mage_Adminhtml_Controller_
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Customer::group');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Customer::group');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/OnlineController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/OnlineController.php
index 3d0f3b21a3f94b315c58d2b6bb85da44cc684d2d..b845f4cc4a84b59e44b372c20c8b34e1b5f825bf 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Customer/OnlineController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Customer/OnlineController.php
@@ -49,6 +49,6 @@ class Mage_Adminhtml_Customer_OnlineController extends Mage_Adminhtml_Controller
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Customer::online');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Customer::online');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Wishlist/Product/Composite/WishlistController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Wishlist/Product/Composite/WishlistController.php
index 101d0fde5548a81ffe840a9b34c0296124b7bae3..8b2accc33fc40032df55d3ceab1716661d0c5e51 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Customer/Wishlist/Product/Composite/WishlistController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Wishlist/Product/Composite/WishlistController.php
@@ -142,6 +142,6 @@ class Mage_Adminhtml_Customer_Wishlist_Product_Composite_WishlistController
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Customer::manage');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Customer::manage');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php
index da83fb91459548ff21ff4deabbaac7f9b516d76f..b4055b650217632f4495e23dfe4c878735c911f2 100644
--- a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php
@@ -34,18 +34,72 @@
 class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
 {
 
+    /**
+     * @var Mage_Core_Model_Config
+     */
+    protected $_objectFactory;
+
+    /**
+     * Event manager
+     *
+     * @var Mage_Core_Model_Event_Manager
+     */
+    protected $_eventManager;
+
+    /**
+     * Registry model
+     *
+     * @var Mage_Core_Model_Registry
+     */
+    protected $_registryManager;
+
+    /**
+     * ACL
+     *
+     * @var Mage_Backend_Model_Auth_Session
+     */
+    protected $_acl;
+
+    /**
+     * Constructor
+     *
+     * @param Zend_Controller_Request_Abstract $request
+     * @param Zend_Controller_Response_Abstract $response
+     * @param array $invokeArgs
+     */
+    public function __construct(Zend_Controller_Request_Abstract $request,
+        Zend_Controller_Response_Abstract $response,
+        array $invokeArgs = array()
+    ) {
+        parent::__construct($request, $response, $invokeArgs);
+
+        $this->_objectFactory = isset($invokeArgs['objectFactory']) ? $invokeArgs['objectFactory'] : Mage::getConfig();
+
+        $this->_registryManager = isset($invokeArgs['registry']) ?
+            $invokeArgs['registry'] :
+            Mage::getSingleton('Mage_Core_Model_Registry');
+
+        $this->_acl = isset($invokeArgs['acl']) ?
+            $invokeArgs['acl'] :
+            Mage::getSingleton('Mage_Core_Model_Authorization');
+
+        $this->_eventManager = isset($invokeArgs['eventManager']) ?
+            $invokeArgs['eventManager'] :
+            Mage::getSingleton('Mage_Core_Model_Event_Manager');
+    }
+
     protected function _initCustomer($idFieldName = 'id')
     {
         $this->_title($this->__('Customers'))->_title($this->__('Manage Customers'));
 
         $customerId = (int) $this->getRequest()->getParam($idFieldName);
-        $customer = Mage::getModel('Mage_Customer_Model_Customer');
+        $customer = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Customer');
 
         if ($customerId) {
             $customer->load($customerId);
         }
 
-        Mage::register('current_customer', $customer);
+        $this->_registryManager->register('current_customer', $customer);
         return $this;
     }
 
@@ -77,8 +131,8 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
         /**
          * Add breadcrumb item
          */
-        $this->_addBreadcrumb(Mage::helper('Mage_Adminhtml_Helper_Data')->__('Customers'), Mage::helper('Mage_Adminhtml_Helper_Data')->__('Customers'));
-        $this->_addBreadcrumb(Mage::helper('Mage_Adminhtml_Helper_Data')->__('Manage Customers'), Mage::helper('Mage_Adminhtml_Helper_Data')->__('Manage Customers'));
+        $this->_addBreadcrumb($this->_getHelper()->__('Customers'), $this->_getHelper()->__('Customers'));
+        $this->_addBreadcrumb($this->_getHelper()->__('Manage Customers'), $this->_getHelper()->__('Manage Customers'));
 
         $this->renderLayout();
     }
@@ -98,10 +152,10 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
         $this->loadLayout();
 
         /* @var $customer Mage_Customer_Model_Customer */
-        $customer = Mage::registry('current_customer');
+        $customer = $this->_registryManager->registry('current_customer');
 
         // set entered data if was error when we do save
-        $data = Mage::getSingleton('Mage_Adminhtml_Model_Session')->getCustomerData(true);
+        $data = $this->_getSession()->getCustomerData(true);
 
         // restore data from SESSION
         if ($data) {
@@ -110,7 +164,7 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
 
             if (isset($data['account'])) {
                 /* @var $customerForm Mage_Customer_Model_Form */
-                $customerForm = Mage::getModel('Mage_Customer_Model_Form');
+                $customerForm = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Form');
                 $customerForm->setEntity($customer)
                     ->setFormCode('adminhtml_customer')
                     ->setIsAjaxRequest(true);
@@ -120,7 +174,7 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
 
             if (isset($data['address']) && is_array($data['address'])) {
                 /* @var $addressForm Mage_Customer_Model_Form */
-                $addressForm = Mage::getModel('Mage_Customer_Model_Form');
+                $addressForm = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Form');
                 $addressForm->setFormCode('adminhtml_customer_address');
 
                 foreach (array_keys($data['address']) as $addressId) {
@@ -130,7 +184,7 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
 
                     $address = $customer->getAddressItemById($addressId);
                     if (!$address) {
-                        $address = Mage::getModel('Mage_Customer_Model_Address');
+                        $address = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Address');
                         $customer->addAddress($address);
                     }
 
@@ -165,15 +219,15 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
     public function deleteAction()
     {
         $this->_initCustomer();
-        $customer = Mage::registry('current_customer');
+        $customer = $this->_registryManager->registry('current_customer');
         if ($customer->getId()) {
             try {
                 $customer->load($customer->getId());
                 $customer->delete();
-                Mage::getSingleton('Mage_Adminhtml_Model_Session')->addSuccess(Mage::helper('Mage_Adminhtml_Helper_Data')->__('The customer has been deleted.'));
+                $this->_getSession()->addSuccess($this->_getHelper()->__('The customer has been deleted.'));
             }
             catch (Exception $e){
-                Mage::getSingleton('Mage_Adminhtml_Model_Session')->addError($e->getMessage());
+                $this->_getSession()->addError($e->getMessage());
             }
         }
         $this->_redirect('*/customer');
@@ -186,184 +240,64 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
     {
         $data = $this->getRequest()->getPost();
         if ($data) {
-            $redirectBack = $this->getRequest()->getParam('back', false);
-            $this->_initCustomer('customer_id');
 
             /** @var $customer Mage_Customer_Model_Customer */
-            $customer = Mage::registry('current_customer');
-
-            /** @var $customerForm Mage_Customer_Model_Form */
-            $customerForm = Mage::getModel('Mage_Customer_Model_Form');
-            $customerForm->setEntity($customer)
-                ->setFormCode('adminhtml_customer')
-                ->ignoreInvisible(false)
-            ;
-
-            $formData = $customerForm->extractData($this->getRequest(), 'account');
-
-            // Handle 'disable auto_group_change' attribute
-            if (isset($formData['disable_auto_group_change'])) {
-                $formData['disable_auto_group_change'] = empty($formData['disable_auto_group_change']) ? '0' : '1';
-            }
-
-            $errors = $customerForm->validateData($formData);
-            if ($errors !== true) {
-                foreach ($errors as $error) {
-                    $this->_getSession()->addError($error);
-                }
-                $this->_getSession()->setCustomerData($data);
-                $this->getResponse()->setRedirect($this->getUrl('*/customer/edit', array('id' => $customer->getId())));
+            $this->_initCustomer('customer_id');
+            $customer = $this->_registryManager->registry('current_customer');
+            if (!$this->_processData($customer, $data)) {
                 return;
             }
 
-            $customerForm->compactData($formData);
-
             // Unset template data
             if (isset($data['address']['_template_'])) {
                 unset($data['address']['_template_']);
             }
 
-            $modifiedAddresses = array();
-            if (!empty($data['address'])) {
-                /** @var $addressForm Mage_Customer_Model_Form */
-                $addressForm = Mage::getModel('Mage_Customer_Model_Form');
-                $addressForm->setFormCode('adminhtml_customer_address')->ignoreInvisible(false);
-
-                foreach (array_keys($data['address']) as $index) {
-                    $address = $customer->getAddressItemById($index);
-                    if (!$address) {
-                        $address = Mage::getModel('Mage_Customer_Model_Address');
-                    }
-
-                    $requestScope = sprintf('address/%s', $index);
-                    $formData = $addressForm->setEntity($address)
-                        ->extractData($this->getRequest(), $requestScope);
-
-                    // Set default billing and shipping flags to address
-                    $isDefaultBilling = isset($data['account']['default_billing'])
-                        && $data['account']['default_billing'] == $index;
-                    $address->setIsDefaultBilling($isDefaultBilling);
-                    $isDefaultShipping = isset($data['account']['default_shipping'])
-                        && $data['account']['default_shipping'] == $index;
-                    $address->setIsDefaultShipping($isDefaultShipping);
-
-                    $errors = $addressForm->validateData($formData);
-                    if ($errors !== true) {
-                        foreach ($errors as $error) {
-                            $this->_getSession()->addError($error);
-                        }
-                        $this->_getSession()->setCustomerData($data);
-                        $this->getResponse()->setRedirect($this->getUrl('*/customer/edit', array(
-                            'id' => $customer->getId())
-                        ));
-                        return;
-                    }
-
-                    $addressForm->compactData($formData);
-
-                    // Set post_index for detect default billing and shipping addresses
-                    $address->setPostIndex($index);
-
-                    if ($address->getId()) {
-                        $modifiedAddresses[] = $address->getId();
-                    } else {
-                        $customer->addAddress($address);
-                    }
-                }
-            }
-
-            // Default billing and shipping
-            if (isset($data['account']['default_billing'])) {
-                $customer->setData('default_billing', $data['account']['default_billing']);
-            }
-            if (isset($data['account']['default_shipping'])) {
-                $customer->setData('default_shipping', $data['account']['default_shipping']);
-            }
-            if (isset($data['account']['confirmation'])) {
-                $customer->setData('confirmation', $data['account']['confirmation']);
-            }
-
-            // Mark not modified customer addresses for delete
-            foreach ($customer->getAddressesCollection() as $customerAddress) {
-                if ($customerAddress->getId() && !in_array($customerAddress->getId(), $modifiedAddresses)) {
-                    $customerAddress->setData('_deleted', true);
-                }
-            }
-
-            if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')
-                ->isAllowed(Mage_Backend_Model_Acl_Config::ACL_RESOURCE_ALL)
-                && !$customer->getConfirmation()
-            ) {
-                $customer->setIsSubscribed(isset($data['subscription']));
+            if (!$this->_processAddress($customer, $data)) {
+                return;
             }
 
-            if (isset($data['account']['sendemail_store_id'])) {
-                $customer->setSendemailStoreId($data['account']['sendemail_store_id']);
-            }
+            $this->_processSubscriptionOptions($customer, $data);
 
             $isNewCustomer = $customer->isObjectNew();
             try {
                 $sendPassToEmail = false;
                 // Force new customer confirmation
                 if ($isNewCustomer) {
-                    $customer->setPassword($data['account']['password']);
-                    $customer->setForceConfirmed(true);
-                    if ($customer->getPassword() == 'auto') {
-                        $sendPassToEmail = true;
-                        $customer->setPassword($customer->generatePassword());
-                    }
+                    $sendPassToEmail = $this->_processPassword($customer, $data);
                 }
 
-                Mage::dispatchEvent('adminhtml_customer_prepare_save', array(
-                    'customer'  => $customer,
-                    'request'   => $this->getRequest()
-                ));
+                $this->_eventManager->dispatch(
+                    'adminhtml_customer_prepare_save',
+                    array('customer' => $customer, 'request' => $this->getRequest())
+                );
 
                 $customer->save();
 
                 // Send welcome email
-                if ($customer->getWebsiteId() && (isset($data['account']['sendemail']) || $sendPassToEmail)) {
-                    $storeId = $customer->getSendemailStoreId();
-                    if ($isNewCustomer) {
-                        $customer->sendNewAccountEmail('registered', '', $storeId);
-                    } elseif ((!$customer->getConfirmation())) {
-                        // Confirm not confirmed customer
-                        $customer->sendNewAccountEmail('confirmed', '', $storeId);
-                    }
-                }
+                $data = $this->_sendWelcomeEmail($customer, $data, $sendPassToEmail, $isNewCustomer);
 
-                if (!empty($data['account']['new_password'])) {
-                    $newPassword = $data['account']['new_password'];
-                    if ($newPassword == 'auto') {
-                        $newPassword = $customer->generatePassword();
-                    }
-                    $customer->changePassword($newPassword);
-                    $customer->sendPasswordReminderEmail();
-                }
+                $data = $this->_changePassword($customer, $data);
 
-                Mage::getSingleton('Mage_Adminhtml_Model_Session')->addSuccess(
-                    Mage::helper('Mage_Adminhtml_Helper_Data')->__('The customer has been saved.')
+                $this->_session->addSuccess($this->_getHelper()->__('The customer has been saved.'));
+                $this->_eventManager->dispatch(
+                    'adminhtml_customer_save_after',
+                    array('customer'  => $customer, 'request'   => $this->getRequest())
                 );
-                Mage::dispatchEvent('adminhtml_customer_save_after', array(
-                    'customer'  => $customer,
-                    'request'   => $this->getRequest()
-                ));
 
-                if ($redirectBack) {
-                    $this->_redirect('*/*/edit', array(
-                        'id' => $customer->getId(),
-                        '_current' => true
-                    ));
+                if ($this->getRequest()->getParam('back', false)) {
+                    $this->_redirect('*/*/edit', array( 'id' => $customer->getId(), '_current' => true));
                     return;
                 }
             } catch (Mage_Core_Exception $e) {
-                $this->_getSession()->addError($e->getMessage());
-                $this->_getSession()->setCustomerData($data);
+                $this->_session->addError($e->getMessage());
+                $this->_session->setCustomerData($data);
                 $this->getResponse()->setRedirect($this->getUrl('*/customer/edit', array('id' => $customer->getId())));
+                return;
             } catch (Exception $e) {
-                $this->_getSession()->addException($e,
-                    Mage::helper('Mage_Adminhtml_Helper_Data')->__('An error occurred while saving the customer.'));
-                $this->_getSession()->setCustomerData($data);
+                $this->_session->addException($e,
+                    $this->_getHelper()->__('An error occurred while saving the customer.'));
+                $this->_session->setCustomerData($data);
                 $this->getResponse()->setRedirect($this->getUrl('*/customer/edit', array('id'=>$customer->getId())));
                 return;
             }
@@ -371,6 +305,211 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
         $this->getResponse()->setRedirect($this->getUrl('*/customer'));
     }
 
+    /**
+     * Set customer password
+     *
+     * @param Mage_Customer_Model_Customer $customer
+     * @param array $data
+     * @return bool
+     */
+    protected function _processPassword($customer, $data)
+    {
+        $customer->setPassword($data['account']['password']);
+        $customer->setForceConfirmed(true);
+        if ($customer->getPassword() == 'auto') {
+            $customer->setPassword($customer->generatePassword());
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Process subscription options
+     *
+     * @param Mage_Customer_Model_Customer $customer
+     * @param array $data
+     */
+    protected function _processSubscriptionOptions($customer, $data)
+    {
+        if (isset($data['account']['confirmation'])) {
+            $customer->setData('confirmation', $data['account']['confirmation']);
+        }
+
+        if ($this->_acl->isAllowed(Mage_Backend_Model_Acl_Config::ACL_RESOURCE_ALL)
+            && !$customer->getConfirmation()
+        ) {
+            $customer->setIsSubscribed(isset($data['subscription']));
+        }
+
+        if (isset($data['account']['sendemail_store_id'])) {
+            $customer->setSendemailStoreId($data['account']['sendemail_store_id']);
+        }
+    }
+
+    /**
+     * Change Password
+     *
+     * @param Mage_Customer_Model_Customer $customer
+     * @param array $data
+     * @return mixed
+     */
+    protected function _changePassword($customer, $data)
+    {
+        if (!empty($data['account']['new_password'])) {
+            $newPassword = $data['account']['new_password'];
+            if ($newPassword == 'auto') {
+                $newPassword = $customer->generatePassword();
+            }
+            $customer->changePassword($newPassword);
+            $customer->sendPasswordReminderEmail();
+            return $data;
+        }
+        return $data;
+    }
+
+    /**
+     * @param Mage_Customer_Model_Customer $customer
+     * @param array $data
+     * @param bool $sendPassToEmail
+     * @param bool $isNewCustomer
+     * @return mixed
+     */
+    protected function _sendWelcomeEmail($customer, $data, $sendPassToEmail, $isNewCustomer)
+    {
+        if ($customer->getWebsiteId() && (isset($data['account']['sendemail']) || $sendPassToEmail)) {
+            $storeId = $customer->getSendemailStoreId();
+            if ($isNewCustomer) {
+                $customer->sendNewAccountEmail('registered', '', $storeId);
+                return $data;
+            } elseif ((!$customer->getConfirmation())) {
+                // Confirm not confirmed customer
+                $customer->sendNewAccountEmail('confirmed', '', $storeId);
+                return $data;
+            }
+            return $data;
+        }
+        return $data;
+    }
+
+    /**
+     * Process customer address
+     *
+     * @param Mage_Customer_Model_Customer $customer
+     * @param array $data
+     * @return bool
+     */
+    protected function _processAddress($customer, $data)
+    {
+        $modifiedAddresses = array();
+        if (!empty($data['address'])) {
+            $modifiedAddresses = $this->_processAddresses($customer, $data);
+            if ($modifiedAddresses === false) {
+                return false;
+            }
+        }
+
+        // Default billing and shipping
+        if (isset($data['account']['default_billing'])) {
+            $customer->setData('default_billing', $data['account']['default_billing']);
+        }
+        if (isset($data['account']['default_shipping'])) {
+            $customer->setData('default_shipping', $data['account']['default_shipping']);
+        }
+
+        // Mark not modified customer addresses for delete
+        /** @var $customerAddress Mage_Customer_Model_Address */
+        foreach ($customer->getAddressesCollection() as $customerAddress) {
+            if ($customerAddress->getId() && !in_array($customerAddress->getId(), $modifiedAddresses)) {
+                $customerAddress->setData('_deleted', true);
+            }
+        }
+        return true;
+    }
+
+    protected function _processData($customer, $data)
+    {
+        /** @var $customerForm Mage_Customer_Model_Form */
+        $customerForm = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Form');
+        $customerForm->setEntity($customer)
+            ->setFormCode('adminhtml_customer')
+            ->ignoreInvisible(false);
+
+        $formData = $customerForm->extractData($this->getRequest(), 'account');
+
+        // Handle 'disable auto_group_change' attribute
+        if (isset($formData['disable_auto_group_change'])) {
+            $formData['disable_auto_group_change'] = empty($formData['disable_auto_group_change']) ? '0' : '1';
+        }
+
+        $errors = $customerForm->validateData($formData);
+        if ($errors !== true) {
+            foreach ($errors as $error) {
+                $this->_session->addError($error);
+            }
+            $this->_session->setCustomerData($data);
+            $this->getResponse()->setRedirect($this->getUrl('*/customer/edit', array('id' => $customer->getId())));
+            return false;
+        }
+
+        $customerForm->compactData($formData);
+        return true;
+    }
+
+    /**
+     * @param array $data
+     * @param Mage_Customer_Model_Customer $customer
+     * @return array
+     */
+    protected function _processAddresses($customer, $data)
+    {
+        /** @var $addressForm Mage_Customer_Model_Form */
+        $addressForm = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Form');
+        $addressForm->setFormCode('adminhtml_customer_address')->ignoreInvisible(false);
+
+        $modifiedAddresses = array();
+        foreach (array_keys($data['address']) as $index) {
+            $address = $customer->getAddressItemById($index);
+            if (!$address) {
+                $address = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Address');
+            }
+
+            $requestScope = sprintf('address/%s', $index);
+            $formData = $addressForm->setEntity($address)
+                ->extractData($this->getRequest(), $requestScope);
+
+            // Set default billing and shipping flags to address
+            $isDefaultBilling = isset($data['account']['default_billing'])
+                && $data['account']['default_billing'] == $index;
+            $address->setIsDefaultBilling($isDefaultBilling);
+            $isDefaultShipping = isset($data['account']['default_shipping'])
+                && $data['account']['default_shipping'] == $index;
+            $address->setIsDefaultShipping($isDefaultShipping);
+
+            $errors = $addressForm->validateData($formData);
+            if ($errors !== true) {
+                foreach ($errors as $error) {
+                    $this->_session->addError($error);
+                }
+                $this->_session->setCustomerData($data);
+                $this->getResponse()->setRedirect($this->getUrl('*/customer/edit', array(
+                        'id' => $customer->getId())
+                ));
+                return false;
+            }
+
+            $addressForm->compactData($formData);
+
+            // Set post_index for detect default billing and shipping addresses
+            $address->setPostIndex($index);
+            if ($address->getId()) {
+                $modifiedAddresses[] = $address->getId();
+            } else {
+                $customer->addAddress($address);
+            }
+        }
+        return $modifiedAddresses;
+    }
+
     /**
      * Export customer grid to CSV format
      */
@@ -399,7 +538,8 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
      * Customer orders grid
      *
      */
-    public function ordersAction() {
+    public function ordersAction()
+    {
         $this->_initCustomer();
         $this->loadLayout();
         $this->renderLayout();
@@ -409,7 +549,8 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
      * Customer last orders grid for ajax
      *
      */
-    public function lastOrdersAction() {
+    public function lastOrdersAction()
+    {
         $this->_initCustomer();
         $this->loadLayout();
         $this->renderLayout();
@@ -422,10 +563,10 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
     public function newsletterAction()
     {
         $this->_initCustomer();
-        $subscriber = Mage::getModel('Mage_Newsletter_Model_Subscriber')
-            ->loadByCustomer(Mage::registry('current_customer'));
+        $subscriber = $this->_objectFactory->getModelInstance('Mage_Newsletter_Model_Subscriber')
+            ->loadByCustomer($this->_registryManager->registry('current_customer'));
 
-        Mage::register('subscriber', $subscriber);
+        $this->_registryManager->register('subscriber', $subscriber);
         $this->loadLayout()
             ->renderLayout();
     }
@@ -433,11 +574,11 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
     public function wishlistAction()
     {
         $this->_initCustomer();
-        $customer = Mage::registry('current_customer');
+        $customer = $this->_registryManager->registry('current_customer');
         if ($customer->getId()) {
-            if($itemId = (int) $this->getRequest()->getParam('delete')) {
+            if ($itemId = (int) $this->getRequest()->getParam('delete')) {
                 try {
-                    Mage::getModel('Mage_Wishlist_Model_Item')->load($itemId)
+                    $this->_objectFactory->getModelInstance('Mage_Wishlist_Model_Item')->load($itemId)
                         ->delete();
                 }
                 catch (Exception $e) {
@@ -477,9 +618,9 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
         // delete an item from cart
         $deleteItemId = $this->getRequest()->getPost('delete');
         if ($deleteItemId) {
-            $quote = Mage::getModel('Mage_Sales_Model_Quote')
+            $quote = $this->_objectFactory->getModelInstance('Mage_Sales_Model_Quote')
                 ->setWebsite(Mage::app()->getWebsite($websiteId))
-                ->loadByCustomer(Mage::registry('current_customer'));
+                ->loadByCustomer($this->_registryManager->registry('current_customer'));
             $item = $quote->getItemById($deleteItemId);
             if ($item && $item->getId()) {
                 $quote->removeItem($deleteItemId);
@@ -499,7 +640,7 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
     public function viewCartAction()
     {
         $this->_initCustomer();
-        $layout = $this->loadLayout()
+        $this->loadLayout()
             ->getLayout()
             ->getBlock('admin.customer.view.cart')
             ->setWebsiteId();
@@ -527,7 +668,7 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
         $this->loadLayout()
             ->getLayout()
             ->getBlock('admin.customer.reviews')
-            ->setCustomerId(Mage::registry('current_customer')->getId())
+            ->setCustomerId($this->_registryManager->registry('current_customer')->getId())
             ->setUseAjax(true);
         $this->renderLayout();
     }
@@ -542,7 +683,7 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
         $this->loadLayout()
             ->getLayout()
             ->getBlock('admin.customer.tags')
-            ->setCustomerId(Mage::registry('current_customer')->getId())
+            ->setCustomerId($this->_registryManager->registry('current_customer')->getId())
             ->setUseAjax(true);
         $this->renderLayout();
     }
@@ -552,7 +693,7 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
         $this->_initCustomer();
         $this->loadLayout();
         $this->getLayout()->getBlock('admin.customer.tags')->setCustomerId(
-            Mage::registry('current_customer')
+            $this->_registryManager->registry('current_customer')
         );
         $this->renderLayout();
     }
@@ -564,7 +705,7 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
         $websiteId      = Mage::app()->getStore()->getWebsiteId();
         $accountData    = $this->getRequest()->getPost('account');
 
-        $customer = Mage::getModel('Mage_Customer_Model_Customer');
+        $customer = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Customer');
         $customerId = $this->getRequest()->getParam('id');
         if ($customerId) {
             $customer->load($customerId);
@@ -574,7 +715,7 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
         }
 
         /* @var $customerForm Mage_Customer_Model_Form */
-        $customerForm = Mage::getModel('Mage_Customer_Model_Form');
+        $customerForm = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Form');
         $customerForm->setEntity($customer)
             ->setFormCode('adminhtml_customer')
             ->setIsAjaxRequest(true)
@@ -594,13 +735,13 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
         if (!$response->getError()) {
             # Trying to load customer with the same email and return error message
             # if customer with the same email address exisits
-            $checkCustomer = Mage::getModel('Mage_Customer_Model_Customer')
+            $checkCustomer = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Customer')
                 ->setWebsiteId($websiteId);
             $checkCustomer->loadByEmail($accountData['email']);
             if ($checkCustomer->getId() && ($checkCustomer->getId() != $customer->getId())) {
                 $response->setError(1);
                 $this->_getSession()->addError(
-                    Mage::helper('Mage_Adminhtml_Helper_Data')->__('Customer with the same email already exists.')
+                    $this->_getHelper()->__('Customer with the same email already exists.')
                 );
             }
         }
@@ -608,7 +749,7 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
         $addressesData = $this->getRequest()->getParam('address');
         if (is_array($addressesData)) {
             /* @var $addressForm Mage_Customer_Model_Form */
-            $addressForm = Mage::getModel('Mage_Customer_Model_Form');
+            $addressForm = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Form');
             $addressForm->setFormCode('adminhtml_customer_address')->ignoreInvisible(false);
             foreach (array_keys($addressesData) as $index) {
                 if ($index == '_template_') {
@@ -616,7 +757,7 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
                 }
                 $address = $customer->getAddressItemById($index);
                 if (!$address) {
-                    $address   = Mage::getModel('Mage_Customer_Model_Address');
+                    $address   = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Address');
                 }
 
                 $requestScope = sprintf('address/%s', $index);
@@ -644,21 +785,22 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
     public function massSubscribeAction()
     {
         $customersIds = $this->getRequest()->getParam('customer');
-        if(!is_array($customersIds)) {
-             Mage::getSingleton('Mage_Adminhtml_Model_Session')->addError(Mage::helper('Mage_Adminhtml_Helper_Data')->__('Please select customer(s).'));
+        if (!is_array($customersIds)) {
+             $this->_getSession()->addError($this->_getHelper()->__('Please select customer(s).'));
 
         } else {
             try {
                 foreach ($customersIds as $customerId) {
-                    $customer = Mage::getModel('Mage_Customer_Model_Customer')->load($customerId);
+                    $customer = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Customer')
+                        ->load($customerId);
                     $customer->setIsSubscribed(true);
                     $customer->save();
                 }
-                Mage::getSingleton('Mage_Adminhtml_Model_Session')->addSuccess(
-                    Mage::helper('Mage_Adminhtml_Helper_Data')->__('Total of %d record(s) were updated.', count($customersIds))
+                $this->_getSession()->addSuccess(
+                    $this->_getHelper()->__('Total of %d record(s) were updated.', count($customersIds))
                 );
             } catch (Exception $e) {
-                Mage::getSingleton('Mage_Adminhtml_Model_Session')->addError($e->getMessage());
+                $this->_getSession()->addError($e->getMessage());
             }
         }
         $this->_redirect('*/*/index');
@@ -667,20 +809,21 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
     public function massUnsubscribeAction()
     {
         $customersIds = $this->getRequest()->getParam('customer');
-        if(!is_array($customersIds)) {
-             Mage::getSingleton('Mage_Adminhtml_Model_Session')->addError(Mage::helper('Mage_Adminhtml_Helper_Data')->__('Please select customer(s).'));
+        if (!is_array($customersIds)) {
+             $this->_getSession()->addError($this->_getHelper()->__('Please select customer(s).'));
         } else {
             try {
                 foreach ($customersIds as $customerId) {
-                    $customer = Mage::getModel('Mage_Customer_Model_Customer')->load($customerId);
+                    $customer = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Customer')
+                        ->load($customerId);
                     $customer->setIsSubscribed(false);
                     $customer->save();
                 }
-                Mage::getSingleton('Mage_Adminhtml_Model_Session')->addSuccess(
-                    Mage::helper('Mage_Adminhtml_Helper_Data')->__('Total of %d record(s) were updated.', count($customersIds))
+                $this->_getSession()->addSuccess(
+                    $this->_getHelper()->__('Total of %d record(s) were updated.', count($customersIds))
                 );
             } catch (Exception $e) {
-                Mage::getSingleton('Mage_Adminhtml_Model_Session')->addError($e->getMessage());
+                $this->_getSession()->addError($e->getMessage());
             }
         }
 
@@ -690,21 +833,21 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
     public function massDeleteAction()
     {
         $customersIds = $this->getRequest()->getParam('customer');
-        if(!is_array($customersIds)) {
-             Mage::getSingleton('Mage_Adminhtml_Model_Session')->addError(Mage::helper('Mage_Adminhtml_Helper_Data')->__('Please select customer(s).'));
+        if (!is_array($customersIds)) {
+             $this->_getSession()->addError($this->_getHelper()->__('Please select customer(s).'));
         } else {
             try {
-                $customer = Mage::getModel('Mage_Customer_Model_Customer');
+                $customer = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Customer');
                 foreach ($customersIds as $customerId) {
                     $customer->reset()
                         ->load($customerId)
                         ->delete();
                 }
-                Mage::getSingleton('Mage_Adminhtml_Model_Session')->addSuccess(
-                    Mage::helper('Mage_Adminhtml_Helper_Data')->__('Total of %d record(s) were deleted.', count($customersIds))
+                $this->_getSession()->addSuccess(
+                    $this->_getHelper()->__('Total of %d record(s) were deleted.', count($customersIds))
                 );
             } catch (Exception $e) {
-                Mage::getSingleton('Mage_Adminhtml_Model_Session')->addError($e->getMessage());
+                $this->_getSession()->addError($e->getMessage());
             }
         }
 
@@ -714,20 +857,21 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
     public function massAssignGroupAction()
     {
         $customersIds = $this->getRequest()->getParam('customer');
-        if(!is_array($customersIds)) {
-             Mage::getSingleton('Mage_Adminhtml_Model_Session')->addError(Mage::helper('Mage_Adminhtml_Helper_Data')->__('Please select customer(s).'));
+        if (!is_array($customersIds)) {
+             $this->_getSession()->addError($this->_getHelper()->__('Please select customer(s).'));
         } else {
             try {
                 foreach ($customersIds as $customerId) {
-                    $customer = Mage::getModel('Mage_Customer_Model_Customer')->load($customerId);
+                    $customer = $this->_objectFactory->getModelInstance('Mage_Customer_Model_Customer')
+                        ->load($customerId);
                     $customer->setGroupId($this->getRequest()->getParam('group'));
                     $customer->save();
                 }
-                Mage::getSingleton('Mage_Adminhtml_Model_Session')->addSuccess(
-                    Mage::helper('Mage_Adminhtml_Helper_Data')->__('Total of %d record(s) were updated.', count($customersIds))
+                $this->_getSession()->addSuccess(
+                    $this->_getHelper()->__('Total of %d record(s) were updated.', count($customersIds))
                 );
             } catch (Exception $e) {
-                Mage::getSingleton('Mage_Adminhtml_Model_Session')->addError($e->getMessage());
+                $this->_getSession()->addError($e->getMessage());
             }
         }
 
@@ -808,7 +952,7 @@ class Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Customer::manage');
+        return $this->_acl->isAllowed('Mage_Customer::manage');
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/controllers/DashboardController.php b/app/code/core/Mage/Adminhtml/controllers/DashboardController.php
index d6e5976a743e3449935788532aff2848644381d9..01a70282e087453cbcd7152572e68107e60dc918 100644
--- a/app/code/core/Mage/Adminhtml/controllers/DashboardController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/DashboardController.php
@@ -112,6 +112,6 @@ class Mage_Adminhtml_DashboardController extends Mage_Adminhtml_Controller_Actio
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::dashboard');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::dashboard');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/IndexController.php b/app/code/core/Mage/Adminhtml/controllers/IndexController.php
index cfe5806c5a39d2a06837ecc2057d09a560c68dfc..480f4b690d220beaf441c0079b10ea85f2aab966 100644
--- a/app/code/core/Mage/Adminhtml/controllers/IndexController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/IndexController.php
@@ -42,7 +42,7 @@ class Mage_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
         $searchModules = Mage::getConfig()->getNode("adminhtml/global_search");
         $items = array();
 
-        if (!Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::global_search')) {
+        if (!Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::global_search')) {
             $items[] = array(
                 'id' => 'error',
                 'type' => Mage::helper('Mage_Adminhtml_Helper_Data')->__('Error'),
@@ -65,7 +65,7 @@ class Mage_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
                 $query = $this->getRequest()->getParam('query', '');
                 foreach ($searchModules->children() as $searchConfig) {
 
-                    if ($searchConfig->acl && !Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($searchConfig->acl)){
+                    if ($searchConfig->acl && !Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($searchConfig->acl)){
                         continue;
                     }
 
diff --git a/app/code/core/Mage/Adminhtml/controllers/Media/EditorController.php b/app/code/core/Mage/Adminhtml/controllers/Media/EditorController.php
index d63e813564e485f522afdd4e6396fdd28161c9e5..bebc00cf610f4f3000c931878bae029957aacfe2 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Media/EditorController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Media/EditorController.php
@@ -45,7 +45,7 @@ class Mage_Adminhtml_Media_EditorController extends Mage_Adminhtml_Controller_Ac
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed(
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed(
             Mage_Backend_Model_Acl_Config::ACL_RESOURCE_ALL
         );
     }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Media/UploaderController.php b/app/code/core/Mage/Adminhtml/controllers/Media/UploaderController.php
index db854125468de73eb18c8104c5680ee4afff81b7..e94e1820bbddaf391af44822f3882a7eee91d5e2 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Media/UploaderController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Media/UploaderController.php
@@ -50,7 +50,7 @@ class Mage_Adminhtml_Media_UploaderController extends Mage_Adminhtml_Controller_
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')
+        return Mage::getSingleton('Mage_Core_Model_Authorization')
             ->isAllowed(Mage_Backend_Model_Acl_Config::ACL_RESOURCE_ALL);
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Newsletter/ProblemController.php b/app/code/core/Mage/Adminhtml/controllers/Newsletter/ProblemController.php
index c1a9c941c216878bc99b31970cf8588c0105e9b8..2d30cc5459ad67fa8d9d2fcf3c2ea6eb00c676c9 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Newsletter/ProblemController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Newsletter/ProblemController.php
@@ -99,6 +99,6 @@ class Mage_Adminhtml_Newsletter_ProblemController extends Mage_Adminhtml_Control
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Newsletter::problem');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Newsletter::problem');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php b/app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php
index 8f548aeeb5bdb8f4005ffe7915d3b6bba94ba3ae..ce540fc28aa29bd900fb14956b452783534516ed 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php
@@ -276,6 +276,6 @@ class Mage_Adminhtml_Newsletter_QueueController extends Mage_Adminhtml_Controlle
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Newsletter::queue');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Newsletter::queue');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Newsletter/SubscriberController.php b/app/code/core/Mage/Adminhtml/controllers/Newsletter/SubscriberController.php
index a2e83c8d87249788658bc852db929aca8f8f76b1..a3af3fa5ad63c49095bfa493a4d4a895f71bbc26 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Newsletter/SubscriberController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Newsletter/SubscriberController.php
@@ -137,6 +137,6 @@ class Mage_Adminhtml_Newsletter_SubscriberController extends Mage_Adminhtml_Cont
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Newsletter::subscriber');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Newsletter::subscriber');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php b/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php
index 95846ac039d09a37a7edc27fcd1b29e3a0983489..458c8ffc0de62ee905f27b76586d5c207c421bb2 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php
@@ -39,7 +39,7 @@ class Mage_Adminhtml_Newsletter_TemplateController extends Mage_Adminhtml_Contro
      */
     protected function _isAllowed ()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')
+        return Mage::getSingleton('Mage_Core_Model_Authorization')
             ->isAllowed('Mage_Newsletter::template');
     }
 
diff --git a/app/code/core/Mage/Adminhtml/controllers/NotificationController.php b/app/code/core/Mage/Adminhtml/controllers/NotificationController.php
index 3844fc2f77a301a352a46184e56ba1f704b6db35..bf5038f31d027efa1cc748024c1a72dfc65ac128 100644
--- a/app/code/core/Mage/Adminhtml/controllers/NotificationController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/NotificationController.php
@@ -180,6 +180,6 @@ class Mage_Adminhtml_NotificationController extends Mage_Adminhtml_Controller_Ac
             default:
                 $acl = 'Mage_AdminNotification::show_list';
         }
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($acl);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($acl);
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Poll/AnswerController.php b/app/code/core/Mage/Adminhtml/controllers/Poll/AnswerController.php
index d4cb2ffce33b4dbb37b682613b7ccc5d629c491b..6a35ff34411d72e83338a19dd19914cd67fabad3 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Poll/AnswerController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Poll/AnswerController.php
@@ -125,7 +125,7 @@ class Mage_Adminhtml_Poll_AnswerController extends Mage_Adminhtml_Controller_Act
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Poll::poll');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Poll::poll');
     }
 
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/PollController.php b/app/code/core/Mage/Adminhtml/controllers/PollController.php
index 16dad36c8921d6d681b71565384038614a6cfdd0..3398cc22a3ea65f0ca1eafee98acaf31f2afb0d1 100644
--- a/app/code/core/Mage/Adminhtml/controllers/PollController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/PollController.php
@@ -210,7 +210,7 @@ class Mage_Adminhtml_PollController extends Mage_Adminhtml_Controller_Action
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Poll::poll');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Poll::poll');
     }
 
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Promo/CatalogController.php b/app/code/core/Mage/Adminhtml/controllers/Promo/CatalogController.php
index 8cfc1470b2b61d487b1872a13f7de8d7c45c7ef1..980e1e572d07b1f65a223105189b30b1122ded4d 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Promo/CatalogController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Promo/CatalogController.php
@@ -303,7 +303,7 @@ class Mage_Adminhtml_Promo_CatalogController extends Mage_Adminhtml_Controller_A
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_CatalogRule::promo_catalog');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_CatalogRule::promo_catalog');
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/controllers/Promo/QuoteController.php b/app/code/core/Mage/Adminhtml/controllers/Promo/QuoteController.php
index bf570006f242433b8e82b19b9516806221de83f1..77ff536563fe7a2bb12199eecb1bb6a999551629 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Promo/QuoteController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Promo/QuoteController.php
@@ -411,6 +411,6 @@ class Mage_Adminhtml_Promo_QuoteController extends Mage_Adminhtml_Controller_Act
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_SalesRule::quote');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_SalesRule::quote');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Promo/WidgetController.php b/app/code/core/Mage/Adminhtml/controllers/Promo/WidgetController.php
index cb155fdd527080e9c20c0df4430643aea62fd5c5..774400340ef56abc9192ff453dc6b7f76686cc60 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Promo/WidgetController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Promo/WidgetController.php
@@ -80,7 +80,7 @@ class Mage_Adminhtml_Promo_WidgetController extends Mage_Adminhtml_Controller_Ac
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_CatalogRule::promo_catalog');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_CatalogRule::promo_catalog');
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/controllers/PromoController.php b/app/code/core/Mage/Adminhtml/controllers/PromoController.php
index 7613687c4968fd4259aa7fe2e53ee7cd7b546c3e..2d578c069f89d19119d1c57f0c2b022970369a2c 100644
--- a/app/code/core/Mage/Adminhtml/controllers/PromoController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/PromoController.php
@@ -44,7 +44,7 @@ class Mage_Adminhtml_PromoController extends Mage_Adminhtml_Controller_Action
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_CatalogRule::promo');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_CatalogRule::promo');
     }
 
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/RatingController.php b/app/code/core/Mage/Adminhtml/controllers/RatingController.php
index 4aa5037a91bffcc28518ace15cace25a593a1878..dabb71e938691dc0a36ded53f30887c7c4257252 100644
--- a/app/code/core/Mage/Adminhtml/controllers/RatingController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/RatingController.php
@@ -156,7 +156,7 @@ class Mage_Adminhtml_RatingController extends Mage_Adminhtml_Controller_Action
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Rating::ratings');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Rating::ratings');
     }
 
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php
index b1f1f565aeb7373e1ee066237b7c176ab5c78123..8d5cdd8b9ec17f9d9e1316eae8f579280302549d 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php
@@ -163,16 +163,16 @@ class Mage_Adminhtml_Report_CustomerController extends Mage_Adminhtml_Controller
     {
         switch ($this->getRequest()->getActionName()) {
             case 'accounts':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::accounts');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::accounts');
                 break;
             case 'orders':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::customers_orders');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::customers_orders');
                 break;
             case 'totals':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::totals');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::totals');
                 break;
             default:
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::customers');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::customers');
                 break;
         }
     }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php
index 3e2d0e040bb07def010eba73789674a858f66148..a92ba48c76eb9e7e9b51c3cff7453b0b7f64d444 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php
@@ -239,16 +239,16 @@ class Mage_Adminhtml_Report_ProductController extends Mage_Adminhtml_Controller_
     {
         switch ($this->getRequest()->getActionName()) {
             case 'viewed':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::viewed');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::viewed');
                 break;
             case 'sold':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::sold');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::sold');
                 break;
             case 'lowstock':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::lowstock');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::lowstock');
                 break;
             default:
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::report_products');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::report_products');
                 break;
         }
     }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php b/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php
index c90d3dfc5e3caeb5dabc3aa8c0d4f9981d67468d..3dab543a841a3c022a42aad076b1c57c103fa60e 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php
@@ -162,13 +162,13 @@ class Mage_Adminhtml_Report_ReviewController extends Mage_Adminhtml_Controller_A
     {
         switch ($this->getRequest()->getActionName()) {
             case 'customer':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::review_customer');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::review_customer');
                 break;
             case 'product':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::review_product');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::review_product');
                 break;
             default:
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::review');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::review');
                 break;
         }
     }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php b/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php
index a835da95d6643efd86183d9d80422e7a1ab6d0e8..94d6ddcc6a532fd1793dfd1c89055c43d8c47b62 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php
@@ -375,31 +375,31 @@ class Mage_Adminhtml_Report_SalesController extends Mage_Adminhtml_Controller_Re
     {
         switch ($this->getRequest()->getActionName()) {
             case 'sales':
-                return $this->_getSession()->isAllowed('Mage_Reports::salesroot_sales');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::salesroot_sales');
                 break;
             case 'tax':
-                return $this->_getSession()->isAllowed('Mage_Reports::tax');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::tax');
                 break;
             case 'shipping':
-                return $this->_getSession()->isAllowed('Mage_Reports::shipping');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::shipping');
                 break;
             case 'invoiced':
-                return $this->_getSession()->isAllowed('Mage_Reports::invoiced');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::invoiced');
                 break;
             case 'refunded':
-                return $this->_getSession()->isAllowed('Mage_Reports::refunded');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::refunded');
                 break;
             case 'coupons':
-                return $this->_getSession()->isAllowed('Mage_Reports::coupons');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::coupons');
                 break;
             case 'shipping':
-                return $this->_getSession()->isAllowed('Mage_Reports::shipping');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::shipping');
                 break;
             case 'bestsellers':
-                return $this->_getSession()->isAllowed('Mage_Reports::bestsellers');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::bestsellers');
                 break;
             default:
-                return $this->_getSession()->isAllowed('Mage_Reports::salesroot');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::salesroot');
                 break;
         }
     }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php b/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php
index d1b78cc71a9b360bbb98a84ff6f4459c22c6701f..57edb04398920e7d207fc0e54b25619c189c49d5 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php
@@ -157,17 +157,17 @@ class Mage_Adminhtml_Report_ShopcartController extends Mage_Adminhtml_Controller
     {
         switch ($this->getRequest()->getActionName()) {
             case 'customer':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')
+                return Mage::getSingleton('Mage_Core_Model_Authorization')
                     ->isAllowed(Mage_Backend_Model_Acl_Config::ACL_RESOURCE_ALL);
                 break;
             case 'product':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::product');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::product');
                 break;
             case 'abandoned':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::abandoned');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::abandoned');
                 break;
             default:
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::shopcart');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::shopcart');
                 break;
         }
     }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/StatisticsController.php b/app/code/core/Mage/Adminhtml/controllers/Report/StatisticsController.php
index cdfbbffd8b36941a7b106b629dbd72069b59be14..9bc606d92d1519aa1cc8e4a2118d5327567bb00d 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Report/StatisticsController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Report/StatisticsController.php
@@ -186,7 +186,7 @@ class Mage_Adminhtml_Report_StatisticsController extends Mage_Adminhtml_Controll
 
     protected function _isAllowed()
     {
-        return $this->_getSession()->isAllowed('Mage_Reports::statistics');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::statistics');
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php b/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php
index caf96bf18cac65cce2ba0596422fd7785199b1a0..8df9311548a6700b734f5c7d50ba8950549b1b44 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php
@@ -284,19 +284,19 @@ class Mage_Adminhtml_Report_TagController extends Mage_Adminhtml_Controller_Acti
     {
         switch ($this->getRequest()->getActionName()) {
             case 'customer':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::tags_customer');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::tags_customer');
                 break;
             case 'product':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::tags_product');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::tags_product');
                 break;
             case 'productAll':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::tags_product');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::tags_product');
                 break;
             case 'popular':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::popular');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::popular');
                 break;
             default:
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::tags');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::tags');
                 break;
         }
     }
diff --git a/app/code/core/Mage/Adminhtml/controllers/ReportController.php b/app/code/core/Mage/Adminhtml/controllers/ReportController.php
index e612be0114c67904780640988d24558eef6d2dbc..e0cbb70811ea5124b8aed83b7222bc13a7578b39 100644
--- a/app/code/core/Mage/Adminhtml/controllers/ReportController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/ReportController.php
@@ -82,10 +82,10 @@ class Mage_Adminhtml_ReportController extends Mage_Adminhtml_Controller_Action
     {
         switch ($this->getRequest()->getActionName()) {
             case 'search':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::report_search');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::report_search');
                 break;
             default:
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Reports::report');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Reports::report');
                 break;
         }
     }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php
index 12c36ce390504b19a5cf65d196baab48f587b06e..a9b3032bc841798101f5da5b876923a2f8fcff8c 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php
@@ -207,14 +207,14 @@ class Mage_Adminhtml_Sales_Billing_AgreementController extends Mage_Adminhtml_Co
             case 'index':
             case 'grid' :
             case 'view' :
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::billing_agreement_actions_view');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::billing_agreement_actions_view');
                 break;
             case 'cancel':
             case 'delete':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::actions_manage');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::actions_manage');
                 break;
             default:
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::billing_agreement');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::billing_agreement');
                 break;
         }
     }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php
index a9bee9da7dff7e3466fea79a27fbe88d7daf124f..36976df2b2174e7cb1e6af3a9cd074e7687cd077 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php
@@ -495,7 +495,7 @@ class Mage_Adminhtml_Sales_Order_CreateController extends Mage_Adminhtml_Control
 
             $this->_getSession()->clear();
             Mage::getSingleton('Mage_Adminhtml_Model_Session')->addSuccess($this->__('The order has been created.'));
-            if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::actions_view')) {
+            if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::actions_view')) {
                 $this->_redirect('*/sales_order/view', array('order_id' => $order->getId()));
             } else {
                 $this->_redirect('*/sales_order/index');
@@ -543,7 +543,7 @@ class Mage_Adminhtml_Sales_Order_CreateController extends Mage_Adminhtml_Control
                 $aclResource = 'Mage_Sales::actions';
                 break;
         }
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($aclResource);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($aclResource);
     }
 
     /*
diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/EditController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/EditController.php
index 22905c676ab980dc5861305af8eed614b86a1156..5be4a86ab8f6ce2d96b0c289457f0fb16b1829c4 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/EditController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/EditController.php
@@ -81,6 +81,6 @@ class Mage_Adminhtml_Sales_Order_EditController extends Mage_Adminhtml_Sales_Ord
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::actions_edit');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::actions_edit');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/StatusController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/StatusController.php
index f6f78c2c0e23cfc5c3ab2a75084b4d65a24cc5cd..382f3d8f28396246780325b0c45e7a13c21712b9 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/StatusController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/StatusController.php
@@ -234,6 +234,6 @@ class Mage_Adminhtml_Sales_Order_StatusController extends Mage_Adminhtml_Control
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::order_statuses');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::order_statuses');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php
index 3cdc084513f6cfa5715c89a296ac4493405e7cb2..80e6052b11fcdeec5b265b84284da8ec50000c88 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php
@@ -681,7 +681,7 @@ class Mage_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Controller_Act
                 break;
 
         }
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($aclResource);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($aclResource);
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php
index 81ff5ca813865b7e79d52068ce4cd7bab2e04c0a..aab4f06cea60f3719079acb5cae569801b39c0b1 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php
@@ -132,10 +132,10 @@ class Mage_Adminhtml_Sales_TransactionsController extends Mage_Adminhtml_Control
     {
         switch ($this->getRequest()->getActionName()) {
             case 'fetch':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::transactions_fetch');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::transactions_fetch');
                 break;
             default:
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::transactions');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::transactions');
                 break;
         }
     }
diff --git a/app/code/core/Mage/Adminhtml/controllers/SitemapController.php b/app/code/core/Mage/Adminhtml/controllers/SitemapController.php
index d6a35c0119c71512bb7b7950110e852f528addfc..cd29b9d9ffa60175fe7fd0f025675323262a645e 100644
--- a/app/code/core/Mage/Adminhtml/controllers/SitemapController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/SitemapController.php
@@ -280,6 +280,6 @@ class Mage_Adminhtml_SitemapController extends  Mage_Adminhtml_Controller_Action
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sitemap::sitemap');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sitemap::sitemap');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/SurveyController.php b/app/code/core/Mage/Adminhtml/controllers/SurveyController.php
index 68c7dede4a226ad00453cfe5fdf38853320126d2..5ceac0c1c6499b0b2d4bacae508927721ea884ad 100644
--- a/app/code/core/Mage/Adminhtml/controllers/SurveyController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/SurveyController.php
@@ -53,7 +53,7 @@ class Mage_Adminhtml_SurveyController extends Mage_Adminhtml_Controller_Action
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')
+        return Mage::getSingleton('Mage_Core_Model_Authorization')
             ->isAllowed(Mage_Backend_Model_Acl_Config::ACL_RESOURCE_ALL);
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/System/AccountController.php b/app/code/core/Mage/Adminhtml/controllers/System/AccountController.php
index 77f68c6bb1cd54bde3f7cae82a0d5d9508d77958..e6e6ecffdd407daeba7b5a98084d523f3a237f2d 100644
--- a/app/code/core/Mage/Adminhtml/controllers/System/AccountController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/System/AccountController.php
@@ -91,6 +91,6 @@ class Mage_Adminhtml_System_AccountController extends Mage_Adminhtml_Controller_
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::myaccount');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::myaccount');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/System/BackupController.php b/app/code/core/Mage/Adminhtml/controllers/System/BackupController.php
index c8b5c5e1ed6317608afd450ac42d1d854e998d26..7210596ba24b692eed2e4c3e5119f8c7b114e5ae 100644
--- a/app/code/core/Mage/Adminhtml/controllers/System/BackupController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/System/BackupController.php
@@ -358,7 +358,7 @@ class Mage_Adminhtml_System_BackupController extends Mage_Adminhtml_Controller_A
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Backup::backup');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Backup::backup');
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php b/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php
index 9d1a77a1cf5806b92a6db8ce47ddd6e71f0dfdb8..712fccd4329a97feac974fbfc48709e2d0ab42f7 100644
--- a/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php
@@ -257,7 +257,7 @@ class Mage_Adminhtml_System_ConfigController extends Mage_Adminhtml_Controller_A
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::config');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::config');
     }
 
     /**
@@ -271,15 +271,12 @@ class Mage_Adminhtml_System_ConfigController extends Mage_Adminhtml_Controller_A
     protected function _isSectionAllowed($section)
     {
         try {
-            $session = Mage::getSingleton('Mage_Backend_Model_Auth_Session');
-            if ($session->getData('acl') instanceof Magento_Acl) {
-                $resourceId = (string) Mage::getSingleton('Mage_Adminhtml_Model_Config')
-                    ->getSection($section)->resource;
-                if (!$session->isAllowed($resourceId)) {
-                    throw new Exception('');
-                }
-                return true;
+            $resourceId = (string) Mage::getSingleton('Mage_Adminhtml_Model_Config')
+                ->getSection($section)->resource;
+            if (!Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($resourceId)) {
+                throw new Exception('');
             }
+            return true;
         }
         catch (Zend_Acl_Exception $e) {
             $this->norouteAction();
diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Convert/GuiController.php b/app/code/core/Mage/Adminhtml/controllers/System/Convert/GuiController.php
index b57d89d4a9f4bc8c74ce0bdfe38f5fc6805f2e3a..109045f51d17539281d3d49b2957876a4ddd47dc 100644
--- a/app/code/core/Mage/Adminhtml/controllers/System/Convert/GuiController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/System/Convert/GuiController.php
@@ -151,6 +151,6 @@ class Mage_Adminhtml_System_Convert_GuiController extends Mage_Adminhtml_System_
 //                break;
 //        }
 
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::gui');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::gui');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php b/app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php
index 3ce5b3856486e1774b22c7d86d43f1292923bc5a..7c6bc54e084be9daf4942044ab3b9d91b5d660b4 100644
--- a/app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php
@@ -312,6 +312,6 @@ class Mage_Adminhtml_System_Convert_ProfileController extends Mage_Adminhtml_Con
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::profiles');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::profiles');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php b/app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php
index 94e2c006bad5aa353f0210d809658c8ede91ab03..fcdf189ba183e754a1ef509047c8e84cc519e253 100644
--- a/app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php
@@ -122,6 +122,6 @@ class Mage_Adminhtml_System_CurrencyController extends Mage_Adminhtml_Controller
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_CurrencySymbol::currency_rates');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_CurrencySymbol::currency_rates');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php b/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php
index e12d6567a86d1e1a440cf9f2084e3f0ff9f5d890..2990de1a27ce0f383c7400c01721525dd953d723 100644
--- a/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php
@@ -127,6 +127,6 @@ class Mage_Adminhtml_System_DesignController extends Mage_Adminhtml_Controller_A
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::design');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::design');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Email/TemplateController.php b/app/code/core/Mage/Adminhtml/controllers/System/Email/TemplateController.php
index 8df9744ff17173e95ffec52ae53cb5da8cc0f366..af0fe871976129f9ff37c0c0242f6f856fb17930 100644
--- a/app/code/core/Mage/Adminhtml/controllers/System/Email/TemplateController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/System/Email/TemplateController.php
@@ -225,6 +225,6 @@ class Mage_Adminhtml_System_Email_TemplateController extends Mage_Adminhtml_Cont
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::email_template');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::email_template');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php b/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php
index 7119fd97f0a8c48060b7351a1387ae429253748d..8806681103069279008ee53a31448644257abe8b 100644
--- a/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php
@@ -448,7 +448,7 @@ class Mage_Adminhtml_System_StoreController extends Mage_Adminhtml_Controller_Ac
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::store');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::store');
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/controllers/System/VariableController.php b/app/code/core/Mage/Adminhtml/controllers/System/VariableController.php
index 535e5b26fed3f03095df2c1d7ba3145b071a2e12..0443ba117cbc73e624f6fc6774dc1aba6d848845 100644
--- a/app/code/core/Mage/Adminhtml/controllers/System/VariableController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/System/VariableController.php
@@ -201,6 +201,6 @@ class Mage_Adminhtml_System_VariableController extends Mage_Adminhtml_Controller
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::variable');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::variable');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/SystemController.php b/app/code/core/Mage/Adminhtml/controllers/SystemController.php
index e6ed5fb6e689ead70063fc3d6c601899d2d2b514..752829e56dcbe5ee33252c8cfbd24677435b856d 100644
--- a/app/code/core/Mage/Adminhtml/controllers/SystemController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/SystemController.php
@@ -52,6 +52,6 @@ class Mage_Adminhtml_SystemController extends Mage_Adminhtml_Controller_Action
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::system');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::system');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/TagController.php b/app/code/core/Mage/Adminhtml/controllers/TagController.php
index 64f3dd83f72c0eca0e9221eb2687df56c95c526f..74a570d9ada4e9a49aa55d38fcfb019ec588ed64 100644
--- a/app/code/core/Mage/Adminhtml/controllers/TagController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/TagController.php
@@ -348,13 +348,13 @@ class Mage_Adminhtml_TagController extends Mage_Adminhtml_Controller_Action
     {
         switch ($this->getRequest()->getActionName()) {
             case 'pending':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Tag::tag_pending');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Tag::tag_pending');
                 break;
             case 'all':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Tag::tag_all');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Tag::tag_all');
                 break;
             default:
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Tag::tag');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Tag::tag');
                 break;
         }
     }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/Class/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/Class/CustomerController.php
index f41451998a97ca65a6f23c0a62ea11bbadf5ded2..1791d1fa58aa14039641d67c4d4bc8bbdcc0455c 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Tax/Class/CustomerController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Tax/Class/CustomerController.php
@@ -182,6 +182,6 @@ class Mage_Adminhtml_Tax_Class_CustomerController extends Mage_Adminhtml_Control
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Tax::classes_customer');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Tax::classes_customer');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/Class/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/Class/ProductController.php
index 3a57a111224c3010873045159aaccd0120ce38e2..d3f5c88896891cd3d35db5410b27b4dd417dd6e9 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Tax/Class/ProductController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Tax/Class/ProductController.php
@@ -181,7 +181,7 @@ class Mage_Adminhtml_Tax_Class_ProductController extends Mage_Adminhtml_Controll
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Tax::classes_product');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Tax::classes_product');
     }
 
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/ClassController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/ClassController.php
index 70b0f7d1ab698d3d76d9b3e313f404aa9a5a48ad..5b49eef10901598b95f8a3cbaeee4ce02b975f27 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Tax/ClassController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Tax/ClassController.php
@@ -97,7 +97,7 @@ class Mage_Adminhtml_Tax_ClassController extends Mage_Adminhtml_Controller_Actio
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Tax::classes_product')
-            || Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Tax::classes_customer');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Tax::classes_product')
+            || Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Tax::classes_customer');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php
index 6cb6bf199f64df849ec4fd473df5865770b8513f..3e5bac753fe720ef61640b3f8a6fcc4a9cb36a36 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php
@@ -464,13 +464,13 @@ class Mage_Adminhtml_Tax_RateController extends Mage_Adminhtml_Controller_Action
 
         switch ($this->getRequest()->getActionName()) {
             case 'importExport':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Tax::import_export');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Tax::import_export');
                 break;
             case 'index':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Tax::tax_rates');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Tax::tax_rates');
                 break;
             default:
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Tax::tax_rates');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Tax::tax_rates');
                 break;
         }
     }
diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/RuleController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/RuleController.php
index 9de1f50b70044e8be73b5420391e99326f92104b..16a9c172b33e8357088029df8942419f9882deca 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Tax/RuleController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Tax/RuleController.php
@@ -165,6 +165,6 @@ class Mage_Adminhtml_Tax_RuleController extends Mage_Adminhtml_Controller_Action
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Tax::rules');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Tax::rules');
     }
 }
diff --git a/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php b/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php
index ab56301c0d33744348d8d5d74288c6103b0ce13e..476a750944fe9cffe9b257c97bb91ac1868c0830 100644
--- a/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php
@@ -421,7 +421,7 @@ class Mage_Adminhtml_UrlrewriteController extends Mage_Adminhtml_Controller_Acti
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Catalog::urlrewrite');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Catalog::urlrewrite');
     }
 
     /**
diff --git a/app/code/core/Mage/Adminhtml/view/adminhtml/page/header.phtml b/app/code/core/Mage/Adminhtml/view/adminhtml/page/header.phtml
index 7f812974fb36f979d76639194ccd744391d0b26b..274173a15c554c8be9165b33b025a33432f41c6b 100644
--- a/app/code/core/Mage/Adminhtml/view/adminhtml/page/header.phtml
+++ b/app/code/core/Mage/Adminhtml/view/adminhtml/page/header.phtml
@@ -32,7 +32,7 @@
         <p class="super">
             <?php echo $this->__("Logged in as %s", $this->escapeHtml($this->getUser()->getUsername())) ?><span class="separator">|</span><?php echo $this->formatDate(null, 'full') ?><span class="separator">|</span><a href="http://golinks.magento.com/CE15" onclick="this.target='_blank'" class="go-try"><?php echo $this->__('Try Magento Go for Free') ?></a><span class="separator">|</span><a href="<?php echo $this->getLogoutLink() ?>" class="link-logout"><?php echo $this->__('Log Out') ?></a>
         </p>
-        <?php if ( Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::global_search') ): ?>
+        <?php if ( Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::global_search') ): ?>
         <fieldset>
             <legend>Search</legend>
             <span id="global_search_indicator" class="autocomplete-indicator" style="display: none">
diff --git a/app/code/core/Mage/Adminhtml/view/adminhtml/system/config/switcher.phtml b/app/code/core/Mage/Adminhtml/view/adminhtml/system/config/switcher.phtml
index f32eff4ec369ebf10b8d23e673dc7f30698594a9..8558f206c266177c96afe6bfd0a16fd0a8387ee0 100644
--- a/app/code/core/Mage/Adminhtml/view/adminhtml/system/config/switcher.phtml
+++ b/app/code/core/Mage/Adminhtml/view/adminhtml/system/config/switcher.phtml
@@ -43,7 +43,7 @@
       </option>
     <?php endforeach ?>
     </select>
-    <?php if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::store')): ?>
+    <?php if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::store')): ?>
     <p style="margin:10px 0 0;">
         <a href="<?php echo $this->getUrl('*/system_store') ?>"><?php echo $this->__('Manage Stores') ?></a>
     </p>
diff --git a/app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Grid.php b/app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Grid.php
index 5627bca788c111e0d697c37cfce040a9089f20eb..be7cb0f46b99ca551e386b599bebe5dc6ec0d189 100644
--- a/app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Grid.php
+++ b/app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Grid.php
@@ -96,9 +96,7 @@ class Mage_Api2_Block_Adminhtml_Attribute_Grid extends Mage_Adminhtml_Block_Widg
      */
     public function getRowUrl($row)
     {
-        /** @var $session Mage_Backend_Model_Auth_Session */
-        $session = Mage::getSingleton('Mage_Backend_Model_Auth_Session');
-        if ($session->isAllowed('Mage_Api2::rest_attributes_edit')) {
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Api2::rest_attributes_edit')) {
             return $this->getUrl('*/*/edit', array('type' => $row->getUserTypeCode()));
         }
 
diff --git a/app/code/core/Mage/Api2/Block/Adminhtml/Roles.php b/app/code/core/Mage/Api2/Block/Adminhtml/Roles.php
index 4a0a5585cffbd9f23cf1623278d3cf2a7757c5b2..47e3c383856b659d58efd518766d7b37b16874b0 100644
--- a/app/code/core/Mage/Api2/Block/Adminhtml/Roles.php
+++ b/app/code/core/Mage/Api2/Block/Adminhtml/Roles.php
@@ -45,9 +45,7 @@ class Mage_Api2_Block_Adminhtml_Roles extends Mage_Adminhtml_Block_Widget_Grid_C
         $this->_headerText = Mage::helper('Mage_Adminhtml_Helper_Data')->__('REST Roles');
 
         //check allow edit
-        /** @var $session Mage_Backend_Model_Auth_Session */
-        $session = Mage::getSingleton('Mage_Backend_Model_Auth_Session');
-        if ($session->isAllowed('Mage_Api2::rest_roles_add')) {
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Api2::rest_roles_add')) {
             $this->_updateButton('add', 'label', $this->__('Add Admin Role'));
         } else {
             $this->_removeButton('add');
diff --git a/app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php b/app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php
index c5988e303b5a62dc097146b40d155567b6098ea5..ea94b91ebf2f181252492550e1c314d02a1600ec 100644
--- a/app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php
+++ b/app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php
@@ -113,10 +113,7 @@ class Mage_Api2_Block_Adminhtml_Roles_Grid extends Mage_Adminhtml_Block_Widget_G
      */
     public function getRowUrl($row)
     {
-        /** @var $session Mage_Backend_Model_Auth_Session */
-        $session = Mage::getSingleton('Mage_Backend_Model_Auth_Session');
-
-        if ($session->isAllowed('Mage_Api2::rest_roles_edit')) {
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Api2::rest_roles_edit')) {
             return $this->getUrl('*/*/edit', array('id' => $row->getId()));
         }
         return null;
diff --git a/app/code/core/Mage/Api2/controllers/Adminhtml/Api2/RoleController.php b/app/code/core/Mage/Api2/controllers/Adminhtml/Api2/RoleController.php
index f6462a34958d1b9f246a495fda2db862c144b8e2..89f71a62a7372e437a4f854919434e4f85f54350 100644
--- a/app/code/core/Mage/Api2/controllers/Adminhtml/Api2/RoleController.php
+++ b/app/code/core/Mage/Api2/controllers/Adminhtml/Api2/RoleController.php
@@ -265,9 +265,7 @@ class Mage_Api2_Adminhtml_Api2_RoleController extends Mage_Adminhtml_Controller_
      */
     protected function _isAllowed()
     {
-        /** @var $session Mage_Backend_Model_Auth_Session */
-        $session = Mage::getSingleton('Mage_Backend_Model_Auth_Session');
-        return $session->isAllowed('Mage_Api2::rest_roles');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Api2::rest_roles');
     }
 
     /**
diff --git a/app/code/core/Mage/Backend/Controller/ActionAbstract.php b/app/code/core/Mage/Backend/Controller/ActionAbstract.php
index cc615dffe169bda8b19f2d011b9f3e1f0ef207b1..a803177dfb6e0966f652b6b69d7192afc8c980c3 100644
--- a/app/code/core/Mage/Backend/Controller/ActionAbstract.php
+++ b/app/code/core/Mage/Backend/Controller/ActionAbstract.php
@@ -53,6 +53,42 @@ abstract class Mage_Backend_Controller_ActionAbstract extends Mage_Core_Controll
      */
     protected $_sessionNamespace = self::SESSION_NAMESPACE;
 
+    /**
+     * Helper
+     *
+     * @var Mage_Backend_Helper_Data
+     */
+    protected $_helper;
+
+    /**
+     * Session model
+     *
+     * @var Mage_Backend_Model_Session
+     */
+    protected $_session;
+
+    /**
+     * Constructor
+     *
+     * @param Zend_Controller_Request_Abstract $request
+     * @param Zend_Controller_Response_Abstract $response
+     * @param array $invokeArgs
+     */
+    public function __construct(Zend_Controller_Request_Abstract $request,
+                                Zend_Controller_Response_Abstract $response,
+                                array $invokeArgs = array()
+    ) {
+        parent::__construct($request, $response, $invokeArgs);
+
+        $this->_helper = isset($invokeArgs['helper']) ?
+            $invokeArgs['helper'] :
+            Mage::helper('Mage_Backend_Helper_Data');
+
+        $this->_session = isset($invokeArgs['session']) ?
+            $invokeArgs['session'] :
+            Mage::getSingleton('Mage_Backend_Model_Session');
+    }
+
     protected function _isAllowed()
     {
         return true;
@@ -65,17 +101,17 @@ abstract class Mage_Backend_Controller_ActionAbstract extends Mage_Core_Controll
      */
     protected function _getSession()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Session');
+        return $this->_session;
     }
 
     /**
-     * Retrieve base admihtml helper
+     * Retrieve base adminhtml helper
      *
      * @return Mage_Backend_Helper_Data
      */
     protected function _getHelper()
     {
-        return Mage::helper('Mage_Backend_Helper_Data');
+        return $this->_helper;
     }
 
     /**
@@ -332,9 +368,22 @@ abstract class Mage_Backend_Controller_ActionAbstract extends Mage_Core_Controll
         $this->renderLayout();
     }
 
-    public function loadLayout($ids=null, $generateBlocks=true, $generateXml=true)
+    /**
+     * Load layout by handles and verify user ACL
+     *
+     * @param string|null|bool|array $ids
+     * @param bool $generateBlocks
+     * @param bool $generateXml
+     * @return Mage_Backend_Controller_ActionAbstract|Mage_Core_Controller_Varien_Action
+     */
+    public function loadLayout($ids = null, $generateBlocks = true, $generateXml = true)
     {
-        parent::loadLayout($ids, $generateBlocks, $generateXml);
+        parent::loadLayout($ids, false, $generateXml);
+        Mage::getSingleton('Mage_Core_Model_Authorization')->filterAclNodes($this->getLayout()->getNode());
+        if ($generateBlocks) {
+            $this->generateLayoutBlocks();
+            $this->_isLayoutLoaded = true;
+        }
         $this->_initLayoutMessages('Mage_Backend_Model_Session');
         return $this;
     }
@@ -391,7 +440,7 @@ abstract class Mage_Backend_Controller_ActionAbstract extends Mage_Core_Controll
      */
     public function getUrl($route='', $params=array())
     {
-        return Mage_Backend_Helper_Data::getUrl($route, $params);
+        return $this->_getHelper()->getUrl($route, $params);
     }
 
     /**
diff --git a/app/code/core/Mage/Backend/Helper/Data.php b/app/code/core/Mage/Backend/Helper/Data.php
index a66d163d4440eed32c284b8df3c3434ea04038cc..34a7798ffeb07a3f06d42f75063868a846513722 100644
--- a/app/code/core/Mage/Backend/Helper/Data.php
+++ b/app/code/core/Mage/Backend/Helper/Data.php
@@ -96,9 +96,9 @@ class Mage_Backend_Helper_Data extends Mage_Core_Helper_Abstract
         return $this;
     }
 
-    public static function getUrl($route='', $params=array())
+    public function getUrl($route='', $params=array())
     {
-        return Mage::getModel('Mage_Backend_Model_Url')->getUrl($route, $params);
+        return Mage::getSingleton('Mage_Backend_Model_Url')->getUrl($route, $params);
     }
 
     public function getCurrentUserId()
diff --git a/app/code/core/Mage/Backend/Model/Acl/Config.php b/app/code/core/Mage/Backend/Model/Acl/Config.php
index a3cc97854fd6fab5b4c9a67c0a9bb753e1a2fb6a..0ccf9fb08a011b7863db27e55499371c5749cf32 100644
--- a/app/code/core/Mage/Backend/Model/Acl/Config.php
+++ b/app/code/core/Mage/Backend/Model/Acl/Config.php
@@ -49,7 +49,7 @@ class Mage_Backend_Model_Acl_Config
     protected $_cache;
 
     /**
-     * @var Mage_Backend_Model_Acl_Config_Reader
+     * @var Magento_Acl_Config_Reader
      */
     protected $_reader;
 
@@ -74,13 +74,13 @@ class Mage_Backend_Model_Acl_Config
     /**
      * Reader object initialization
      *
-     * @return Mage_Backend_Model_Acl_Config_Reader
+     * @return Magento_Acl_Config_Reader
      */
     protected function _getReader()
     {
         if (null === $this->_reader) {
             $aclResourceFiles = $this->_getAclResourceFiles();
-            $this->_reader = $this->_config->getModelInstance('Mage_Backend_Model_Acl_Config_Reader', $aclResourceFiles);
+            $this->_reader = $this->_config->getModelInstance('Magento_Acl_Config_Reader', $aclResourceFiles);
         }
         return $this->_reader;
     }
diff --git a/app/code/core/Mage/Backend/Model/Auth/Session.php b/app/code/core/Mage/Backend/Model/Auth/Session.php
index df2fd34d39e1e19232fd94e1b15ed975b8e79960..4f15cd63bfd29d773098a955c559c6e37f32d339 100644
--- a/app/code/core/Mage/Backend/Model/Auth/Session.php
+++ b/app/code/core/Mage/Backend/Model/Auth/Session.php
@@ -61,7 +61,7 @@ class Mage_Backend_Model_Auth_Session extends Mage_Core_Model_Session_Abstract i
             $this->_aclBuilder = $data['aclBuilder'];
         } else {
             $areaConfig = Mage::getConfig()->getAreaConfig(Mage::helper('Mage_Backend_Helper_Data')->getAreaCode());
-            $this->_aclBuilder = Mage::getModel('Mage_Core_Model_Acl_Builder', array(
+            $this->_aclBuilder = Mage::getSingleton('Mage_Core_Model_Acl_Builder', array(
                 'areaConfig' => $areaConfig,
                 'objectFactory' => Mage::getConfig()
             ));
@@ -116,8 +116,8 @@ class Mage_Backend_Model_Auth_Session extends Mage_Core_Model_Session_Abstract i
     /**
      * Check current user permission on resource and privilege
      *
-     * Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Catalog::catalog')
-     * Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Catalog::catalog')
+     * Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Catalog::catalog')
+     * Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Catalog::catalog')
      *
      * @param   string $resource
      * @param   string $privilege
diff --git a/app/code/core/Mage/Backend/Model/Authorization/RoleLocator.php b/app/code/core/Mage/Backend/Model/Authorization/RoleLocator.php
new file mode 100644
index 0000000000000000000000000000000000000000..c4e31b7ed15ad7c8c8086c46d75d6704d0b39cf9
--- /dev/null
+++ b/app/code/core/Mage/Backend/Model/Authorization/RoleLocator.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Mage
+ * @package     Mage_Backend
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+class Mage_Backend_Model_Authorization_RoleLocator implements Magento_Authorization_RoleLocator
+{
+    /**
+     * @var Mage_Backend_Model_Auth_Session
+     */
+    protected $_session;
+
+    /**
+     * @param array $data
+     */
+    public function __construct(array $data = array())
+    {
+        $this->_session = isset($data['session']) ?
+            $data['session'] :
+            Mage::getSingleton('Mage_Backend_Model_Auth_Session');
+    }
+
+    /**
+     * Retrieve current role
+     *
+     * @return string|null
+     */
+    public function getAclRoleId()
+    {
+        if ($this->_session->hasUser()) {
+            return $this->_session->getUser()->getAclRole();
+        }
+        return null;
+    }
+}
diff --git a/app/code/core/Mage/Backend/Model/Menu/Item.php b/app/code/core/Mage/Backend/Model/Menu/Item.php
index 7958e28180514a6a190299c63654400b82d07a70..0f97f112f7e501ae716e99554c1e316e6927cbfc 100644
--- a/app/code/core/Mage/Backend/Model/Menu/Item.php
+++ b/app/code/core/Mage/Backend/Model/Menu/Item.php
@@ -95,7 +95,7 @@ class Mage_Backend_Model_Menu_Item
     /**
      * Acl
      *
-     * @var Mage_Backend_Model_Auth_Session
+     * @var Mage_Core_Model_Authorization
      */
     protected $_acl;
 
diff --git a/app/code/core/Mage/Backend/Model/Menu/Item/Factory.php b/app/code/core/Mage/Backend/Model/Menu/Item/Factory.php
index 57b8a152730530791f45f9d76c89fb07641dc0ee..470122aca65415e1638035ec210590ea503d364f 100644
--- a/app/code/core/Mage/Backend/Model/Menu/Item/Factory.php
+++ b/app/code/core/Mage/Backend/Model/Menu/Item/Factory.php
@@ -28,7 +28,7 @@ class Mage_Backend_Model_Menu_Item_Factory
     /**
      * ACL
      *
-     * @var Mage_Backend_Model_Auth_Session
+     * @var Mage_Core_Model_Authorization
      */
     protected $_acl;
 
@@ -79,8 +79,8 @@ class Mage_Backend_Model_Menu_Item_Factory
      */
     public function __construct(array $data = array())
     {
-        $this->_acl = isset($data['acl']) ? $data['acl'] : Mage::getSingleton('Mage_Backend_Model_Auth_Session');
-        if (!($this->_acl instanceof Mage_Backend_Model_Auth_Session)) {
+        $this->_acl = isset($data['acl']) ? $data['acl'] : Mage::getSingleton('Mage_Core_Model_Authorization');
+        if (!($this->_acl instanceof Mage_Core_Model_Authorization)) {
             throw new InvalidArgumentException('Wrong acl object provided');
         }
 
diff --git a/app/code/core/Mage/Backend/Model/Menu/Item/Validator.php b/app/code/core/Mage/Backend/Model/Menu/Item/Validator.php
index 68252a0ab2413313da0224cf8870d6b0307e65b6..2975b5a63a40a427c3bbf00e495fcd21aa88e0e5 100644
--- a/app/code/core/Mage/Backend/Model/Menu/Item/Validator.php
+++ b/app/code/core/Mage/Backend/Model/Menu/Item/Validator.php
@@ -40,7 +40,7 @@ class Mage_Backend_Model_Menu_Item_Validator
      * @var array
      */
     protected $_requiredTypes = array(
-        'acl' => 'Mage_Backend_Model_Auth_Session',
+        'acl' => 'Mage_Core_Model_Authorization',
         'appConfig' => 'Mage_Core_Model_Config',
         'menuFactory' => 'Mage_Backend_Model_Menu_Factory',
         'urlModel' => 'Mage_Backend_Model_Url',
diff --git a/app/code/core/Mage/Backend/etc/config.xml b/app/code/core/Mage/Backend/etc/config.xml
index f7d25e40708101ef9373fb61865b566c8d19b0ed..6cc7011fb4a9fa6137a4104af501fa2d9f8e622f 100644
--- a/app/code/core/Mage/Backend/etc/config.xml
+++ b/app/code/core/Mage/Backend/etc/config.xml
@@ -49,6 +49,8 @@
                 <auth/>
                 <acl>
                     <resourceLoader>Mage_Backend_Model_Acl_Loader_Resource</resourceLoader>
+                    <roleLocator>Mage_Backend_Model_Authorization_RoleLocator</roleLocator>
+                    <policy>Magento_Authorization_Policy_Acl</policy>
                 </acl>
             </adminhtml>
         </areas>
diff --git a/app/code/core/Mage/Backup/Helper/Data.php b/app/code/core/Mage/Backup/Helper/Data.php
index be23f143c0108936aaeba27aefeea0fb85cfdaf2..a3fe090bd4f1f8bd8983f94788d74b2815833d0f 100644
--- a/app/code/core/Mage/Backup/Helper/Data.php
+++ b/app/code/core/Mage/Backup/Helper/Data.php
@@ -150,7 +150,7 @@ class Mage_Backup_Helper_Data extends Mage_Core_Helper_Abstract
      * @return boolean
      */
     public function isRollbackAllowed(){
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Backup::rollback' );
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Backup::rollback' );
     }
 
     /**
diff --git a/app/code/core/Mage/Centinel/Model/State/Jcb.php b/app/code/core/Mage/Centinel/Model/State/Jcb.php
index 45fb5f967786eb40b46bd2f0ac2bc9fee5268154..f3781b78990b12926c4b39efbf9e0add222d4665 100644
--- a/app/code/core/Mage/Centinel/Model/State/Jcb.php
+++ b/app/code/core/Mage/Centinel/Model/State/Jcb.php
@@ -25,7 +25,7 @@
  */
 
 /**
- * Abstract Validation State Model for JCB
+ * Validation State Model for JCB
  */
 class Mage_Centinel_Model_State_Jcb extends Mage_Centinel_Model_StateAbstract
 {
@@ -47,67 +47,18 @@ class Mage_Centinel_Model_State_Jcb extends Mage_Centinel_Model_StateAbstract
      */
     public function isAuthenticateSuccessful()
     {
-        //Test cases 5-9
         if (!$this->getIsModeStrict() && $this->_isLookupSoftSuccessful()) {
             return true;
         }
 
-        $paResStatus = $this->getAuthenticatePaResStatus();
-        $eciFlag = $this->getAuthenticateEciFlag();
-        $xid = $this->getAuthenticateXid();
-        $cavv = $this->getAuthenticateCavv();
-        $errorNo = $this->getAuthenticateErrorNo();
-        $signatureVerification = $this->getAuthenticateSignatureVerification();
-
-        //Test cases 1-4, 10-11
         if ($this->_isLookupStrictSuccessful()) {
-
-            if ($paResStatus == 'Y' && $eciFlag == '05' && $xid != '' && $cavv != '' && $errorNo == '0') {
-                //Test case 1
-                if ($signatureVerification == 'Y') {
-                    return true;
-                }
-                //Test case 2
-                if ($signatureVerification == 'N') {
-                    return false;
-                }
-            }
-
-            //Test case 3
-            if ($paResStatus == 'N' && $signatureVerification == 'Y' && $eciFlag == '07' &&
-                $xid != '' && $cavv == '' && $errorNo == '0') {
-                return false;
-            }
-
-            //Test case 4
-            if ($paResStatus == 'U' && $signatureVerification == 'Y' && $eciFlag == '07' &&
-                $xid != '' && $cavv == '' && $errorNo == '0') {
-                if ($this->getIsModeStrict()) {
-                    return false;
-                } else {
-                    return true;
-                }
-            }
-
-            //Test case 5
-            if ($paResStatus == 'U' && $signatureVerification == 'Y' && $eciFlag == '07' &&
-                $xid != '' && $cavv == '' && $errorNo == '0') {
-                if ($this->getIsModeStrict()) {
-                    return false;
-                } else {
-                    return true;
-                }
+            if ($this->_isAuthenticationSuccessful()) {
+                return true;
             }
-
-            //Test case 10
-            if ($paResStatus == '' && $signatureVerification == '' && $eciFlag == '07' &&
-                $xid == '' && $cavv == '' && $errorNo != '0') {
-                return false;
+            if ($this->_isAuthenticationUnavailable() && !$this->getIsModeStrict()) {
+                return true;
             }
-
-            //Test case 11
-            if ($paResStatus == 'A' && $signatureVerification == 'Y' && $eciFlag == '06' &&
-                $xid != '' && $cavv != '' && $errorNo == '0') {
+            if ($this->_isAuthenticationAttemptsPerformed()) {
                 return true;
             }
         }
@@ -116,24 +67,65 @@ class Mage_Centinel_Model_State_Jcb extends Mage_Centinel_Model_StateAbstract
     }
 
     /**
-     * Analyse lookup`s results. If lookup is strict successful return true
+     * Returns true if authentication successful (Test case 1)
+     *
+     * @return bool
+     */
+    protected function _isAuthenticationSuccessful()
+    {
+        return $this->getAuthenticatePaResStatus() === 'Y'
+            && $this->getAuthenticateEciFlag() === '05'
+            && $this->getAuthenticateXid() != ''
+            && $this->getAuthenticateCavv() != ''
+            && $this->getAuthenticateErrorNo() === '0'
+            && $this->getAuthenticateSignatureVerification() === 'Y';
+    }
+
+    /**
+     * Returns true if authentication unavailable (Test case 4) or timeout encountered (Test case 5)
+     *
+     * @return bool
+     */
+    protected function _isAuthenticationUnavailable()
+    {
+        return $this->getAuthenticatePaResStatus() === 'U'
+            && $this->getAuthenticateSignatureVerification() === 'Y'
+            && $this->getAuthenticateEciFlag() === '07'
+            && $this->getAuthenticateXid() != ''
+            && $this->getAuthenticateCavv() === ''
+            && $this->getAuthenticateErrorNo() === '0';
+    }
+
+    /**
+     * Returns true if processing attempts performed (Test case 11)
+     *
+     * @return bool
+     */
+    protected function _isAuthenticationAttemptsPerformed()
+    {
+        return $this->getAuthenticatePaResStatus() === 'A'
+            && $this->getAuthenticateSignatureVerification() === 'Y'
+            && $this->getAuthenticateEciFlag() === '06'
+            && $this->getAuthenticateXid() != ''
+            && $this->getAuthenticateCavv() != ''
+            && $this->getAuthenticateErrorNo() === '0';
+    }
+
+    /**
+     * Analyse lookup`s results. If lookup is strict successful return true (Test cases 1-4, 6, 10-11)
      *
      * @return bool
      */
     protected function _isLookupStrictSuccessful()
     {
-        //Test cases 1-4, 6, 10-11
-        if ($this->getLookupEnrolled() == 'Y' &&
-            $this->getLookupAcsUrl() != '' &&
-            $this->getLookupPayload() != '' &&
-            $this->getLookupErrorNo() == '0') {
-            return true;
-        }
-        return false;
+        return $this->getLookupEnrolled() === 'Y'
+            && $this->getLookupAcsUrl() != ''
+            && $this->getLookupPayload() != ''
+            && $this->getLookupErrorNo() === '0';
     }
 
     /**
-     * Analyse lookup`s results. If lookup is soft successful return true
+     * Analyse lookup`s results. If lookup is soft successful return true (Test cases 5,7,8,9)
      *
      * @return bool
      */
@@ -144,21 +136,18 @@ class Mage_Centinel_Model_State_Jcb extends Mage_Centinel_Model_StateAbstract
         $errorNo = $this->getLookupErrorNo();
         $enrolled = $this->getLookupEnrolled();
 
-        //Test cases 5
-        if ($enrolled == '' && $acsUrl == '' && $payload == '' && $errorNo == '0') {
-            return true;
+        if ($acsUrl !== '' || $payload !== '') {
+            return false;
         }
 
-        //Test case 7
-        if ($enrolled == 'U' && $acsUrl == '' && $payload == '' && $errorNo == '0') {
+        if ($enrolled === '' && $errorNo === '0') {
             return true;
         }
 
-        //Test cases 8,9
-        if ($enrolled == 'U' && $acsUrl == '' && $payload == '' && $errorNo != '0') {
+        if ($enrolled === 'U' && ($errorNo === '0' || $errorNo !== '')) {
             return true;
         }
 
         return false;
     }
-}
+}
\ No newline at end of file
diff --git a/app/code/core/Mage/Cms/Model/Wysiwyg/Config.php b/app/code/core/Mage/Cms/Model/Wysiwyg/Config.php
index 2732f5f885bb69321060f724a24cbfc66dafd88f..77730d49bb1af614059165292ec4b2d3b01d8496 100644
--- a/app/code/core/Mage/Cms/Model/Wysiwyg/Config.php
+++ b/app/code/core/Mage/Cms/Model/Wysiwyg/Config.php
@@ -82,7 +82,7 @@ class Mage_Cms_Model_Wysiwyg_Config extends Varien_Object
 
         $config->setData('directives_url_quoted', preg_quote($config->getData('directives_url')));
 
-        if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Cms::media_gallery')) {
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Cms::media_gallery')) {
             $config->addData(array(
                 'add_images'               => true,
                 'files_browser_window_url' => Mage::getSingleton('Mage_Adminhtml_Model_Url')->getUrl('*/cms_wysiwyg_images/index'),
diff --git a/app/code/core/Mage/Connect/controllers/Adminhtml/Extension/CustomController.php b/app/code/core/Mage/Connect/controllers/Adminhtml/Extension/CustomController.php
index d397bf895cc85fa7f3a7a76336de2fff08a51ee0..6754e84d3adac6e5f097e5adc6f4d0a7d56f7a7f 100644
--- a/app/code/core/Mage/Connect/controllers/Adminhtml/Extension/CustomController.php
+++ b/app/code/core/Mage/Connect/controllers/Adminhtml/Extension/CustomController.php
@@ -199,6 +199,6 @@ class Mage_Connect_Adminhtml_Extension_CustomController extends Mage_Adminhtml_C
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Adminhtml::custom');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::custom');
     }
 }
diff --git a/app/code/core/Mage/Core/Controller/Varien/Action.php b/app/code/core/Mage/Core/Controller/Varien/Action.php
index c3757f7d477b9714de9bc2a52c760511c401bf67..2d683c489a083e33a4f8af673a91b0c234fcf107 100755
--- a/app/code/core/Mage/Core/Controller/Varien/Action.php
+++ b/app/code/core/Mage/Core/Controller/Varien/Action.php
@@ -128,6 +128,11 @@ abstract class Mage_Core_Controller_Varien_Action implements Mage_Core_Controlle
      */
     protected $_removeDefaultTitle = false;
 
+    /**
+     * @var Mage_Core_Controller_Varien_Front
+     */
+    protected $_frontController = null;
+
     /**
      * Constructor
      *
@@ -141,7 +146,11 @@ abstract class Mage_Core_Controller_Varien_Action implements Mage_Core_Controlle
         $this->_request = $request;
         $this->_response= $response;
 
-        Mage::app()->getFrontController()->setAction($this);
+        $this->_frontController = isset($invokeArgs['frontController']) ?
+            $invokeArgs['frontController'] :
+            Mage::app()->getFrontController();
+
+        $this->_frontController->setAction($this);
         if (!$this->_currentArea) {
             $this->_currentArea = isset($invokeArgs['areaCode']) ? $invokeArgs['areaCode'] : null;
         }
@@ -159,6 +168,7 @@ abstract class Mage_Core_Controller_Varien_Action implements Mage_Core_Controlle
      */
     public function setCurrentArea($areaCode)
     {
+        Mage::getConfig()->setCurrentAreaCode($areaCode);
         $this->_currentArea = $areaCode;
         return $this;
     }
@@ -406,7 +416,7 @@ abstract class Mage_Core_Controller_Varien_Action implements Mage_Core_Controlle
             return;
         }
 
-        if (Mage::app()->getFrontController()->getNoRender()) {
+        if ($this->_frontController->getNoRender()) {
             return;
         }
 
@@ -447,6 +457,8 @@ abstract class Mage_Core_Controller_Varien_Action implements Mage_Core_Controlle
             $profilerKey = 'CONTROLLER_ACTION:' . $this->getFullActionName();
             Magento_Profiler::start($profilerKey);
 
+            Mage::getConfig()->setCurrentAreaCode($this->_currentArea);
+
             Magento_Profiler::start('predispatch');
             $this->preDispatch();
             Magento_Profiler::stop('predispatch');
diff --git a/app/code/core/Mage/Core/Controller/Varien/Router/Base.php b/app/code/core/Mage/Core/Controller/Varien/Router/Base.php
index a869aaab123a34b5eea9cd0d904c7238eb45b468..aec07c102f1294019dddc291c07cb6f31cc5976e 100644
--- a/app/code/core/Mage/Core/Controller/Varien/Router/Base.php
+++ b/app/code/core/Mage/Core/Controller/Varien/Router/Base.php
@@ -301,12 +301,13 @@ class Mage_Core_Controller_Varien_Router_Base extends Mage_Core_Controller_Varie
             if (false == $controllerClassName) {
                 return null;
             }
-            // instantiate controller class
-            $controllerInstance = $this->_getControllerInstance($controllerClassName, $request);
 
-            if (false == $this->_validateControllerInstance($controllerInstance, $action)) {
+            if (false == $this->_validateControllerAction($controllerClassName, $action)) {
                 return null;
             }
+
+            // instantiate controller class
+            $controllerInstance = $this->_getControllerInstance($controllerClassName, $request);
         } else {
             return null;
         }
@@ -314,6 +315,18 @@ class Mage_Core_Controller_Varien_Router_Base extends Mage_Core_Controller_Varie
         return $controllerInstance;
     }
 
+    /**
+     * Check whether action handler exists for provided handler
+     *
+     * @param string $controllerClassName
+     * @param string $action
+     * @return bool
+     */
+    protected function _validateControllerAction($controllerClassName, $action)
+    {
+        return method_exists($controllerClassName, $action . 'Action');
+    }
+
     /**
      * Create matched controller instance
      *
@@ -370,12 +383,14 @@ class Mage_Core_Controller_Varien_Router_Base extends Mage_Core_Controller_Varie
                 continue;
             }
 
+            if (false === $this->_validateControllerAction($controllerClassName, $action)) {
+                continue;
+            }
+
+            Mage::getConfig()->setCurrentAreaCode($this->_area);
             // instantiate controller class
             $controllerInstance = $this->_getControllerInstance($controllerClassName, $request);
 
-            if (false == $this->_validateControllerInstance($controllerInstance, $action)) {
-                continue;
-            }
             $found = true;
             break;
         }
@@ -401,19 +416,6 @@ class Mage_Core_Controller_Varien_Router_Base extends Mage_Core_Controller_Varie
         return $controllerInstance;
     }
 
-    /**
-     * Validate accessibility of controller action
-     *
-     * @param Mage_Core_Controller_Varien_Action $controllerInstance
-     * @param string $action
-     *
-     * @return bool
-     */
-    protected function _validateControllerInstance($controllerInstance, $action)
-    {
-        return (bool) $controllerInstance->hasAction($action);
-    }
-
     /**
      * Get router default request path
      * @return string
diff --git a/app/code/core/Mage/Core/Helper/Cookie.php b/app/code/core/Mage/Core/Helper/Cookie.php
index 0d3f670a0a03e739ddc4fb0d8356045f3e4aabeb..ec43e3466d06690c842ccd4a96d998079924872f 100644
--- a/app/code/core/Mage/Core/Helper/Cookie.php
+++ b/app/code/core/Mage/Core/Helper/Cookie.php
@@ -48,6 +48,47 @@ class Mage_Core_Helper_Cookie extends Mage_Core_Helper_Abstract
      */
     const XML_PATH_COOKIE_RESTRICTION_LIFETIME = 'web/cookie/cookie_restriction_lifetime';
 
+    /**
+     * @var Mage_Core_Model_Store
+     */
+    protected $_currentStore;
+
+    /**
+     * @var Mage_Core_Model_Cookie
+     */
+    protected $_cookieModel;
+
+    /**
+     * @var Mage_Core_Model_Website
+     */
+    protected $_website;
+
+    /**
+     * @param array $data
+     */
+    public function __construct(array $data = array())
+    {
+        $this->_currentStore = isset($data['current_store']) ? $data['current_store'] : Mage::app()->getStore();
+
+        if (!($this->_currentStore instanceof Mage_Core_Model_Store)) {
+            throw new InvalidArgumentException('Required store object is invalid');
+        }
+
+        $this->_cookieModel = isset($data['cookie_model'])
+            ? $data['cookie_model'] : Mage::getSingleton('Mage_Core_Model_Cookie');
+
+        if (false == ($this->_cookieModel instanceof Mage_Core_Model_Cookie)) {
+            throw new InvalidArgumentException('Required cookie object is invalid');
+        }
+
+        $this->_website = isset($data['website']) ? $data['website'] : Mage::app()->getWebsite();
+
+        if (false == ($this->_website instanceof Mage_Core_Model_Website)) {
+            throw new InvalidArgumentException('Required website object is invalid');
+        }
+    }
+
+
     /**
      * Check if cookie restriction notice should be displayed
      *
@@ -56,20 +97,20 @@ class Mage_Core_Helper_Cookie extends Mage_Core_Helper_Abstract
     public function isUserNotAllowSaveCookie()
     {
         $acceptedSaveCookiesWebsites = $this->_getAcceptedSaveCookiesWebsites();
-        return Mage::getStoreConfig(self::XML_PATH_COOKIE_RESTRICTION) &&
-            empty($acceptedSaveCookiesWebsites[Mage::app()->getWebsite()->getId()]);
+        return $this->_currentStore->getConfig(self::XML_PATH_COOKIE_RESTRICTION) &&
+            empty($acceptedSaveCookiesWebsites[$this->_website->getId()]);
     }
 
     /**
-     * Return serialzed list of accepted save cookie website
+     * Return serialized list of accepted save cookie website
      *
      * @return string
      */
     public function getAcceptedSaveCookiesWebsiteIds()
     {
         $acceptedSaveCookiesWebsites = $this->_getAcceptedSaveCookiesWebsites();
-        $acceptedSaveCookiesWebsites[Mage::app()->getWebsite()->getId()] = 1;
-        return serialize($acceptedSaveCookiesWebsites);
+        $acceptedSaveCookiesWebsites[$this->_website->getId()] = 1;
+        return json_encode($acceptedSaveCookiesWebsites);
     }
 
     /**
@@ -79,8 +120,8 @@ class Mage_Core_Helper_Cookie extends Mage_Core_Helper_Abstract
      */
     protected function _getAcceptedSaveCookiesWebsites()
     {
-        $serializedList = Mage::getSingleton('Mage_Core_Model_Cookie')->get(self::IS_USER_ALLOWED_SAVE_COOKIE);
-        $unSerializedList = unserialize($serializedList);
+        $serializedList = $this->_cookieModel->get(self::IS_USER_ALLOWED_SAVE_COOKIE);
+        $unSerializedList = json_decode($serializedList, true);
         return is_array($unSerializedList) ? $unSerializedList : array();
     }
 
@@ -91,6 +132,6 @@ class Mage_Core_Helper_Cookie extends Mage_Core_Helper_Abstract
      */
     public function getCookieRestrictionLifetime()
     {
-        return (int)Mage::getStoreConfig(self::XML_PATH_COOKIE_RESTRICTION_LIFETIME);
+        return (int)$this->_currentStore->getConfig(self::XML_PATH_COOKIE_RESTRICTION_LIFETIME);
     }
 }
diff --git a/app/code/core/Mage/Core/Model/Acl/Builder.php b/app/code/core/Mage/Core/Model/Acl/Builder.php
index 64a7ed01ecb0d3ec9646d27d1ef2f9acd592cc0c..de37fab2270e370ff3c53aef55000f7f354966b2 100644
--- a/app/code/core/Mage/Core/Model/Acl/Builder.php
+++ b/app/code/core/Mage/Core/Model/Acl/Builder.php
@@ -31,6 +31,13 @@
  */
 class Mage_Core_Model_Acl_Builder
 {
+    /**
+     * Acl object
+     *
+     * @var Magento_Acl
+     */
+    protected $_acl;
+
     /**
      * Area configuration
      *
@@ -69,16 +76,18 @@ class Mage_Core_Model_Acl_Builder
      */
     public function getAcl()
     {
-        try {
-            $acl = $this->_objectFactory->getModelInstance('Magento_Acl');
-            $this->_objectFactory->getModelInstance($this->_getLoaderClass('resource'))->populateAcl($acl);
-            $this->_objectFactory->getModelInstance($this->_getLoaderClass('role'))->populateAcl($acl);
-            $this->_objectFactory->getModelInstance($this->_getLoaderClass('rule'))->populateAcl($acl);
-        } catch (Exception $e) {
-            throw new LogicException('Could not create acl object: ' . $e->getMessage());
+        if (!$this->_acl) {
+            try {
+                $acl = $this->_objectFactory->getModelInstance('Magento_Acl');
+                $this->_objectFactory->getModelInstance($this->_getLoaderClass('resource'))->populateAcl($acl);
+                $this->_objectFactory->getModelInstance($this->_getLoaderClass('role'))->populateAcl($acl);
+                $this->_objectFactory->getModelInstance($this->_getLoaderClass('rule'))->populateAcl($acl);
+                $this->_acl = $acl;
+            } catch (Exception $e) {
+                throw new LogicException('Could not create acl object: ' . $e->getMessage());
+            }
         }
-
-        return $acl;
+        return $this->_acl;
     }
 
     /**
diff --git a/app/code/core/Mage/Core/Model/Authorization.php b/app/code/core/Mage/Core/Model/Authorization.php
new file mode 100644
index 0000000000000000000000000000000000000000..60626891f1e9c76874baf48e8ab55a24def5d9f6
--- /dev/null
+++ b/app/code/core/Mage/Core/Model/Authorization.php
@@ -0,0 +1,137 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Mage
+ * @package     Mage_Core
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+/**
+ * Core Authorization model
+ */
+class Mage_Core_Model_Authorization
+{
+    /**
+     * ACL policy
+     *
+     * @var Magento_Authorization_Policy
+     */
+    protected $_aclPolicy;
+
+    /**
+     * ACL role locator
+     *
+     * @var Magento_Authorization_RoleLocator
+     */
+    protected $_aclRoleLocator;
+
+    /**
+     * @param array $data
+     */
+    public function __construct(array $data = array())
+    {
+        $this->_aclPolicy = isset($data['policy']) ? $data['policy'] : $this->_getAclPolicy();
+        $this->_aclRoleLocator = isset($data['roleLocator']) ? $data['roleLocator'] : $this->_getAclRoleLocator();
+    }
+
+    /**
+     * Get ACL policy object
+     *
+     * @return Magento_Authorization_Policy
+     * @throws InvalidArgumentException
+     */
+    protected function _getAclPolicy()
+    {
+        $areaConfig = Mage::getConfig()->getAreaConfig();
+        $policyClassName = isset($areaConfig['acl']['policy']) ?
+            $areaConfig['acl']['policy'] :
+            'Magento_Authorization_Policy_Default';
+
+        /** @var $aclBuilder Mage_Core_Model_Acl_Builder */
+        $aclBuilder = Mage::getSingleton('Mage_Core_Model_Acl_Builder', array(
+            'areaConfig' => Mage::getConfig()->getAreaConfig(),
+            'objectFactory' => Mage::getConfig(),
+        ));
+
+        /** @var $policyObject Magento_Authorization_Policy **/
+        $policyObject = new $policyClassName($aclBuilder->getAcl());
+        if (false == ($policyObject instanceof Magento_Authorization_Policy)) {
+            throw new InvalidArgumentException($policyClassName . ' is not instance of Magento_Authorization_Policy');
+        }
+
+        return $policyObject;
+    }
+
+    /**
+     * Get ACL role locator
+     *
+     * @return Magento_Authorization_RoleLocator
+     * @throws InvalidArgumentException
+     */
+    protected function _getAclRoleLocator()
+    {
+        $areaConfig = Mage::getConfig()->getAreaConfig();
+        $roleLocatorClassName = isset($areaConfig['acl']['roleLocator']) ?
+            $areaConfig['acl']['roleLocator'] :
+            'Magento_Authorization_RoleLocator_Default';
+
+        /** @var $roleLocatorObject Magento_Authorization_RoleLocator **/
+        $roleLocatorObject = Mage::getSingleton($roleLocatorClassName);
+
+        if (false == ($roleLocatorObject instanceof Magento_Authorization_RoleLocator)) {
+            throw new InvalidArgumentException(
+                $roleLocatorClassName . ' is not instance of Magento_Authorization_RoleLocator'
+            );
+        }
+        return $roleLocatorObject;
+    }
+
+    /**
+     * Check current user permission on resource and privilege
+     *
+     * @param   string $resource
+     * @param   string $privilege
+     * @return  boolean
+     */
+    public function isAllowed($resource, $privilege = null)
+    {
+        return $this->_aclPolicy->isAllowed($this->_aclRoleLocator->getAclRoleId(), $resource, $privilege);
+    }
+
+    /**
+     * Delete nodes that have "acl" attribute but value is "not allowed"
+     *
+     * In any case, the "acl" attribute will be unset
+     *
+     * @param Varien_Simplexml_Element $xml
+     */
+    public function filterAclNodes(Varien_Simplexml_Element $xml)
+    {
+        $limitations = $xml->xpath('//*[@acl]') ?: array();
+        foreach ($limitations as $node) {
+            if (!$this->isAllowed($node['acl'])) {
+                $node->unsetSelf();
+            } else {
+                unset($node['acl']);
+            }
+        }
+    }
+}
diff --git a/app/code/core/Mage/Core/Model/Config.php b/app/code/core/Mage/Core/Model/Config.php
index 68d16e939cc312241ed084cf122287e9c01b1422..5601fce66f79a1342fccb951e91a3b2b0a66381e 100644
--- a/app/code/core/Mage/Core/Model/Config.php
+++ b/app/code/core/Mage/Core/Model/Config.php
@@ -195,6 +195,20 @@ class Mage_Core_Model_Config extends Mage_Core_Model_Config_Base
      */
     protected $_moduleDirs = array();
 
+    /*
+     * Cache for declared modules to prevent loading modules' config twice
+     *
+     * @var array
+     */
+    protected $_modulesCache = array();
+
+    /**
+     * Current area code
+     *
+     * @var string
+     */
+    protected $_currentAreaCode = null;
+
     /**
      * Class construct
      *
@@ -359,14 +373,15 @@ class Mage_Core_Model_Config extends Mage_Core_Model_Config_Base
         Magento_Profiler::start('load_modules');
         $this->_loadDeclaredModules();
 
-        $resourceConfig = sprintf('config.%s.xml', $this->_getResourceConnectionModel('core'));
-        $this->loadModulesConfiguration(array('config.xml',$resourceConfig), $this);
+        Magento_Profiler::start('load_modules_configuration');
+        $this->loadModulesConfiguration(array('config.xml'), $this);
+        Magento_Profiler::stop('load_modules_configuration');
 
         /**
          * Prevent local.xml directives overwriting
          */
         $mergeConfig = clone $this->_prototype;
-        $this->_isLocalConfigLoaded = $mergeConfig->loadFile($this->getOptions()->getEtcDir().DS.'local.xml');
+        $this->_isLocalConfigLoaded = $mergeConfig->loadFile($this->getOptions()->getEtcDir() . DS . 'local.xml');
         if ($this->_isLocalConfigLoaded) {
             $this->extend($mergeConfig);
         }
@@ -809,27 +824,53 @@ class Mage_Core_Model_Config extends Mage_Core_Model_Config_Base
      */
     protected function _loadDeclaredModules()
     {
+        Magento_Profiler::start('load_modules_files');
         $moduleFiles = $this->_getDeclaredModuleFiles();
         if (!$moduleFiles) {
             return $this;
         }
+        Magento_Profiler::stop('load_modules_files');
 
         Magento_Profiler::start('load_modules_declaration');
-
         $unsortedConfig = new Mage_Core_Model_Config_Base('<config/>');
+        $emptyConfig = new Mage_Core_Model_Config_Element('<config><modules/></config>');
+        $declaredModules = array();
         foreach ($moduleFiles as $oneConfigFile) {
-            $fileConfig = new Mage_Core_Model_Config_Base($oneConfigFile);
-            foreach ($fileConfig->_xml->xpath('modules/*') as $module) {
-                $newModule = new Mage_Core_Model_Config_Element('<config><modules/></config>');
+            $path = explode(DIRECTORY_SEPARATOR, $oneConfigFile);
+            $moduleConfig = new Mage_Core_Model_Config_Base($oneConfigFile);
+            $modules = $moduleConfig->getXpath('modules/*');
+            if (!$modules) {
+                continue;
+            }
+            $cPath = count($path);
+            if ($cPath > 4) {
+                $moduleName = $path[$cPath - 4] . '_' . $path[$cPath - 3];
+                $this->_modulesCache[$moduleName] = $moduleConfig;
+            }
+            foreach ($modules as $module) {
+                $moduleName = $module->getName();
+                $isActive = (string)$module->active;
+                if (isset($declaredModules[$moduleName])) {
+                    $declaredModules[$moduleName]['active'] = $isActive;
+                    continue;
+                }
+                $newModule = clone $emptyConfig;
                 $newModule->modules->appendChild($module);
-                $unsortedConfig->extend(new Mage_Core_Model_Config_Base($newModule));
+                $declaredModules[$moduleName] = array(
+                    'active' => $isActive,
+                    'module' => $newModule,
+                );
+            }
+        }
+        foreach ($declaredModules as $moduleName => $module) {
+            if ($module['active'] == 'true') {
+                $module['module']->modules->{$moduleName}->active = 'true';
+                $unsortedConfig->extend(new Mage_Core_Model_Config_Base($module['module']));
             }
         }
-
         $sortedConfig = new Mage_Core_Model_Config_Module($unsortedConfig, $this->_allowedModules);
 
         $this->extend($sortedConfig);
-
         Magento_Profiler::stop('load_modules_declaration');
         return $this;
     }
@@ -906,23 +947,24 @@ class Mage_Core_Model_Config extends Mage_Core_Model_Config_Base
                 if (!is_array($fileName)) {
                     $fileName = array($fileName);
                 }
-
                 foreach ($fileName as $configFile) {
-                    $configFilePath = $this->getModuleDir('etc', $modName).DS.$configFile;
-                    if ($mergeModel->loadFile($configFilePath)) {
-                        $mergeToObject->extend($mergeModel, true);
-                        if ($configFile !== 'config.xml') {
-                            continue;
-                        }
+                    if ($configFile == 'config.xml' && isset($this->_modulesCache[$modName])) {
+                        $mergeToObject->extend($this->_modulesCache[$modName], true);
                         //Prevent overriding <active> node of module if it was redefined in etc/modules
                         $mergeToObject->extend(new Mage_Core_Model_Config_Base(
                             "<config><modules><{$modName}><active>true</active></{$modName}></modules></config>"),
                             true
                         );
+                    } else {
+                        $configFilePath = $this->getModuleDir('etc', $modName) . DS . $configFile;
+                        if ($mergeModel->loadFile($configFilePath)) {
+                            $mergeToObject->extend($mergeModel, true);
+                        }
                     }
                 }
             }
         }
+        unset($this->_modulesCache);
         return $mergeToObject;
     }
 
@@ -1532,11 +1574,12 @@ class Mage_Core_Model_Config extends Mage_Core_Model_Config_Base
     /**
      * Retrieve area config by area code
      *
-     * @param string $areaCode
+     * @param string|null $areaCode
      * @return array
      */
-    public function getAreaConfig($areaCode)
+    public function getAreaConfig($areaCode = null)
     {
+        $areaCode = empty($areaCode) ? $this->getCurrentAreaCode() : $areaCode;
         $areas = $this->getAreas();
         if (!isset($areas[$areaCode])) {
             throw new InvalidArgumentException('Requested area (' . $areaCode . ') doesn\'t exist');
@@ -1596,4 +1639,26 @@ class Mage_Core_Model_Config extends Mage_Core_Model_Config_Base
         }
         return $routers;
     }
+
+
+    /**
+     * Get currently used area code
+     * @return string|null
+     */
+    public function getCurrentAreaCode()
+    {
+        return $this->_currentAreaCode;
+    }
+
+    /**
+     * Set currently used area code
+     *
+     * @param $areaCode
+     * @return Mage_Core_Model_Config
+     */
+    public function setCurrentAreaCode($areaCode)
+    {
+        $this->_currentAreaCode = $areaCode;
+        return $this;
+    }
 }
diff --git a/app/code/core/Mage/Core/Model/Layout.php b/app/code/core/Mage/Core/Model/Layout.php
index c67b7c97ad94e07264f46f783ac56211b3ef05dd..c736c053346c2927ddf4d63b24cda39b24ecbe65 100644
--- a/app/code/core/Mage/Core/Model/Layout.php
+++ b/app/code/core/Mage/Core/Model/Layout.php
@@ -28,27 +28,62 @@
 /**
  * Layout model
  *
- * @category   Mage
- * @package    Mage_Core
+ * @category    Mage
+ * @package     Mage_Core
  * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
  * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 class Mage_Core_Model_Layout extends Varien_Simplexml_Config
 {
-    /**
-     * Supported structural element types
-     */
-    const TYPE_BLOCK = 'block';
-    const TYPE_CONTAINER = 'container';
-
-    /**
+    /**#@+
+     * Supported layout directives
+     */
+    const TYPE_BLOCK        = 'block';
+    const TYPE_CONTAINER    = 'container';
+    const TYPE_ACTION       = 'action';
+    const TYPE_REFERENCE    = 'reference';
+    const TYPE_REMOVE       = 'remove';
+    const TYPE_MOVE         = 'move';
+    /**#@-*/
+
+    /**#@+
      * Names of container options in layout
      */
     const CONTAINER_OPT_HTML_TAG   = 'htmlTag';
     const CONTAINER_OPT_HTML_CLASS = 'htmlClass';
     const CONTAINER_OPT_HTML_ID    = 'htmlId';
     const CONTAINER_OPT_LABEL      = 'label';
+    /**#@-*/
+
+    /**
+     * Scheduled structure array index for name
+     */
+    const SCHEDULED_STRUCTURE_INDEX_NAME = 0;
+
+    /**
+     * Scheduled structure array index for alias
+     */
+    const SCHEDULED_STRUCTURE_INDEX_ALIAS = 1;
+
+    /**
+     * Scheduled structure array index for parent element name
+     */
+    const SCHEDULED_STRUCTURE_INDEX_PARENT_NAME = 2;
+
+    /**
+     * Scheduled structure array index for sibling element name
+     */
+    const SCHEDULED_STRUCTURE_INDEX_SIBLING_NAME = 3;
+
+    /**
+     * Scheduled structure array index for is after parameter
+     */
+    const SCHEDULED_STRUCTURE_INDEX_IS_AFTER = 4;
+
+    /**
+     * Scheduled structure array index for layout element object
+     */
+    const SCHEDULED_STRUCTURE_INDEX_LAYOUT_ELEMENT = 5;
 
     /**
      * Layout Update module
@@ -141,6 +176,20 @@ class Mage_Core_Model_Layout extends Varien_Simplexml_Config
      */
     protected $_scheduledElements = array();
 
+    /**
+     * Scheduled structure elements moves
+     *
+     * @var array
+     */
+    protected $_scheduledMoves = array();
+
+    /**
+     * Scheduled structure elements removes
+     *
+     * @var array
+     */
+    protected $_scheduledRemoves = array();
+
     /**
      * Class constructor
      *
@@ -228,29 +277,6 @@ class Mage_Core_Model_Layout extends Varien_Simplexml_Config
     public function generateXml()
     {
         $xml = $this->getUpdate()->asSimplexml();
-        $removeInstructions = (array)$xml->xpath("//remove[@name]");
-        foreach ($removeInstructions as $infoNode) {
-            $attributes = $infoNode->attributes();
-            $blockName = (string)$attributes->name;
-            $xpath = "//block[@name='" . $blockName . "']"
-                . " | //reference[@name='" . $blockName . "']"
-                . " | //action[(@method='insert' or @method='append') and *[position()=1 and text()='$blockName']]";
-            $ignoreNodes = $xml->xpath($xpath);
-            if (!$ignoreNodes) {
-                continue;
-            }
-
-            foreach ($ignoreNodes as $block) {
-                $acl = (string)$attributes->acl;
-                if ($block->getAttribute('ignore') !== null || ($acl
-                    && Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($acl))) {
-                    continue;
-                }
-                if (!isset($block->attributes()->ignore)) {
-                    $block->addAttribute('ignore', true);
-                }
-            }
-        }
         $this->setXml($xml);
         $this->_structure->importElements(array());
         return $this;
@@ -271,25 +297,35 @@ class Mage_Core_Model_Layout extends Varien_Simplexml_Config
             reset($this->_scheduledStructure);
             $this->_scheduleElement(key($this->_scheduledStructure));
         };
+        $this->_scheduledPaths = array();
+
+        $moveList = array_keys(array_intersect_key($this->_scheduledElements, $this->_scheduledMoves));
+        foreach ($moveList as $elementToMove) {
+            $this->_moveElementInStructure($elementToMove);
+        }
+
+        $removeList = array_keys(array_intersect_key($this->_scheduledElements, $this->_scheduledRemoves));
+        foreach ($removeList as $elementToRemove) {
+            $this->_removeElement($elementToRemove);
+        }
         Magento_Profiler::stop('build_structure');
 
         Magento_Profiler::start('generate_elements');
         while (!empty($this->_scheduledElements)) {
             list($type, $node) = reset($this->_scheduledElements);
             $elementName = key($this->_scheduledElements);
+
             if (isset($node['output'])) {
                 $this->addOutputElement($elementName);
             }
             if ($type == self::TYPE_BLOCK) {
                 $this->_generateBlock($elementName);
             } else {
-                $this->_generateContainer($elementName, (string)$node[self::CONTAINER_OPT_LABEL],
-                    array(
-                        self::CONTAINER_OPT_HTML_TAG => (string)$node[self::CONTAINER_OPT_HTML_TAG],
-                        self::CONTAINER_OPT_HTML_ID => (string)$node[self::CONTAINER_OPT_HTML_ID],
-                        self::CONTAINER_OPT_HTML_CLASS => (string)$node[self::CONTAINER_OPT_HTML_CLASS]
-                    )
-                );
+                $this->_generateContainer($elementName, (string)$node[self::CONTAINER_OPT_LABEL], array(
+                    self::CONTAINER_OPT_HTML_TAG => (string)$node[self::CONTAINER_OPT_HTML_TAG],
+                    self::CONTAINER_OPT_HTML_ID => (string)$node[self::CONTAINER_OPT_HTML_ID],
+                    self::CONTAINER_OPT_HTML_CLASS => (string)$node[self::CONTAINER_OPT_HTML_CLASS]
+                ));
                 unset($this->_scheduledElements[$elementName]);
             }
         }
@@ -297,6 +333,46 @@ class Mage_Core_Model_Layout extends Varien_Simplexml_Config
         Magento_Profiler::stop(__CLASS__ . '::' . __METHOD__);
     }
 
+    /**
+     * Remove scheduled element
+     *
+     * @param string $elementName
+     * @param bool $isChild
+     * @return Mage_Core_Model_Layout
+     */
+    protected function _removeElement($elementName, $isChild = false)
+    {
+        $elementsToRemove = array_keys($this->_structure->getChildren($elementName));
+        unset($this->_scheduledElements[$elementName]);
+
+        foreach ($elementsToRemove as $element) {
+            $this->_removeElement($element, true);
+        }
+
+        if (!$isChild) {
+            $this->_structure->unsetElement($elementName);
+            unset($this->_scheduledRemoves[$elementName]);
+        }
+        return $this;
+    }
+
+    /**
+     * Move element in scheduled structure
+     *
+     * @param string $element
+     * @return Mage_Core_Model_Layout
+     */
+    protected function _moveElementInStructure($element)
+    {
+        list ($destination, $siblingName, $isAfter, $alias) = $this->_scheduledMoves[$element];
+        if (!$alias && false === $this->_structure->getChildId($destination, $this->getElementAlias($element))) {
+            $alias = $this->getElementAlias($element);
+        }
+        $this->_structure->unsetChild($element, $alias)->setAsChild($element, $destination, $alias);
+        $this->reorderChild($destination, $element, $siblingName, $isAfter);
+        return $this;
+    }
+
     /**
      * Traverse through all elements of specified XML-node and schedule structural elements of it
      *
@@ -304,31 +380,60 @@ class Mage_Core_Model_Layout extends Varien_Simplexml_Config
      */
     protected function _readStructure($parent)
     {
-        /** @var Mage_Core_Model_Layout_Element $node  */
+        /** @var Mage_Core_Model_Layout_Element $node */
         foreach ($parent as $node) {
-            $attributes = $node->attributes();
-            if ((bool)$attributes->ignore) {
-                continue;
-            }
             switch ($node->getName()) {
-                case 'container':
-                case 'block':
+                case self::TYPE_CONTAINER:
+                case self::TYPE_BLOCK:
                     $this->_scheduleStructure($node, $parent);
                     $this->_readStructure($node);
                     break;
 
-                case 'reference':
+                case self::TYPE_REFERENCE:
                     $this->_readStructure($node);
                     break;
 
-                case 'action':
+                case self::TYPE_ACTION:
                     $referenceName = $parent->getAttribute('name');
                     $this->_scheduledStructure[$referenceName]['actions'][] = array($node, $parent);
                     break;
+
+                case self::TYPE_MOVE:
+                    $this->_scheduleMove($node);
+                    break;
+
+                case self::TYPE_REMOVE:
+                    $this->_scheduledRemoves[(string)$node->getAttribute('name')] = 1;
+                    break;
+
+                default:
+                    break;
             }
         }
     }
 
+    /**
+     * Schedule structural changes for move directive
+     *
+     * @param Mage_Core_Model_Layout_Element $node
+     * @throws Magento_Exception
+     * @return Mage_Core_Model_Layout
+     */
+    protected function _scheduleMove($node)
+    {
+        $elementName = (string)$node->getAttribute('element');
+        $destination = (string)$node->getAttribute('destination');
+        $alias = (string)$node->getAttribute('as') ?: '';
+
+        if ($elementName && $destination) {
+            list($siblingName, $isAfter) = $this->_beforeAfterToSibling($node);
+            $this->_scheduledMoves[$elementName] = array($destination, $siblingName, $isAfter, $alias);
+        } else {
+            throw new Magento_Exception('Element name and destination must be specified.');
+        }
+        return $this;
+    }
+
     /**
      * Populate queue for generating structural elements
      *
@@ -338,32 +443,46 @@ class Mage_Core_Model_Layout extends Varien_Simplexml_Config
      */
     protected function _scheduleStructure($node, $parent)
     {
-        $name = (string)$node->getAttribute('name');
-        // type, alias, parentName, siblingName, isAfter, node
-        $row = array($node->getName(), '', '', null, true, $node);
+        if ((string)$node->getAttribute('name')) {
+            $name = (string)$node->getAttribute('name');
+        } else {
+            $name = $this->_generateAnonymousName();
+            $node->addAttribute('name', $name);
+        }
         $path = $name;
+
+        // type, alias, parentName, siblingName, isAfter, node
+        $row = array(
+            self::SCHEDULED_STRUCTURE_INDEX_NAME            => $node->getName(),
+            self::SCHEDULED_STRUCTURE_INDEX_ALIAS           => '',
+            self::SCHEDULED_STRUCTURE_INDEX_PARENT_NAME     => '',
+            self::SCHEDULED_STRUCTURE_INDEX_SIBLING_NAME    => null,
+            self::SCHEDULED_STRUCTURE_INDEX_IS_AFTER        => true,
+            self::SCHEDULED_STRUCTURE_INDEX_LAYOUT_ELEMENT  => $node
+        );
+
         $parentName = $parent->getElementName();
         if ($parentName) {
-            $row[1] = (string)$node->getAttribute('as');
-            $row[2] = $parentName;
-            list($row[3], $row[4]) = $this->_beforeAfterToSibling($node);
+            $row[self::SCHEDULED_STRUCTURE_INDEX_ALIAS] = (string)$node->getAttribute('as');
+            $row[self::SCHEDULED_STRUCTURE_INDEX_PARENT_NAME] = $parentName;
+
+            list(
+                $row[self::SCHEDULED_STRUCTURE_INDEX_SIBLING_NAME],
+                $row[self::SCHEDULED_STRUCTURE_INDEX_IS_AFTER]
+            ) = $this->_beforeAfterToSibling($node);
+
             // materialized path for referencing nodes in the plain array of _scheduledStructure
             if (isset($this->_scheduledPaths[$parentName])) {
                 $path = $this->_scheduledPaths[$parentName] . '/' . $path;
             }
         }
 
-        if ($name) {
-            $this->_overrideElementWorkaround($name, $path);
-            $this->_scheduledPaths[$name] = $path;
-            if (isset($this->_scheduledStructure[$name])) {
-                $this->_scheduledStructure[$name] = $row + $this->_scheduledStructure[$name]; // union of arrays
-            } else {
-                $this->_scheduledStructure[$name] = $row;
-            }
+        $this->_overrideElementWorkaround($name, $path);
+        $this->_scheduledPaths[$name] = $path;
+        if (isset($this->_scheduledStructure[$name])) {
+            $this->_scheduledStructure[$name] = $row + $this->_scheduledStructure[$name]; // union of arrays
         } else {
-            // anonymous elements get into queue with integer keys
-            $this->_scheduledStructure[] = $row;
+            $this->_scheduledStructure[$name] = $row;
         }
     }
 
@@ -399,8 +518,7 @@ class Mage_Core_Model_Layout extends Varien_Simplexml_Config
         if (isset($this->_scheduledStructure[$name])) {
             foreach ($this->_scheduledPaths as $potentialChild => $childPath) {
                 if (0 === strpos($childPath, "{$path}/")) {
-                    unset($this->_scheduledPaths[$potentialChild]);
-                    unset($this->_scheduledStructure[$potentialChild]);
+                    unset($this->_scheduledPaths[$potentialChild], $this->_scheduledStructure[$potentialChild]);
                 }
             }
         }
@@ -413,18 +531,19 @@ class Mage_Core_Model_Layout extends Varien_Simplexml_Config
      * Since layout updates could come in arbitrary order, a case is possible where an element is declared in reference,
      * while referenced element itself is not declared yet.
      *
-     * @param string $key in _scheduledStructure -- can be integer or represent element name
+     * @param string $key in _scheduledStructure represent element name
      */
     protected function _scheduleElement($key)
     {
         $row = $this->_scheduledStructure[$key];
-        if (!isset($row[5])) {
+
+        if (!isset($row[self::SCHEDULED_STRUCTURE_INDEX_LAYOUT_ELEMENT])) {
             Mage::log("Broken reference: missing declaration of the element '{$key}'.", Zend_Log::CRIT);
-            unset($this->_scheduledStructure[$key]);
+            unset($this->_scheduledStructure[$key], $this->_scheduledPaths[$key]);
             return;
         }
         list($type, $alias, $parentName, $siblingName, $isAfter, $node) = $row;
-        $name = $this->_createStructuralElement(is_int($key) ? '' : $key, $type);
+        $name = $this->_createStructuralElement($key, $type);
         if ($parentName) {
             // recursively populate parent first
             if (isset($this->_scheduledStructure[$parentName])) {
@@ -434,7 +553,7 @@ class Mage_Core_Model_Layout extends Varien_Simplexml_Config
                 $this->_structure->setAsChild($name, $parentName, $alias);
             } else {
                 Mage::log("Broken reference: the '{$name}' element cannot be added as child to '{$parentName}, "
-                        . 'because the latter doesn\'t exist', Zend_Log::CRIT
+                    . 'because the latter doesn\'t exist', Zend_Log::CRIT
                 );
             }
         }
@@ -447,7 +566,7 @@ class Mage_Core_Model_Layout extends Varien_Simplexml_Config
          */
         if ($siblingName) {
             if (isset($this->_scheduledStructure[$siblingName])) {
-                $this->_scheduleElement($siblingName, $this->_scheduledStructure[$siblingName]);
+                $this->_scheduleElement($siblingName);
             }
             $this->reorderChild($parentName, $name, $siblingName, $isAfter);
         }
@@ -465,12 +584,22 @@ class Mage_Core_Model_Layout extends Varien_Simplexml_Config
     protected function _createStructuralElement($name, $type)
     {
         if (empty($name)) {
-            $name = 'ANONYMOUS_' . $this->_nameIncrement++;
+            $name = $this->_generateAnonymousName();
         }
         $this->_structure->createElement($name, array('type' => $type));
         return $name;
     }
 
+    /**
+     * Generate anonymous element name for structure
+     *
+     * @return string
+     */
+    protected function _generateAnonymousName()
+    {
+        return 'ANONYMOUS_' . $this->_nameIncrement++;
+    }
+
     /**
      * Creates block object based on xml node data and add it to the layout
      *
@@ -1045,7 +1174,7 @@ class Mage_Core_Model_Layout extends Varien_Simplexml_Config
         $block->setLayout($this);
 
         $this->_blocks[$name] = $block;
-        Mage::dispatchEvent('core_layout_block_create_after', array('block'=>$block));
+        Mage::dispatchEvent('core_layout_block_create_after', array('block' => $block));
         return $this->_blocks[$name];
     }
 
@@ -1236,7 +1365,7 @@ class Mage_Core_Model_Layout extends Varien_Simplexml_Config
     }
 
     /**
-     * Enter description here...
+     * Get block singleton
      *
      * @param string $type
      * @return Mage_Core_Helper_Abstract
diff --git a/app/code/core/Mage/Core/Model/Registry.php b/app/code/core/Mage/Core/Model/Registry.php
new file mode 100644
index 0000000000000000000000000000000000000000..64763a9da600b1de72bb7f57fe531d24e905e5d5
--- /dev/null
+++ b/app/code/core/Mage/Core/Model/Registry.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Mage
+ * @package     Mage_Core
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+/**
+ * Registry model. Used to manage values in registry
+ */
+class Mage_Core_Model_Registry
+{
+    /**
+     * Retrieve a value from registry by a key
+     *
+     * @param string $key
+     * @return mixed
+     */
+    public function registry($key)
+    {
+        return Mage::registry($key);
+    }
+
+    /**
+     * Register a new variable
+     *
+     * @param string $key
+     * @param mixed $value
+     * @param bool $graceful
+     * @throws Mage_Core_Exception
+     */
+    public function register($key, $value, $graceful = false)
+    {
+       Mage::register($key, $value, $graceful);
+    }
+
+    /**
+     * Unregister a variable from register by key
+     *
+     * @param string $key
+     */
+    public function unregister($key)
+    {
+        Mage::unregister($key);
+    }
+}
diff --git a/app/code/core/Mage/CurrencySymbol/controllers/Adminhtml/System/CurrencysymbolController.php b/app/code/core/Mage/CurrencySymbol/controllers/Adminhtml/System/CurrencysymbolController.php
index 125eb1ae17dad3fceb94b7d52edfa76919fb001b..dd85a491ad1e94ae2a7b2e56138c14ef2e6a1237 100644
--- a/app/code/core/Mage/CurrencySymbol/controllers/Adminhtml/System/CurrencysymbolController.php
+++ b/app/code/core/Mage/CurrencySymbol/controllers/Adminhtml/System/CurrencysymbolController.php
@@ -95,6 +95,6 @@ class Mage_CurrencySymbol_Adminhtml_System_CurrencysymbolController extends Mage
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_CurrencySymbol::symbols');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_CurrencySymbol::symbols');
     }
 }
diff --git a/app/code/core/Mage/DesignEditor/controllers/Adminhtml/System/Design/EditorController.php b/app/code/core/Mage/DesignEditor/controllers/Adminhtml/System/Design/EditorController.php
index 8f8c33e0fb40c4c92adb672fbb0b49f0ba9769fe..186b0e0d758825ac97cda35ef1e1d480212b65c3 100644
--- a/app/code/core/Mage/DesignEditor/controllers/Adminhtml/System/Design/EditorController.php
+++ b/app/code/core/Mage/DesignEditor/controllers/Adminhtml/System/Design/EditorController.php
@@ -80,6 +80,6 @@ class Mage_DesignEditor_Adminhtml_System_Design_EditorController extends Mage_Ad
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_DesignEditor::editor');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_DesignEditor::editor');
     }
 }
diff --git a/app/code/core/Mage/Downloadable/controllers/Adminhtml/Downloadable/FileController.php b/app/code/core/Mage/Downloadable/controllers/Adminhtml/Downloadable/FileController.php
index beade69fe9fcc40ff68825272dcce13f673e4d1b..94f380d66821b985e60181cb38f74141faab1561 100644
--- a/app/code/core/Mage/Downloadable/controllers/Adminhtml/Downloadable/FileController.php
+++ b/app/code/core/Mage/Downloadable/controllers/Adminhtml/Downloadable/FileController.php
@@ -87,7 +87,7 @@ class Mage_Downloadable_Adminhtml_Downloadable_FileController extends Mage_Admin
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Catalog::products');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Catalog::products');
     }
 
 }
diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Tab/Googleoptimizer.php b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Tab/Googleoptimizer.php
index 17f23c9228cd01e43dd5a6119610fac69b32b2b3..3990d09f2b4c43688680f9680e9fac382dda00b9 100644
--- a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Tab/Googleoptimizer.php
+++ b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Tab/Googleoptimizer.php
@@ -247,6 +247,6 @@ class Mage_GoogleOptimizer_Block_Adminhtml_Cms_Page_Edit_Tab_Googleoptimizer
      */
     protected function _isAllowedAction($resourceId)
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($resourceId);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($resourceId);
     }
 }
diff --git a/app/code/core/Mage/GoogleShopping/controllers/Adminhtml/Googleshopping/ItemsController.php b/app/code/core/Mage/GoogleShopping/controllers/Adminhtml/Googleshopping/ItemsController.php
index a63c6913424b88b85903612c4ed4e2791b3409a5..673c69e197289687dc87da0943859bccc59923f9 100644
--- a/app/code/core/Mage/GoogleShopping/controllers/Adminhtml/Googleshopping/ItemsController.php
+++ b/app/code/core/Mage/GoogleShopping/controllers/Adminhtml/Googleshopping/ItemsController.php
@@ -334,6 +334,6 @@ class Mage_GoogleShopping_Adminhtml_Googleshopping_ItemsController extends Mage_
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_GoogleShopping::items');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_GoogleShopping::items');
     }
 }
diff --git a/app/code/core/Mage/GoogleShopping/controllers/Adminhtml/Googleshopping/TypesController.php b/app/code/core/Mage/GoogleShopping/controllers/Adminhtml/Googleshopping/TypesController.php
index fcf415c8cdb195f9c1c369ee8582296065460066..3ecac38b64153862c36b8d40c368f2ea7d370ae1 100644
--- a/app/code/core/Mage/GoogleShopping/controllers/Adminhtml/Googleshopping/TypesController.php
+++ b/app/code/core/Mage/GoogleShopping/controllers/Adminhtml/Googleshopping/TypesController.php
@@ -294,6 +294,6 @@ class Mage_GoogleShopping_Adminhtml_Googleshopping_TypesController extends Mage_
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_GoogleShopping::types');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_GoogleShopping::types');
     }
 }
diff --git a/app/code/core/Mage/ImportExport/controllers/Adminhtml/ExportController.php b/app/code/core/Mage/ImportExport/controllers/Adminhtml/ExportController.php
index da109220819553502699029094c3f9c61c8899a3..63e1c19e2e6140bb3c4fb2c36e23c81d4ce7ba7b 100644
--- a/app/code/core/Mage/ImportExport/controllers/Adminhtml/ExportController.php
+++ b/app/code/core/Mage/ImportExport/controllers/Adminhtml/ExportController.php
@@ -65,7 +65,7 @@ class Mage_ImportExport_Adminhtml_ExportController extends Mage_Adminhtml_Contro
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_ImportExport::export');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_ImportExport::export');
     }
 
     /**
diff --git a/app/code/core/Mage/ImportExport/controllers/Adminhtml/ImportController.php b/app/code/core/Mage/ImportExport/controllers/Adminhtml/ImportController.php
index 2225987d6fdc1fc1a5f344717e7da48468622b9c..9e712c2bf804b28955fff47d39a6826301067f62 100644
--- a/app/code/core/Mage/ImportExport/controllers/Adminhtml/ImportController.php
+++ b/app/code/core/Mage/ImportExport/controllers/Adminhtml/ImportController.php
@@ -65,7 +65,7 @@ class Mage_ImportExport_Adminhtml_ImportController extends Mage_Adminhtml_Contro
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_ImportExport::import');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_ImportExport::import');
     }
 
     /**
diff --git a/app/code/core/Mage/Index/Block/Adminhtml/Notifications.php b/app/code/core/Mage/Index/Block/Adminhtml/Notifications.php
index e212a9a96901f5eedd1e2a74eca42059e0bc9c2c..e36c8bb70f4c8e5b697f1290dc7f4bb8ec2318d3 100644
--- a/app/code/core/Mage/Index/Block/Adminhtml/Notifications.php
+++ b/app/code/core/Mage/Index/Block/Adminhtml/Notifications.php
@@ -63,7 +63,7 @@ class Mage_Index_Block_Adminhtml_Notifications extends Mage_Adminhtml_Block_Temp
      */
     protected function _toHtml()
     {
-        if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Index::index')) {
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Index::index')) {
             return parent::_toHtml();
         }
         return '';
diff --git a/app/code/core/Mage/Index/controllers/Adminhtml/ProcessController.php b/app/code/core/Mage/Index/controllers/Adminhtml/ProcessController.php
index 6abde0485ab442344437cac15240b76bd9bc1ab0..2f079e928e08153800b1096e07eba7de1979980b 100644
--- a/app/code/core/Mage/Index/controllers/Adminhtml/ProcessController.php
+++ b/app/code/core/Mage/Index/controllers/Adminhtml/ProcessController.php
@@ -238,6 +238,6 @@ class Mage_Index_Adminhtml_ProcessController extends Mage_Adminhtml_Controller_A
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Index::index');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Index::index');
     }
 }
diff --git a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/AuthorizedTokens/Grid.php b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/AuthorizedTokens/Grid.php
index 3a03cc74f92a2ecd4a0d2aa9b023214490ced8ee..f5695080f8ecbdcb4777f0fbfb10e4a8a7fd433f 100644
--- a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/AuthorizedTokens/Grid.php
+++ b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/AuthorizedTokens/Grid.php
@@ -218,8 +218,6 @@ class Mage_Oauth_Block_Adminhtml_Oauth_AuthorizedTokens_Grid extends Mage_Adminh
      */
     protected function _isAllowed()
     {
-        /** @var $session Mage_Backend_Model_Auth_Session */
-        $session = Mage::getSingleton('Mage_Backend_Model_Auth_Session');
-        return $session->isAllowed('Mage_Oauth::authorizedTokens');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Oauth::authorizedTokens');
     }
 }
diff --git a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer.php b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer.php
index ab9159248bc9cf97911ba511b05445f417befe52..ff1362719be7a1b570243f0d368c9ccbc86797bc 100644
--- a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer.php
+++ b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer.php
@@ -45,9 +45,7 @@ class Mage_Oauth_Block_Adminhtml_Oauth_Consumer extends Mage_Adminhtml_Block_Wid
         $this->_headerText = Mage::helper('Mage_Adminhtml_Helper_Data')->__('OAuth Consumers');
 
         //check allow edit
-        /** @var $session Mage_Backend_Model_Auth_Session */
-        $session = Mage::getSingleton('Mage_Backend_Model_Auth_Session');
-        if (!$session->isAllowed('Mage_Oauth::consumer_edit')) {
+        if (!Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Oauth::consumer_edit')) {
             $this->_removeButton('add');
         }
     }
diff --git a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Edit.php b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Edit.php
index 16f646b03c00b70617e02d1032bcc20b3d2f6040..fc799acb7926c50f5e95a51fe41860412e885e18 100644
--- a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Edit.php
+++ b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Edit.php
@@ -77,9 +77,9 @@ class Mage_Oauth_Block_Adminhtml_Oauth_Consumer_Edit extends Mage_Adminhtml_Bloc
         $this->_updateButton('save', 'id', 'save_button');
         $this->_updateButton('delete', 'label', $this->__('Delete'));
 
-        /** @var $session Mage_Backend_Model_Auth_Session */
-        $session = Mage::getSingleton('Mage_Backend_Model_Auth_Session');
-        if (!$this->getModel() || !$this->getModel()->getId() || !$session->isAllowed('Mage_Oauth::consumer_delete')) {
+        /** @var $auth Mage_Core_Model_Authorization */
+        $auth = Mage::getSingleton('Mage_Core_Model_Authorization');
+        if (!$this->getModel() || !$this->getModel()->getId() || !$auth->isAllowed('Mage_Oauth::consumer_delete')) {
             $this->_removeButton('delete');
         }
     }
diff --git a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Grid.php b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Grid.php
index 19f635941a3ffc051e3430eae99e54deb46d8d5b..9e12672ea78d425014d5e3750c30a9d36819957d 100644
--- a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Grid.php
+++ b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Grid.php
@@ -52,9 +52,7 @@ class Mage_Oauth_Block_Adminhtml_Oauth_Consumer_Grid extends Mage_Adminhtml_Bloc
         $this->setDefaultSort('entity_id')
             ->setDefaultDir(Varien_Db_Select::SQL_DESC);
 
-        /** @var $session Mage_Backend_Model_Auth_Session */
-        $session = Mage::getSingleton('Mage_Backend_Model_Auth_Session');
-        $this->_editAllow = $session->isAllowed('Mage_Oauth::consumer_edit');
+        $this->_editAllow = Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Oauth::consumer_edit');
     }
 
     /**
diff --git a/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/Admin/TokenController.php b/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/Admin/TokenController.php
index a43dcafb88550a80fcaabddb85927bdb6218eca1..3d0e2531604890993250ebd1c9f60283a69f44a6 100644
--- a/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/Admin/TokenController.php
+++ b/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/Admin/TokenController.php
@@ -179,8 +179,6 @@ class Mage_Oauth_Adminhtml_Oauth_Admin_TokenController extends Mage_Adminhtml_Co
      */
     protected function _isAllowed()
     {
-        /** @var $session Mage_Backend_Model_Auth_Session */
-        $session = Mage::getSingleton('Mage_Backend_Model_Auth_Session');
-        return $session->isAllowed('Mage_Oauth::oauth_admin_token');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Oauth::oauth_admin_token');
     }
 }
diff --git a/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/AuthorizedTokensController.php b/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/AuthorizedTokensController.php
index cf5ca728612afba5d384f23b0f23f0d92d60ff40..f39ea38dec99021fe6ac6c1d74531de4956fd605 100644
--- a/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/AuthorizedTokensController.php
+++ b/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/AuthorizedTokensController.php
@@ -161,9 +161,7 @@ class Mage_Oauth_Adminhtml_Oauth_AuthorizedTokensController extends Mage_Adminht
      */
     protected function _isAllowed()
     {
-        /** @var $session Mage_Backend_Model_Auth_Session */
-        $session = Mage::getSingleton('Mage_Backend_Model_Auth_Session');
-        return $session->isAllowed('Mage_Oauth::authorizedTokens');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Oauth::authorizedTokens');
     }
 
     /**
diff --git a/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/ConsumerController.php b/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/ConsumerController.php
index 771274f770bb2f62881abfb24a8208ca87df6690..4cf013f3649aec9c5308b31462c300507f40b6fb 100644
--- a/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/ConsumerController.php
+++ b/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/ConsumerController.php
@@ -250,9 +250,7 @@ class Mage_Oauth_Adminhtml_Oauth_ConsumerController extends Mage_Adminhtml_Contr
                 break;
         }
 
-        /** @var $session Mage_Backend_Model_Auth_Session*/
-        $session = Mage::getSingleton('Mage_Backend_Model_Auth_Session');
-        return $session->isAllowed($resourceId);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($resourceId);
     }
 
     /**
diff --git a/app/code/core/Mage/PageCache/Block/Adminhtml/Cache/Additional.php b/app/code/core/Mage/PageCache/Block/Adminhtml/Cache/Additional.php
index 762e72fc54133d405db85e63f28b76bee1e354d6..ef29d2b1030d55f75536be6b72995a709680316b 100644
--- a/app/code/core/Mage/PageCache/Block/Adminhtml/Cache/Additional.php
+++ b/app/code/core/Mage/PageCache/Block/Adminhtml/Cache/Additional.php
@@ -51,6 +51,6 @@ class Mage_PageCache_Block_Adminhtml_Cache_Additional extends Mage_Adminhtml_Blo
     public function canShowButton()
     {
         return Mage::helper('Mage_PageCache_Helper_Data')->isEnabled()
-            && Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_PageCache::page_cache');
+            && Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_PageCache::page_cache');
     }
 }
diff --git a/app/code/core/Mage/PageCache/controllers/Adminhtml/PageCacheController.php b/app/code/core/Mage/PageCache/controllers/Adminhtml/PageCacheController.php
index 633f52c0ac0e79d3a4fbbeb3d52fd4b7d541db5f..d06b575ed9144eab9793f152b5529320e1b55761 100644
--- a/app/code/core/Mage/PageCache/controllers/Adminhtml/PageCacheController.php
+++ b/app/code/core/Mage/PageCache/controllers/Adminhtml/PageCacheController.php
@@ -77,6 +77,6 @@ class Mage_PageCache_Adminhtml_PageCacheController extends Mage_Adminhtml_Contro
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_PageCache::page_cache');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_PageCache::page_cache');
     }
 }
diff --git a/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Report.php b/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Report.php
index 99705a99029bc3cb11dfa0bc926a010932ac4e76..b056b618af83a804e5d0b2e0fd20e171e6993bbf 100644
--- a/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Report.php
+++ b/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Report.php
@@ -44,10 +44,12 @@ class Mage_Paypal_Block_Adminhtml_Settlement_Report extends Mage_Adminhtml_Block
         parent::__construct();
         $this->_removeButton('add');
         $message = Mage::helper('Mage_Paypal_Helper_Data')->__('Connecting to PayPal SFTP server to fetch new reports. Are you sure you want to proceed?');
-        $this->_addButton('fetch', array(
-            'label'   => Mage::helper('Mage_Paypal_Helper_Data')->__('Fetch Updates'),
-            'onclick' => "confirmSetLocation('{$message}', '{$this->getUrl('*/*/fetch')}')",
-            'class'   => 'task'
-        ));
+        if (true == Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Paypal::fetch')) {
+            $this->_addButton('fetch', array(
+                'label'   => Mage::helper('Mage_Paypal_Helper_Data')->__('Fetch Updates'),
+                'onclick' => "confirmSetLocation('{$message}', '{$this->getUrl('*/*/fetch')}')",
+                'class'   => 'task'
+            ));
+        }
     }
 }
diff --git a/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php b/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php
index 2835b5ac3c688e56ccb955bdf2058d33b82157eb..2796179aa0a6876745f336ad26b6abe9c4bba921 100644
--- a/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php
+++ b/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php
@@ -131,13 +131,13 @@ class Mage_Paypal_Adminhtml_Paypal_ReportsController extends Mage_Adminhtml_Cont
         switch ($this->getRequest()->getActionName()) {
             case 'index':
             case 'details':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Paypal::paypal_settlement_reports_view');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Paypal::paypal_settlement_reports_view');
                 break;
             case 'fetch':
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Paypal::fetch');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Paypal::fetch');
                 break;
             default:
-                return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Paypal::paypal_settlement_reports');
+                return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Paypal::paypal_settlement_reports');
                 break;
         }
     }
diff --git a/app/code/core/Mage/Rss/controllers/CatalogController.php b/app/code/core/Mage/Rss/controllers/CatalogController.php
index 469a19026f0a6f1f9fc690fe16b5621d9ec4a0c9..2990326bf5cacfede3b0b87d0073d38c12f34ee2 100644
--- a/app/code/core/Mage/Rss/controllers/CatalogController.php
+++ b/app/code/core/Mage/Rss/controllers/CatalogController.php
@@ -41,7 +41,10 @@ class Mage_Rss_CatalogController extends Mage_Core_Controller_Front_Action
     public function preDispatch()
     {
         $action = $this->getRequest()->getActionName();
-        $acl = array('notifystock' => 'catalog/products', 'review' => 'catalog/reviews_ratings');
+        /**
+         * Format actionName => acrResourceId
+         */
+        $acl = array('notifystock' => 'Mage_Catalog::products', 'review' => 'Mage_Review::reviews_ratings');
         if (isset($acl[$action])) {
             $this->setCurrentArea('adminhtml');
             if (Mage_Rss_OrderController::authenticateAndAuthorizeAdmin($this, $acl[$action])) {
diff --git a/app/code/core/Mage/Rss/controllers/OrderController.php b/app/code/core/Mage/Rss/controllers/OrderController.php
index b1ad95858c44d7eb0a42ef0ec3be4123cc3f22c3..57ed60e4f96597063faf516daabf957d736eeb2a 100644
--- a/app/code/core/Mage/Rss/controllers/OrderController.php
+++ b/app/code/core/Mage/Rss/controllers/OrderController.php
@@ -72,7 +72,7 @@ class Mage_Rss_OrderController extends Mage_Core_Controller_Front_Action
         }
 
         // verify if logged in and authorized
-        if (!$session->isLoggedIn() || !$session->isAllowed($aclResource)) {
+        if (!$session->isLoggedIn() || !Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($aclResource)) {
             Mage::helper('Mage_Core_Helper_Http')->failHttpAuthentication($controller->getResponse(), 'RSS Feeds');
             $controller->setFlag('', self::FLAG_NO_DISPATCH, true);
             return false;
diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View.php b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View.php
index f917fa9dc54d6d6fe045217e76eb7f340f1407bc..ef23116f99086713deffb528014838e5db7bfe1d 100644
--- a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View.php
+++ b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View.php
@@ -107,6 +107,6 @@ class Mage_Sales_Block_Adminhtml_Billing_Agreement_View extends Mage_Adminhtml_B
      */
     protected function _isAllowed($resourceId)
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed($resourceId);
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed($resourceId);
     }
 }
diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Orders.php b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Orders.php
index 8b1846a991fa3dca8503aef73164da34b5a09059..152439e8ce4445748aa668f6c745623e286d189c 100644
--- a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Orders.php
+++ b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Orders.php
@@ -122,7 +122,7 @@ class Mage_Sales_Block_Adminhtml_Recurring_Profile_View_Tab_Orders
             'options' => Mage::getSingleton('Mage_Sales_Model_Order_Config')->getStatuses(),
         ));
 
-        if (Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::actions_view')) {
+        if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::actions_view')) {
             $this->addColumn('action',
                 array(
                     'header'    => Mage::helper('Mage_Sales_Helper_Data')->__('Action'),
diff --git a/app/code/core/Mage/Sales/Model/Observer.php b/app/code/core/Mage/Sales/Model/Observer.php
index 0561b9b5845b10a83b91a1dd50dea6ea827c8f68..d550e28687938e2100fc1d31ac878c9ca4be1f4d 100644
--- a/app/code/core/Mage/Sales/Model/Observer.php
+++ b/app/code/core/Mage/Sales/Model/Observer.php
@@ -269,7 +269,7 @@ class Mage_Sales_Model_Observer
         if (!($methodInstance instanceof Mage_Sales_Model_Payment_Method_Billing_AgreementAbstract)) {
             return;
         }
-        if (!Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Sales::use')) {
+        if (!Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Sales::use')) {
             $observer->getEvent()->getResult()->isAvailable = false;
         }
     }
diff --git a/app/code/core/Mage/User/Block/Role/Tab/Edit.php b/app/code/core/Mage/User/Block/Role/Tab/Edit.php
index fd0ec4af82a52d9ebb1a701dc24570e297641b61..aee861523588a396217ee0bccf969536191ae8ab 100644
--- a/app/code/core/Mage/User/Block/Role/Tab/Edit.php
+++ b/app/code/core/Mage/User/Block/Role/Tab/Edit.php
@@ -76,16 +76,21 @@ class Mage_User_Block_Role_Tab_Edit extends Mage_Backend_Block_Widget_Form
 
     /**
      * Class constructor
-     *
+     * @param array $data
      */
-    public function __construct()
+    public function __construct(array $data = array())
     {
         parent::__construct();
 
         $rid = Mage::app()->getRequest()->getParam('rid', false);
 
-        /** @var $acl Magento_Acl */
-        $acl = Mage::getModel('Mage_Backend_Model_Auth_Session')->getAcl();
+        $acl = isset($data['acl']) ? $data['acl'] : Mage::getSingleton(
+            'Mage_Core_Model_Acl_Builder',
+            array(
+                'areaConfig' => Mage::getConfig()->getAreaConfig(),
+                'objectFactory' => Mage::getConfig()
+            )
+        )->getAcl();
         $rulesSet = Mage::getResourceModel('Mage_User_Model_Resource_Rules_Collection')->getByRoles($rid)->load();
 
         $selectedResourceIds = array();
diff --git a/app/code/core/Mage/User/Model/Resource/Rules.php b/app/code/core/Mage/User/Model/Resource/Rules.php
index 11b95c032faa320d5f1e04931d36d9275500f251..ac4e3e802ceec6621093a6f11676ba69296a3d52 100755
--- a/app/code/core/Mage/User/Model/Resource/Rules.php
+++ b/app/code/core/Mage/User/Model/Resource/Rules.php
@@ -77,7 +77,7 @@ class Mage_User_Model_Resource_Rules extends Mage_Core_Model_Resource_Db_Abstrac
 
                     $adapter->insert($this->getMainTable(), $insertData);
                 } else {
-                    $acl = Mage::getModel('Mage_Backend_Model_Auth_Session')->getAcl();
+                    $acl = Mage::getSingleton('Mage_Core_Model_Acl_Builder')->getAcl();
                     /** @var $resource Magento_Acl_Resource */
                     foreach ($acl->getResources() as $resourceId) {
                         $row['permission'] = in_array($resourceId, $postedResources) ? 'allow' : 'deny';
diff --git a/app/code/core/Mage/User/controllers/Adminhtml/User/RoleController.php b/app/code/core/Mage/User/controllers/Adminhtml/User/RoleController.php
index f40f4e6c0d54849ec672280db485719899458c12..c9b5e2169f1051ee9545ddc0f2c89c69d01db0b0 100644
--- a/app/code/core/Mage/User/controllers/Adminhtml/User/RoleController.php
+++ b/app/code/core/Mage/User/controllers/Adminhtml/User/RoleController.php
@@ -286,6 +286,6 @@ class Mage_User_Adminhtml_User_RoleController extends Mage_Backend_Controller_Ac
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_User::acl_roles');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_User::acl_roles');
     }
 }
diff --git a/app/code/core/Mage/User/controllers/Adminhtml/UserController.php b/app/code/core/Mage/User/controllers/Adminhtml/UserController.php
index 1721d97ce04d8b13e467639e8e2b5a458044cdb4..ec9dd20e6b2b74970df8e53cdcb49190af6379b9 100644
--- a/app/code/core/Mage/User/controllers/Adminhtml/UserController.php
+++ b/app/code/core/Mage/User/controllers/Adminhtml/UserController.php
@@ -214,7 +214,7 @@ class Mage_User_Adminhtml_UserController extends Mage_Backend_Controller_ActionA
 
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_User::acl_users');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_User::acl_users');
     }
 
 }
diff --git a/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php b/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php
index f371d1a17c021da84da7dff10d7bf54be13c84bd..c79ffcc17cc7d50ddd8185e7d345d8fc07ff95e1 100644
--- a/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php
+++ b/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php
@@ -304,6 +304,6 @@ class Mage_Widget_Adminhtml_Widget_InstanceController extends Mage_Adminhtml_Con
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_Widget::widget_instance');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Widget::widget_instance');
     }
 }
diff --git a/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php b/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php
index 1ca55fb41f1c3f746adaf5e49eaa6fb8bdff5bca..bf67c8b85945df91d78d0330be746bbdbae3f5f8 100644
--- a/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php
+++ b/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php
@@ -777,7 +777,7 @@ class Mage_XmlConnect_Adminhtml_MobileController extends Mage_Adminhtml_Controll
      */
     protected function _isAllowed()
     {
-        return Mage::getSingleton('Mage_Backend_Model_Auth_Session')->isAllowed('Mage_XmlConnect::xmlconnect');
+        return Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_XmlConnect::xmlconnect');
     }
 
     /**
diff --git a/dev/tests/integration/framework/Magento/Test/Bootstrap.php b/dev/tests/integration/framework/Magento/Test/Bootstrap.php
index 6ca290dd140deb7becc23740c9affa655041f174..4d4208c63c799fc318157424c725977a65d47593 100644
--- a/dev/tests/integration/framework/Magento/Test/Bootstrap.php
+++ b/dev/tests/integration/framework/Magento/Test/Bootstrap.php
@@ -327,7 +327,9 @@ class Magento_Test_Bootstrap
     {
         switch ($this->_cleanupAction) {
             case self::CLEANUP_UNINSTALL:
-                $this->_db->cleanup();
+                if (!$this->_db->cleanup()) {
+                    throw new Magento_Exception("Database cleanup failed.");
+                }
                 $this->_cleanupFilesystem();
                 break;
             case self::CLEANUP_RESTORE_DB:
diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/BootstrapTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/BootstrapTest.php
index 1625a5c66f91e107a0209337d51dc7c070f930ff..5241636735bc62dd0dd92ea12d1dc751a1a49fcd 100644
--- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/BootstrapTest.php
+++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/BootstrapTest.php
@@ -223,6 +223,7 @@ class Magento_Test_BootstrapTest extends PHPUnit_Framework_TestCase
         $this->_db
             ->expects($this->exactly(1))
             ->method('cleanup')
+            ->will($this->returnValue(true))
         ;
         $this->_bootstrap
             ->expects($this->exactly(1))
@@ -231,6 +232,19 @@ class Magento_Test_BootstrapTest extends PHPUnit_Framework_TestCase
         $this->_callBootstrapConstructor(null, Magento_Test_Bootstrap::CLEANUP_UNINSTALL);
     }
 
+    /**
+     * @expectedException Magento_Exception
+     */
+    public function testConstructorCleanupUninstallWithFail()
+    {
+        $this->_db
+            ->expects($this->exactly(1))
+            ->method('cleanup')
+            ->will($this->returnValue(false))
+        ;
+        $this->_callBootstrapConstructor(null, Magento_Test_Bootstrap::CLEANUP_UNINSTALL);
+    }
+
     public function testConstructorCleanupRestoreDb()
     {
         $this->_db
diff --git a/dev/tests/integration/testsuite/Mage/Adminhtml/Block/Catalog/Product/Edit/TabsTest.php b/dev/tests/integration/testsuite/Mage/Adminhtml/Block/Catalog/Product/Edit/TabsTest.php
index b8ab6f23beeeaab6a4fe08131780b2b9721dc8af..43e061da66443da8e922b27a05ad1e2cbd586983 100644
--- a/dev/tests/integration/testsuite/Mage/Adminhtml/Block/Catalog/Product/Edit/TabsTest.php
+++ b/dev/tests/integration/testsuite/Mage/Adminhtml/Block/Catalog/Product/Edit/TabsTest.php
@@ -32,6 +32,7 @@ class Mage_Adminhtml_Block_Catalog_Product_Edit_TabsTest extends PHPUnit_Framewo
      */
     public function testPrepareLayout()
     {
+        Mage::getConfig()->setCurrentAreaCode(Mage::helper("Mage_Backend_Helper_Data")->getAreaCode());
         $product = new Mage_Catalog_Model_Product;
         $product->load(1); // fixture
         Mage::register('product', $product);
diff --git a/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/CustomerControllerTest.php b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/CustomerControllerTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..1584023f273ad3b11f5a0c98ad61bbfc124284ad
--- /dev/null
+++ b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/CustomerControllerTest.php
@@ -0,0 +1,286 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Mage
+ * @package     Mage_Adminhtml
+ * @subpackage  integration_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+class Mage_Adminhtml_CustomerControllerTest extends Mage_Adminhtml_Utility_Controller
+{
+    /**
+     * Base controller URL
+     *
+     * @var string
+     */
+    protected $_baseControllerUrl;
+
+    public function setUp()
+    {
+        parent::setUp();
+        $this->_baseControllerUrl = 'http://localhost/index.php/backend/admin/customer/';
+    }
+
+    public function tearDown()
+    {
+        /**
+         * Unset customer data
+         */
+        Mage::getSingleton('Mage_Backend_Model_Session')->setCustomerData(null);
+
+        /**
+         * Unset messages
+         */
+        Mage::getSingleton('Mage_Backend_Model_Session')->getMessages(true);
+    }
+
+
+    public function testSaveActionWithEmptyPostData()
+    {
+        $this->getRequest()->setPost(array());
+        $this->dispatch('backend/admin/customer/save');
+        $this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl . 'index/key'));
+    }
+
+    public function testSaveActionWithInvalidFormData()
+    {
+        $post = array(
+            'account' => array(
+                'middlename' => 'test middlename',
+                'group_id' => 1
+            )
+        );
+        $this->getRequest()->setPost($post);
+        $this->dispatch('backend/admin/customer/save');
+        /**
+         * Check that errors was generated and set to session
+         */
+        $this->assertNotEmpty(Mage::getSingleton('Mage_Backend_Model_Session')->getMessages(false)->getErrors());
+        /**
+         * Check that customer data were set to session
+         */
+        $this->assertEquals($post, Mage::getSingleton('Mage_Backend_Model_Session')->getCustomerData());
+        $this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl . 'edit/key'));
+    }
+
+    public function testSaveActionWithInvalidCustomerAddressData()
+    {
+        $post = array(
+            'account' => array(
+                'middlename' => 'test middlename',
+                'group_id' => 1,
+                'website_id' => 0,
+                'firstname' => 'test firstname',
+                'lastname' => 'test lastname',
+                'email' => 'exmaple@domain.com',
+                'default_billing' => '_item1',
+            ),
+            'address' => array('_item1' => array()),
+        );
+        $this->getRequest()->setPost($post);
+        $this->dispatch('backend/admin/customer/save');
+        /**
+         * Check that errors was generated and set to session
+         */
+        $this->assertNotEmpty(Mage::getSingleton('Mage_Backend_Model_Session')->getMessages(false)->getErrors());
+        /**
+         * Check that customer data were set to session
+         */
+        $this->assertEquals($post, Mage::getSingleton('Mage_Backend_Model_Session')->getCustomerData());
+        $this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl . 'edit/key'));
+    }
+
+    /**
+     * @magentoDbIsolation enabled
+     */
+    public function testSaveActionWithValidCustomerDataAndValidAddressData()
+    {
+        $post = array(
+            'account' => array(
+                'middlename' => 'test middlename',
+                'group_id' => 1,
+                'website_id' => 0,
+                'firstname' => 'test firstname',
+                'lastname' => 'test lastname',
+                'email' => 'exmaple@domain.com',
+                'default_billing' => '_item1',
+                'password' => 'auto'
+            ),
+            'address' => array('_item1' => array(
+                'firstname' => 'test firstname',
+                'lastname' => 'test lastname',
+                'street' => array(
+                    'test street'
+                ),
+                'city' => 'test city',
+                'country_id' => 'US',
+                'postcode' => '01001',
+                'telephone' => '+7000000001',
+            )),
+        );
+        $this->getRequest()->setPost($post);
+        $this->getRequest()->setParam('back', '1');
+        $this->dispatch('backend/admin/customer/save');
+        /**
+         * Check that errors was generated and set to session
+         */
+        $this->assertEmpty(Mage::getSingleton('Mage_Backend_Model_Session')->getMessages(false)->getErrors());
+        /**
+         * Check that customer data were set to session
+         */
+        $this->assertEmpty(Mage::getSingleton('Mage_Backend_Model_Session')->getCustomerData());
+
+        /**
+         * Check that success message is set
+         */
+        $this->assertCount(1,
+            Mage::getSingleton('Mage_Backend_Model_Session')
+                ->getMessages(false)->getItemsByType(Mage_Core_Model_Message::SUCCESS),
+            'Success message was not set'
+        );
+
+        /**
+         * Check that customer id set and addresses saved
+         */
+        $customer = Mage::registry('current_customer');
+        $this->assertInstanceOf('Mage_Customer_Model_Customer', $customer);
+        $this->assertCount(1, $customer->getAddressesCollection());
+
+        $this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl
+            . 'edit/id/' . $customer->getId() . '/back/1/key/')
+        );
+    }
+
+    /**
+     *
+     * @magentoDataFixture Mage/Adminhtml/controllers/_files/customer_sample.php
+     */
+    public function testSaveActionExistingCustomerAndExistingAddressData()
+    {
+        $post = array(
+            'account' => array(
+                'middlename' => 'test middlename',
+                'group_id' => 1,
+                'website_id' => 1,
+                'firstname' => 'test firstname',
+                'lastname' => 'test lastname',
+                'email' => 'exmaple@domain.com',
+                'default_shipping' => '_item1',
+                'new_password' => 'auto',
+                'sendemail_store_id' => '1',
+                'sendemail' => '1',
+
+            ),
+            'address' => array(
+                '1' => array(
+                    'firstname' => 'update firstname',
+                    'lastname' => 'update lastname',
+                    'street' => array('update street'),
+                    'city' => 'update city',
+                    'country_id' => 'US',
+                    'postcode' => '01001',
+                    'telephone' => '+7000000001',
+                ),
+                '_item1' => array(
+                    'firstname' => 'test firstname',
+                    'lastname' => 'test lastname',
+                    'street' => array('test street'),
+                    'city' => 'test city',
+                    'country_id' => 'US',
+                    'postcode' => '01001',
+                    'telephone' => '+7000000001',
+                ),
+                '_template_' => array(
+                    'firstname' => '',
+                    'lastname' => '',
+                    'street' => array(),
+                    'city' => '',
+                    'country_id' => 'US',
+                    'postcode' => '',
+                    'telephone' => '',
+                )
+            ),
+        );
+        $this->getRequest()->setPost($post);
+        $this->getRequest()->setParam('customer_id', 1);
+        $this->dispatch('backend/admin/customer/save');
+        /**
+         * Check that success message is set
+         */
+        $successMessages = Mage::getSingleton('Mage_Backend_Model_Session')
+            ->getMessages(false)->getItemsByType(Mage_Core_Model_Message::SUCCESS);
+        $this->assertEquals('The customer has been saved.', current($successMessages)->getCode());
+
+        /**
+         * Check that customer id set and addresses saved
+         */
+        $customer = Mage::registry('current_customer');
+        $this->assertInstanceOf('Mage_Customer_Model_Customer', $customer);
+
+        /**
+         * addressOne - updated
+         * addressTwo - removed
+         * addressThree - removed
+         * _item1 - new address
+         */
+        $this->assertCount(4, $customer->getAddressesCollection());
+
+        $savedCustomer = Mage::getModel('Mage_Customer_Model_Customer');
+        $savedCustomer->load($customer->getId());
+        /**
+         * addressOne - updated
+         * _item1 - new address
+         */
+        $this->assertCount(2, $savedCustomer->getAddressesCollection());
+
+        $this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl . 'index/key/'));
+    }
+
+    /**
+     *
+     * @magentoDataFixture Mage/Adminhtml/controllers/_files/customer_sample.php
+     */
+    public function testSaveActionCoreException()
+    {
+        $post = array(
+            'account' => array(
+                'middlename' => 'test middlename',
+                'group_id' => 1,
+                'website_id' => 1,
+                'firstname' => 'test firstname',
+                'lastname' => 'test lastname',
+                'email' => 'exmaple@domain.com',
+                'password' => 'auto',
+            ),
+        );
+        $this->getRequest()->setPost($post);
+        $this->dispatch('backend/admin/customer/save');
+        /*
+        * Check that error message is set
+        */
+        $errorMessages = Mage::getSingleton('Mage_Backend_Model_Session')
+            ->getMessages(false)->getErrors();
+        $this->assertEquals('This customer email already exists', current($errorMessages)->getCode());
+        $this->assertEquals($post, Mage::getSingleton('Mage_Backend_Model_Session')->getCustomerData());
+        $this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl . 'edit/key/'));
+    }
+}
diff --git a/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/_files/customer_sample.php b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/_files/customer_sample.php
new file mode 100644
index 0000000000000000000000000000000000000000..266615519d8e186238f9310ec3db189c5c16c49a
--- /dev/null
+++ b/dev/tests/integration/testsuite/Mage/Adminhtml/controllers/_files/customer_sample.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Magento
+ * @package     Mage_Adminhtml
+ * @subpackage  integration_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+/** @var Mage_Customer_Model_Customer $customer */
+$customer = Mage::getModel('Mage_Customer_Model_Customer');
+
+$customerData = array(
+    'group_id' => 1,
+    'website_id' => 1,
+    'firstname' => 'test firstname',
+    'lastname' => 'test lastname',
+    'email' => 'exmaple@domain.com',
+    'default_billing' => '_item1',
+    'password' => '123123q'
+ );
+$customer->setData($customerData);
+$customer->setId(1);
+
+/** @var Mage_Customer_Model_Address $addressOne  */
+$addressOne = Mage::getModel('Mage_Customer_Model_Address');
+$addressOneData = array(
+    'firstname' => 'test firstname',
+    'lastname' => 'test lastname',
+    'street' => array('test street'),
+    'city' => 'test city',
+    'country_id' => 'US',
+    'postcode' => '01001',
+    'telephone' => '+7000000001',
+    'entity_id' => 1
+);
+$addressOne->setData($addressOneData);
+$customer->addAddress($addressOne);
+
+/** @var Mage_Customer_Model_Address $addressTwo  */
+$addressTwo = Mage::getModel('Mage_Customer_Model_Address');
+$addressTwoData = array(
+    'firstname' => 'test firstname',
+    'lastname' => 'test lastname',
+    'street' => array('test street'),
+    'city' => 'test city',
+    'country_id' => 'US',
+    'postcode' => '01001',
+    'telephone' => '+7000000001',
+    'entity_id' => 2
+);
+$addressTwo->setData($addressTwoData);
+$customer->addAddress($addressTwo);
+
+/** @var Mage_Customer_Model_Address $addressThree  */
+$addressThree = Mage::getModel('Mage_Customer_Model_Address');
+$addressThreeData = array(
+    'firstname' => 'removed firstname',
+    'lastname' => 'removed lastname',
+    'street' => array('removed street'),
+    'city' => 'removed city',
+    'country_id' => 'US',
+    'postcode' => '01001',
+    'telephone' => '+7000000001',
+    'entity_id' => 3
+);
+$addressThree->setData($addressThreeData);
+$customer->addAddress($addressThree);
+
+$customer->save();
diff --git a/dev/tests/integration/testsuite/Mage/Backend/Controller/ActionAbstractTest.php b/dev/tests/integration/testsuite/Mage/Backend/Controller/ActionAbstractTest.php
index c335855a0cbff9314d9cfb49ab7c7651ee4b49f5..12524a5f12da63d692fbee1b89053f5b8ea47f78 100644
--- a/dev/tests/integration/testsuite/Mage/Backend/Controller/ActionAbstractTest.php
+++ b/dev/tests/integration/testsuite/Mage/Backend/Controller/ActionAbstractTest.php
@@ -67,4 +67,56 @@ class Mage_Backend_Controller_ActionAbstractTest extends Mage_Adminhtml_Utility_
         $expected = 'backend/admin/system_account/index';
         $this->assertRedirect($this->stringContains($expected));
     }
+
+    /**
+     * Check layout attribute "acl" for check access to
+     *
+     * @param string $blockName
+     * @param string $resource
+     * @param bool $isLimitedAccess
+     * @dataProvider nodesWithAcl
+     */
+    public function testAclInNodes($blockName, $resource, $isLimitedAccess)
+    {
+        /** @var $noticeInbox Mage_AdminNotification_Model_Inbox */
+        $noticeInbox = Mage::getModel('Mage_AdminNotification_Model_Inbox');
+        if (!$noticeInbox->loadLatestNotice()->getId()) {
+            $noticeInbox->addCritical('Test notice', 'Test description');
+        }
+
+        $this->_auth->login(Magento_Test_Bootstrap::ADMIN_NAME, Magento_Test_Bootstrap::ADMIN_PASSWORD);
+
+        /** @var $acl Magento_Acl */
+        $acl = Mage::getSingleton('Mage_Core_Model_Acl_Builder')->getAcl();
+        if ($isLimitedAccess) {
+            $acl->deny(null, $resource);
+        }
+
+        $this->dispatch('backend/admin/dashboard');
+
+        $layout = Mage::app()->getLayout();
+        $actualBlocks = $layout->getAllBlocks();
+
+        $this->assertNotEmpty($actualBlocks);
+        if ($isLimitedAccess) {
+            $this->assertNotContains($blockName, array_keys($actualBlocks));
+        } else {
+            $this->assertContains($blockName, array_keys($actualBlocks));
+        }
+    }
+
+    /**
+     * Data provider with expected blocks with acl properties
+     *
+     * @return array
+     */
+    public function nodesWithAcl()
+    {
+        return array(
+            array('notification_toolbar', 'Mage_AdminNotification::show_toolbar', true),
+            array('notification_window', 'Mage_AdminNotification::show_toolbar', true),
+            array('notification_toolbar', 'Mage_AdminNotification::show_toolbar', false),
+            array('notification_window', 'Mage_AdminNotification::show_toolbar', false),
+        );
+    }
 }
diff --git a/dev/tests/integration/testsuite/Mage/Backend/Model/MenuTest.php b/dev/tests/integration/testsuite/Mage/Backend/Model/MenuTest.php
index 9e7c41b4cc426188d1388b12af640aea8e521fda..144d2fba09054dd253efc4a7647c5303e0a636a6 100644
--- a/dev/tests/integration/testsuite/Mage/Backend/Model/MenuTest.php
+++ b/dev/tests/integration/testsuite/Mage/Backend/Model/MenuTest.php
@@ -40,6 +40,7 @@ class Mage_Backend_Model_MenuTest extends PHPUnit_Framework_TestCase
     public function setUp()
     {
         $this->_model = new Mage_Backend_Model_Auth();
+        Mage::getConfig()->setCurrentAreaCode(Mage::helper('Mage_Backend_Helper_Data')->getAreaCode());
     }
 
     protected function tearDown()
diff --git a/dev/tests/integration/testsuite/Mage/Cms/Model/Wysiwyg/ConfigTest.php b/dev/tests/integration/testsuite/Mage/Cms/Model/Wysiwyg/ConfigTest.php
index 9f14a2f70f4fd44daa40e6fe435b9ffc73b17e02..bbf7849049671c765dd3b91ae8579c1c572d02ed 100644
--- a/dev/tests/integration/testsuite/Mage/Cms/Model/Wysiwyg/ConfigTest.php
+++ b/dev/tests/integration/testsuite/Mage/Cms/Model/Wysiwyg/ConfigTest.php
@@ -34,6 +34,7 @@ class Mage_Cms_Model_Wysiwyg_ConfigTest extends PHPUnit_Framework_TestCase
 
     protected function setUp()
     {
+        Mage::getConfig()->setCurrentAreaCode(Mage::helper('Mage_Backend_Helper_Data')->getAreaCode());
         $this->_model = new Mage_Cms_Model_Wysiwyg_Config;
     }
 
diff --git a/dev/tests/integration/testsuite/Mage/Core/Controller/Varien/ActionTest.php b/dev/tests/integration/testsuite/Mage/Core/Controller/Varien/ActionTest.php
index f928ba72c00602e11ed856547cc1e1f5fc6fe8cf..e6807dacdb94468319af45ef026bb5b7702b6fe5 100644
--- a/dev/tests/integration/testsuite/Mage/Core/Controller/Varien/ActionTest.php
+++ b/dev/tests/integration/testsuite/Mage/Core/Controller/Varien/ActionTest.php
@@ -277,6 +277,7 @@ class Mage_Core_Controller_Varien_ActionTest extends PHPUnit_Framework_TestCase
      */
     public function testPreDispatch($controllerClass, $expectedArea, $expectedStore, $expectedDesign)
     {
+        Mage::getConfig()->setCurrentAreaCode($expectedArea);
         /** @var $controller Mage_Core_Controller_Varien_Action */
         $controller = new $controllerClass(new Magento_Test_Request(), new Magento_Test_Response());
         $controller->preDispatch();
diff --git a/dev/tests/integration/testsuite/Mage/Core/Model/LayoutTest.php b/dev/tests/integration/testsuite/Mage/Core/Model/LayoutTest.php
index 4dd9d8f2abb093b05ae8b38832db26a51965c447..85c3a5bb3575187be2e8a6a063acea0d3e0e128f 100644
--- a/dev/tests/integration/testsuite/Mage/Core/Model/LayoutTest.php
+++ b/dev/tests/integration/testsuite/Mage/Core/Model/LayoutTest.php
@@ -25,6 +25,15 @@
  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  */
 
+/**
+ * Layout integration tests
+ *
+ * 'ExcessivePublicCount' rule intersects with the 'TooManyFields' and 'TooManyMethods'.
+ * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
+ * @SuppressWarnings(PHPMD.ExcessivePublicCount)
+ * @SuppressWarnings(PHPMD.TooManyFields)
+ * @SuppressWarnings(PHPMD.TooManyMethods)
+ */
 class Mage_Core_Model_LayoutTest extends PHPUnit_Framework_TestCase
 {
     /**
@@ -117,7 +126,7 @@ class Mage_Core_Model_LayoutTest extends PHPUnit_Framework_TestCase
      * @covers Mage_Core_Model_Layout::generateBlocks
      * @covers Mage_Core_Model_Layout::getBlock
      */
-    public function testGenerateXmlAndBlocks()
+    public function testGenerateXmlAndElements()
     {
         $this->_layout->generateXml();
         /* Generate fixture
@@ -156,6 +165,97 @@ class Mage_Core_Model_LayoutTest extends PHPUnit_Framework_TestCase
         /** @var $block Mage_Core_Block_Template */
         $block = $this->_layout->getBlock('root');
         $this->assertEquals('popup.phtml', $block->getTemplate());
+
+        $this->assertFalse($this->_layout->getBlock('test.nonexisting.block'));
+    }
+
+    public function testLayoutMoveDirective()
+    {
+        $layout = new Mage_Core_Model_Layout();
+        $layout->getUpdate()->load(array('layout_test_handle_move'));
+        $layout->generateXml()->generateElements();
+        $this->assertEquals('container2', $layout->getParentName('container1'));
+        $this->assertEquals('container1', $layout->getParentName('no.name2'));
+        $this->assertEquals('block_container', $layout->getParentName('no_name3'));
+
+        // verify `after` attribute
+        $this->assertEquals('block_container', $layout->getParentName('no_name'));
+        $childrenOrderArray = array_keys($layout->getChildBlocks($layout->getParentName('no_name')));
+        $positionAfter = array_search('child_block1', $childrenOrderArray);
+        $positionToVerify = array_search('no_name', $childrenOrderArray);
+        $this->assertEquals($positionAfter, --$positionToVerify);
+
+        // verify `before` attribute
+        $this->assertEquals('block_container', $layout->getParentName('no_name4'));
+        $childrenOrderArray = array_keys($layout->getChildBlocks($layout->getParentName('no_name4')));
+        $positionBefore = array_search('child_block2', $childrenOrderArray);
+        $positionToVerify = array_search('no_name4', $childrenOrderArray);
+        $this->assertEquals($positionBefore, ++$positionToVerify);
+    }
+
+    /**
+     * @expectedException Magento_Exception
+     */
+    public function testLayoutMoveDirectiveBroken()
+    {
+        $layout = new Mage_Core_Model_Layout();
+        $layout->getUpdate()->load(array('layout_test_handle_move_broken'));
+        $layout->generateXml()->generateElements();
+    }
+
+    /**
+     * @expectedException Magento_Exception
+     */
+    public function testLayoutMoveAliasBroken()
+    {
+        $layout = new Mage_Core_Model_Layout();
+        $layout->getUpdate()->load(array('layout_test_handle_move_alias_broken'));
+        $layout->generateXml()->generateElements();
+    }
+
+    public function testLayoutMoveSameAlias()
+    {
+        $layout = new Mage_Core_Model_Layout();
+        $layout->getUpdate()->load(array('layout_test_handle_move_the_same_alias'));
+        $layout->generateXml()->generateElements();
+        $this->assertEquals('container1', $layout->getParentName('no_name3'));
+    }
+
+    public function testLayoutMoveNewAlias()
+    {
+        $layout = new Mage_Core_Model_Layout();
+        $layout->getUpdate()->load(array('layout_test_handle_move_new_alias'));
+        $layout->generateXml()->generateElements();
+        $this->assertEquals('new_alias', $layout->getElementAlias('no_name3'));
+    }
+
+    public function testLayoutActionForAnonymousParent()
+    {
+        $layout = new Mage_Core_Model_Layout();
+        $layout->getUpdate()->load(array('layout_test_handle_action_for_anonymous_parent_block'));
+        $layout->generateXml()->generateElements();
+        $this->assertEquals('ANONYMOUS_0', $layout->getParentName('test.block.insert'));
+        $this->assertEquals('ANONYMOUS_1', $layout->getParentName('test.block.append'));
+    }
+
+    public function testLayoutRemoveDirective()
+    {
+        $layout = new Mage_Core_Model_Layout();
+        $layout->getUpdate()->load(array('layout_test_handle_remove'));
+        $layout->generateXml()->generateElements();
+        $this->assertFalse($layout->getBlock('no_name2'));
+        $this->assertFalse($layout->getBlock('child_block1'));
+        $this->assertTrue($layout->isBlock('child_block2'));
+    }
+
+    /**
+     * @expectedException Magento_Exception
+     */
+    public function testGenerateElementsBroken()
+    {
+        $layout = new Mage_Core_Model_Layout();
+        $layout->getUpdate()->load('layout_test_handle_remove_broken');
+        $layout->generateXml()->generateElements();
     }
 
     public function testRenderElement()
diff --git a/dev/tests/integration/testsuite/Mage/Core/Model/_files/_layout_update.xml b/dev/tests/integration/testsuite/Mage/Core/Model/_files/_layout_update.xml
index f21276ffb0ebf668c1111c1ec6cc3c506b6e2a19..2f3d290573009502f6e459eb066593627cc65de1 100644
--- a/dev/tests/integration/testsuite/Mage/Core/Model/_files/_layout_update.xml
+++ b/dev/tests/integration/testsuite/Mage/Core/Model/_files/_layout_update.xml
@@ -43,8 +43,8 @@
          </action>
          <block type="Mage_Core_Block_Html_Calendar" name="head.calendar" as="calendar" template="page/js/calendar.phtml"/>
       </block>
-      <block type="Mage_Adminhtml_Block_Page_Header" name="header" as="header" ignore="1"/>
-      <block type="Mage_Backend_Block_Menu" name="menu" as="menu" ignore="1"/>
+      <block type="Mage_Adminhtml_Block_Page_Header" name="header" as="header"/>
+      <block type="Mage_Backend_Block_Menu" name="menu" as="menu"/>
       <block type="Mage_Core_Block_Text_List" name="notifications" as="notifications">
          <block type="Mage_Adminhtml_Block_Notification_Baseurl" name="notification_baseurl" as="notification_baseurl" template="notification/baseurl.phtml"/>
          <block type="Mage_Adminhtml_Block_Cache_Notifications" name="cache_notifications" template="system/cache/notifications.phtml"/>
@@ -53,8 +53,6 @@
       </block>
       <block type="Mage_Core_Block_Messages" name="messages" as="messages"/>
       <block type="Mage_Core_Block_Text" as="no_name"/>
-       <action method="insert" ignore="1"><element>some_element_1</element></action>
-       <action method="append" ignore="1"><element>some_element_2</element></action>
    </block>
    <update handle="layout_test_handle_sample"/>
    <remove name="header"/>
@@ -66,7 +64,12 @@
          <template>popup.phtml</template>
       </action>
    </reference>
-    <reference name="some_element_1" ignore="1"/>
+    <reference name="some_element_1"/>
+    <block name="test.nonexisting.block" type="Mage_Core_Block_Text_List"/>
+    <remove name="test.nonexisting.block"/>
+    <reference name="test.nonexisting.block">
+        <action method="getSomething"/>
+    </reference>
     <reference name="notifications">
        <block type="Mage_Index_Block_Adminhtml_Notifications" name="index_notifications" template="index/notifications.phtml" before="-"/>
        <block class="Mage_Index_Block_Adminhtml_Notifications" name="index_notifications_copy" template="index/notifications.phtml" after="-"/>
diff --git a/dev/tests/integration/testsuite/Mage/Core/Model/_files/design/frontend/test/default/Mage_Core/layout.xml b/dev/tests/integration/testsuite/Mage/Core/Model/_files/design/frontend/test/default/Mage_Core/layout.xml
index a09588ee4dd13aff5afe63610db7cfdc0010f05e..d5292ffe2c5c3396cbf11b34124a89ce9d22f439 100644
--- a/dev/tests/integration/testsuite/Mage/Core/Model/_files/design/frontend/test/default/Mage_Core/layout.xml
+++ b/dev/tests/integration/testsuite/Mage/Core/Model/_files/design/frontend/test/default/Mage_Core/layout.xml
@@ -49,8 +49,6 @@
 
             <block type="Mage_Core_Block_Messages" name="messages" as="messages"/>
             <block type="Mage_Core_Block_Text" as="no_name"/>
-            <action method="insert"><element>some_element_1</element></action>
-            <action method="append"><element>some_element_2</element></action>
         </block>
     </layout_test_handle_sample>
 
@@ -64,6 +62,101 @@
             <action method="setTemplate"><template>popup.phtml</template></action>
         </reference>
         <reference name="some_element_1"/>
+        <block name="test.nonexisting.block" type="Mage_Core_Block_Text_List"/>
+        <remove name="test.nonexisting.block"/>
+        <reference name="test.nonexisting.block">
+            <action method="getSomething"/>
+        </reference>
     </layout_test_handle_main>
 
+    <layout_test_handle_move>
+        <container name="container1" label="Container 1">
+            <block type="Mage_Core_Block_Text" name="no.name2" as="no.name2"/>
+        </container>
+        <container name="container2" label="Container 2"/>
+        <move element="container1" destination="container2"/>
+
+        <block type="Mage_Core_Block_Text" name="block_container" as="block.container">
+            <block type="Mage_Core_Block_Text" name="child_block1"/>
+            <block type="Mage_Core_Block_Text" name="child_block2"/>
+        </block>
+
+        <container name="container3" label="Container 3">
+            <block type="Mage_Core_Block_Text" name="no_name"/>
+        </container>
+        <move element="no_name" destination="block_container" after="child_block1"/>
+
+        <block type="Mage_Core_Block_Text" name="no_name4"/>
+        <move element="no_name4" destination="block_container" before="child_block2"/>
+
+        <move element="no_name3" destination="block_container"/>
+        <block type="Mage_Core_Block_Text" name="no_name3"/>
+    </layout_test_handle_move>
+
+    <layout_test_handle_move_broken>
+        <container name="container1" label="Container 1"/>
+        <move element="no_name3"/>
+        <block type="Mage_Core_Block_Text" name="no_name3"/>
+    </layout_test_handle_move_broken>
+
+    <layout_test_handle_move_alias_broken>
+        <container name="container1" label="Container 1">
+            <block type="Mage_Core_Block_Text" name="no_name1" as="same_alias"/>
+        </container>
+        <move element="no_name3" destination="container1" as="same_alias"/>
+        <block type="Mage_Core_Block_Text" name="no_name3" as="same_alias"/>
+    </layout_test_handle_move_alias_broken>
+
+    <layout_test_handle_move_the_same_alias>
+        <container name="container1" label="Container 1">
+            <block type="Mage_Core_Block_Text" name="no_name1" as="same_alias"/>
+        </container>
+        <move element="no_name3" destination="container1"/>
+        <block type="Mage_Core_Block_Text" name="no_name3" as="same_alias"/>
+    </layout_test_handle_move_the_same_alias>
+
+    <layout_test_handle_move_new_alias>
+        <container name="container1" label="Container 1">
+            <block type="Mage_Core_Block_Text" name="no_name1" as="same_alias"/>
+        </container>
+        <move element="no_name3" destination="container1" as="new_alias"/>
+        <block type="Mage_Core_Block_Text" name="no_name3" as="same_alias"/>
+    </layout_test_handle_move_new_alias>
+
+    <layout_test_handle_remove>
+        <container name="container1" label="Container 1">
+            <block type="Mage_Core_Block_Text" name="no_name2"/>
+        </container>
+        <remove name="container1"/>
+
+        <remove name="child_block1"/>
+        <block type="Mage_Core_Block_Text" name="block_container" as="block.container">
+            <block type="Mage_Core_Block_Text" name="child_block1"/>
+            <block type="Mage_Core_Block_Text" name="child_block2"/>
+        </block>
+        <remove name="not_exist"/>
+    </layout_test_handle_remove>
+
+    <layout_test_handle_remove_broken>
+        <block name="test.broken.block" type="Mage_Core_Block_Text"/>
+        <remove name="test.broken.block"/>
+        <block type="Mage_Core_Block_Template" name="bug.without.name.action.is.ignored">
+            <action method="insert"><element>test.broken.block</element></action>
+            <action method="append"><element>test.broken.block</element></action>
+        </block>
+    </layout_test_handle_remove_broken>
+
+
+    <layout_test_handle_action_for_anonymous_parent_block>
+        <block name="test.block.insert" type="Mage_Core_Block_Text"/>
+
+        <block type="Mage_Core_Block_Template">
+            <action method="insert"><element>test.block.insert</element></action>
+        </block>
+
+        <block name="test.block.append" type="Mage_Core_Block_Text"/>
+        <block type="Mage_Core_Block_Text">
+            <action method="append"><element>test.block.append</element></action>
+        </block>
+    </layout_test_handle_action_for_anonymous_parent_block>
 </layout>
diff --git a/dev/tests/integration/testsuite/Mage/User/Block/Role/Tab/EditTest.php b/dev/tests/integration/testsuite/Mage/User/Block/Role/Tab/EditTest.php
index 6c0f88a96bc56061c413ec32601aef70af5a2afc..8ecfb9a68cdbbe1ecaeb0b6b07b3e3b67f5a242d 100644
--- a/dev/tests/integration/testsuite/Mage/User/Block/Role/Tab/EditTest.php
+++ b/dev/tests/integration/testsuite/Mage/User/Block/Role/Tab/EditTest.php
@@ -43,9 +43,8 @@ class Mage_User_Block_Role_Tab_EditTest extends PHPUnit_Framework_TestCase
 
         $aclMock = $this->getMock('Magento_Acl');
         $aclMock->expects($this->any())->method('has')->will($this->returnValue(true));
-        Mage::getSingleton('Mage_Backend_Model_Auth_Session')->setAcl($aclMock);
 
-        $this->_block = new Mage_User_Block_Role_Tab_Edit();
+        $this->_block = new Mage_User_Block_Role_Tab_Edit(array('acl' => $aclMock));
     }
 
     protected function tearDown()
diff --git a/dev/tests/integration/testsuite/integrity/modular/AclConfigFilesTest.php b/dev/tests/integration/testsuite/integrity/modular/AclConfigFilesTest.php
index b100d93180aed38ce397bbdf3a26d46591b19889..ac4946e563c0aae1ef14c24eb94a84f8115dc220 100644
--- a/dev/tests/integration/testsuite/integrity/modular/AclConfigFilesTest.php
+++ b/dev/tests/integration/testsuite/integrity/modular/AclConfigFilesTest.php
@@ -43,7 +43,7 @@ class Integrity_Modular_AclConfigFilesTest extends PHPUnit_Framework_TestCase
 
     public function setUp()
     {
-        $readerMock = $this->getMock('Mage_Backend_Model_Acl_Config_Reader', array('getShemaFile'), array(), '', false);
+        $readerMock = $this->getMock('Magento_Acl_Config_Reader', array('getShemaFile'), array(), '', false);
         $this->_schemeFile = $readerMock->getSchemaFile();
         $this->_prepareFileList();
     }
@@ -94,10 +94,10 @@ class Integrity_Modular_AclConfigFilesTest extends PHPUnit_Framework_TestCase
      */
     public function testMergedConfiguration()
     {
-        /** @var $dom DOMDocument **/
-        $dom = Mage::getModel('Mage_Backend_Model_Acl_Config_Reader', $this->_fileList)->getAclResources();
+        /** @var $dom Magento_Acl_Config_Reader **/
+        $dom = Mage::getModel('Magento_Acl_Config_Reader', $this->_fileList)->getAclResources();
 
-        $domConfig = new Mage_Backend_Model_Acl_Config_Reader_Dom($dom->saveXML());
+        $domConfig = new Magento_Acl_Config_Reader_Dom($dom->saveXML());
         $errors = array();
         $result = $domConfig->validate($this->_schemeFile, $errors);
         $message = "Invalid merged ACL config\n";
diff --git a/dev/tests/integration/testsuite/integrity/modular/TemplateFilesTest.php b/dev/tests/integration/testsuite/integrity/modular/TemplateFilesTest.php
index 53b8e0cc4571f48428cf25ec83b43965ed96d891..2302645ba84dfdc48bb36c3c1cdcf8016eb70dbe 100644
--- a/dev/tests/integration/testsuite/integrity/modular/TemplateFilesTest.php
+++ b/dev/tests/integration/testsuite/integrity/modular/TemplateFilesTest.php
@@ -63,20 +63,46 @@ class Integrity_Modular_TemplateFilesTest extends Magento_Test_TestCase_Integrit
             if ($class->isAbstract() || !$class->isSubclassOf('Mage_Core_Block_Template')) {
                 continue;
             }
+
+            $area = 'frontend';
+            if ($module == 'Mage_Install') {
+                $area = 'install';
+            } elseif ($module == 'Mage_Adminhtml' || strpos($blockClass, '_Adminhtml_')
+                || strpos($blockClass, '_Backend_')
+                || ($this->_isClassInstanceOf($blockClass, 'Mage_Backend_Block_Template'))
+            ) {
+                $area = 'adminhtml';
+            }
+
+            Mage::getConfig()->setCurrentAreaCode($area);
+
             $block = new $blockClass;
             $template = $block->getTemplate();
             if ($template) {
-                $area = 'frontend';
-                if ($module == 'Mage_Install') {
-                    $area = 'install';
-                } elseif ($module == 'Mage_Adminhtml' || strpos($blockClass, '_Adminhtml_')
-                    || strpos($blockClass, '_Backend_') || ($block instanceof Mage_Backend_Block_Template)
-                ) {
-                    $area = 'adminhtml';
-                }
                 $templates[] = array($module, $template, $blockClass, $area);
             }
         }
         return $templates;
     }
+
+    /**
+     * @param string $blockClass
+     * @param string $parentClass
+     * @return bool
+     */
+    protected function _isClassInstanceOf($blockClass, $parentClass)
+    {
+        $currentClass = new ReflectionClass($blockClass);
+        $supertypes = array();
+        do {
+            $supertypes = array_merge($supertypes, $currentClass->getInterfaceNames());
+            if (!($currentParent = $currentClass->getParentClass())) {
+                break;
+            }
+            $supertypes[] = $currentParent->getName();
+            $currentClass = $currentParent;
+        } while (true);
+
+        return in_array($parentClass, $supertypes);
+    }
 }
diff --git a/dev/tests/static/testsuite/Legacy/ObsoleteCodeTest.php b/dev/tests/static/testsuite/Legacy/ObsoleteCodeTest.php
index 6e899a5a47a4fbe9119305329d843cfaf5bcc500..546d2abade14f2381e65d1cdee01f00a96fe44ff 100644
--- a/dev/tests/static/testsuite/Legacy/ObsoleteCodeTest.php
+++ b/dev/tests/static/testsuite/Legacy/ObsoleteCodeTest.php
@@ -149,13 +149,19 @@ class Legacy_ObsoleteCodeTest extends PHPUnit_Framework_TestCase
             . ' must be invoked with menu item identifier than xpath for menu item'
         );
 
+        $this->assertEquals(0,
+            preg_match('#Mage::getSingleton\([\'"]Mage_Backend_Model_Auth_Session[\'"]\)'
+                . '([\s]+)?->isAllowed\(#Ui', $content),
+            'Backwards-incompatible change: method isAllowed()'
+                . ' must be invoked from Mage::getSingleton(\'Mage_Code_Model_Authorization\')->isAllowed($resource)'
+        );
+
         $this->_assertNotRegExp(
-            '#Mage::getSingleton\([\'"]Mage_Backend_Model_Auth_Session[\'"]\)'
+            '#Mage::getSingleton\([\'"]Mage_Core_Model_Authorization[\'"]\)'
                 . '([\s]+)?->isAllowed\([\'"]([\w\d/_]+)[\'"]\)#Ui',
             $content,
             'Backwards-incompatible change: method isAllowed()'
-                . ' must be invoked with acl item identifier than xpath for acl item'
-        );
+                . ' must be invoked with acl item identifier than xpath for acl item');
     }
 
     /**
diff --git a/dev/tests/static/testsuite/Php/_files/blacklist/core.txt b/dev/tests/static/testsuite/Php/_files/blacklist/core.txt
index 2a3cb1ad4d1548ab3a7780e37467c7f873e73c58..ca73d72383ebd558e4ce76b94489aa44cb25eb37 100644
--- a/dev/tests/static/testsuite/Php/_files/blacklist/core.txt
+++ b/dev/tests/static/testsuite/Php/_files/blacklist/core.txt
@@ -7,3 +7,4 @@ dev/tests/integration/testsuite/Mage/Core/Block/_files
 dev/tests/integration/tmp
 dev/tests/static/testsuite/Php/Exemplar/_files/phpcs/input
 dev/tests/static/testsuite/Php/Exemplar/_files/phpmd/input
+dev/tools/translate
diff --git a/dev/tests/static/testsuite/Php/_files/whitelist/core.txt b/dev/tests/static/testsuite/Php/_files/whitelist/core.txt
index 0e0e67cd8d6465d018af757c2e2a641c48ebd5fa..852e4d30ddfe477c324b77fb2937f8edc5617de3 100644
--- a/dev/tests/static/testsuite/Php/_files/whitelist/core.txt
+++ b/dev/tests/static/testsuite/Php/_files/whitelist/core.txt
@@ -8,6 +8,7 @@ app/code/core/Mage/Adminhtml/Block/Page/System/Config/Robots/Reset.php
 app/code/core/Mage/Adminhtml/Block/System/Store/Edit
 app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php
 app/code/core/Mage/Core/Block/Abstract.php
+app/code/core/Mage/Centinel/Model/State/Jcb.php
 app/code/core/Mage/Core/Model/Config/Module.php
 app/code/core/Mage/Core/Model/Design.php
 app/code/core/Mage/Core/Model/ShellAbstract.php
diff --git a/dev/tests/unit/framework/bootstrap.php b/dev/tests/unit/framework/bootstrap.php
index b3cc2cca8d890fe48ad122367e82b6004681990e..f5feb1f5a8d5d6e6b0f2606ac6c410df77b5f8d4 100755
--- a/dev/tests/unit/framework/bootstrap.php
+++ b/dev/tests/unit/framework/bootstrap.php
@@ -27,12 +27,12 @@
 define('TESTS_TEMP_DIR', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'tmp');
 
 $includePaths = array(
-    get_include_path(),
     "./framework",
     './testsuite',
     '../../../lib',
     '../../../app/code/core',
-    '../../../app/'
+    '../../../app/',
+    get_include_path()
 );
 set_include_path(implode(PATH_SEPARATOR, $includePaths));
 spl_autoload_register('magentoAutoloadForUnitTests');
diff --git a/dev/tests/unit/testsuite/Mage/Backend/Model/Acl/ConfigTest.php b/dev/tests/unit/testsuite/Mage/Backend/Model/Acl/ConfigTest.php
index 89cacc8f923ff5aa95c8e3c3013b51a2fdb6f180..a23e5b87f7babc66a390f1c5d3fe192496bf7b4d 100644
--- a/dev/tests/unit/testsuite/Mage/Backend/Model/Acl/ConfigTest.php
+++ b/dev/tests/unit/testsuite/Mage/Backend/Model/Acl/ConfigTest.php
@@ -49,7 +49,7 @@ class Mage_Backend_Model_Acl_ConfigTest extends PHPUnit_Framework_TestCase
 
     public function setUp()
     {
-        $this->_readerMock = $this->getMock('Mage_Backend_Model_Acl_Config_Reader', array(), array(), '', false);
+        $this->_readerMock = $this->getMock('Magento_Acl_Config_Reader', array(), array(), '', false);
         $this->_configMock = $this->getMock('Mage_Core_Model_Config', array(), array(), '', false);
         $this->_cacheMock  = $this->getMock('Mage_Core_Model_Cache', array(), array(), '', false);
 
@@ -65,7 +65,7 @@ class Mage_Backend_Model_Acl_ConfigTest extends PHPUnit_Framework_TestCase
         $originalAclResources->loadXML('<?xml version="1.0" encoding="utf-8"?><config><acl></acl></config>');
 
         $this->_configMock->expects($this->once())->method('getModelInstance')
-            ->with($this->equalTo('Mage_Backend_Model_Acl_Config_Reader'))
+            ->with($this->equalTo('Magento_Acl_Config_Reader'))
             ->will($this->returnValue($this->_readerMock));
 
         $this->_cacheMock->expects($this->exactly(2))->method('canUse')
@@ -99,7 +99,7 @@ class Mage_Backend_Model_Acl_ConfigTest extends PHPUnit_Framework_TestCase
         );
 
         $this->_configMock->expects($this->once())->method('getModelInstance')
-            ->with($this->equalTo('Mage_Backend_Model_Acl_Config_Reader'))
+            ->with($this->equalTo('Magento_Acl_Config_Reader'))
             ->will($this->returnValue($this->_readerMock));
 
         $this->_cacheMock->expects($this->exactly(2))->method('canUse')
@@ -151,7 +151,7 @@ class Mage_Backend_Model_Acl_ConfigTest extends PHPUnit_Framework_TestCase
         $aclResources->loadXML('<?xml version="1.0" encoding="utf-8"?><config><acl></acl></config>');
 
         $this->_configMock->expects($this->once())->method('getModelInstance')
-            ->with($this->equalTo('Mage_Backend_Model_Acl_Config_Reader'))
+            ->with($this->equalTo('Magento_Acl_Config_Reader'))
             ->will($this->returnValue($this->_readerMock));
 
         $this->_cacheMock->expects($this->exactly(4))->method('canUse')
diff --git a/dev/tests/unit/testsuite/Mage/Backend/Model/Authorization/RoleLocatorTest.php b/dev/tests/unit/testsuite/Mage/Backend/Model/Authorization/RoleLocatorTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..46ad67bd4c84fc8c81c068d7ffa3c07a0c7ce1f7
--- /dev/null
+++ b/dev/tests/unit/testsuite/Mage/Backend/Model/Authorization/RoleLocatorTest.php
@@ -0,0 +1,59 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Magento
+ * @package     Mage_Backend
+ * @subpackage  unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+class Mage_Backend_Model_Authorization_RoleLocatorTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Mage_Backend_Model_Authorization_RoleLocator
+     */
+    protected $_model;
+
+    /**
+     * @var PHPUnit_Framework_MockObject_MockObject
+     */
+    protected $_sessionMock = array();
+
+    public function setUp()
+    {
+        $this->_sessionMock = $this->getMock(
+            'Mage_Backend_Model_Auth_Session',
+            array('getUser', 'getAclRole', 'hasUser'),
+            array(),
+            '',
+            false
+        );
+        $this->_model = new Mage_Backend_Model_Authorization_RoleLocator(array('session' => $this->_sessionMock));
+    }
+
+    public function testGetAclRoleIdReturnsCurrentUserAclRoleId()
+    {
+        $this->_sessionMock->expects($this->once())->method('hasUser')->will($this->returnValue(true));
+        $this->_sessionMock->expects($this->once())->method('getUser')->will($this->returnSelf());
+        $this->_sessionMock->expects($this->once())->method('getAclRole')->will($this->returnValue('some_role'));
+        $this->assertEquals('some_role', $this->_model->getAclRoleId());
+    }
+}
diff --git a/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/Item/FactoryTest.php b/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/Item/FactoryTest.php
index 4ade3bb6a43b7e330b95682ad58b88912ee70475..90bbef621aa9d1376bf4969df788d4989b6fa0d6 100644
--- a/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/Item/FactoryTest.php
+++ b/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/Item/FactoryTest.php
@@ -81,7 +81,7 @@ class Mage_Backend_Model_Menu_Item_FactoryTest extends PHPUnit_Framework_TestCas
 
     public function setUp()
     {
-        $this->_aclMock = $this->getMock('Mage_Backend_Model_Auth_Session', array(), array(), '', false);
+        $this->_aclMock = $this->getMock('Mage_Core_Model_Authorization', array(), array(), '', false);
         $this->_objectFactoryMock = $this->getMock('Mage_Core_Model_Config', array(), array(), '', false);
         $this->_factoryMock = $this->getMock('Mage_Backend_Model_Menu_Factory');
         $this->_helpers = array(
diff --git a/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/Item/ValidatorTest.php b/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/Item/ValidatorTest.php
index a6161eae8f2c28230e6541f463ff28dfd7553ebf..03928481dbf348e96b43ff6405a11947c42380fc 100644
--- a/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/Item/ValidatorTest.php
+++ b/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/Item/ValidatorTest.php
@@ -79,7 +79,7 @@ class Mage_Backend_Model_Menu_Item_ValidatorTest extends PHPUnit_Framework_TestC
 
     public function setUp()
     {
-        $this->_aclMock = $this->getMock('Mage_Backend_Model_Auth_Session', array(), array(), '', false);
+        $this->_aclMock = $this->getMock('Mage_Core_Model_Authorization', array(), array(), '', false);
         $this->_factoryMock = $this->getMock('Mage_Backend_Model_Menu_Factory');
         $this->_helperMock = $this->getMock('Mage_Backend_Helper_Data', array(), array(), '', false);
         $this->_urlModelMock = $this->getMock("Mage_Backend_Model_Url", array(), array(), '', false);
diff --git a/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/ItemTest.php b/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/ItemTest.php
index 59ff754e979249216d46e227fbdbd2e59a0314ed..13ac8c25cbeb88105172e687cb4ce1731e7458a4 100644
--- a/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/ItemTest.php
+++ b/dev/tests/unit/testsuite/Mage/Backend/Model/Menu/ItemTest.php
@@ -82,7 +82,7 @@ class Mage_Backend_Model_Menu_ItemTest extends PHPUnit_Framework_TestCase
 
     public function setUp()
     {
-        $this->_aclMock = $this->getMock('Mage_Backend_Model_Auth_Session', array(), array(), '', false);
+        $this->_aclMock = $this->getMock('Mage_Core_Model_Authorization', array(), array(), '', false);
         $this->_appConfigMock = $this->getMock('Mage_Core_Model_Config', array(), array(), '', false);
         $this->_storeConfigMock = $this->getMock('Mage_Core_Model_Store_Config');
         $this->_menuFactoryMock = $this->getMock('Mage_Backend_Model_Menu_Factory', array(), array(), '', false);
diff --git a/dev/tests/unit/testsuite/Mage/Backend/Model/UrlTest.php b/dev/tests/unit/testsuite/Mage/Backend/Model/UrlTest.php
index 8af8e1352c7a2ad09e5295835785bafe0d7a3cc1..ee0d43fbfdcf309a2ac5bd01d85c282dea4c3ba8 100644
--- a/dev/tests/unit/testsuite/Mage/Backend/Model/UrlTest.php
+++ b/dev/tests/unit/testsuite/Mage/Backend/Model/UrlTest.php
@@ -160,16 +160,6 @@ class Mage_Backend_Model_UrlTest extends PHPUnit_Framework_TestCase
 
     public function testGetStartupPageUrl()
     {
-        $mockSession = $this->getMock('Mage_Backend_Model_Auth_Session',
-            array('getUser', 'isAllowed'),
-            array(),
-            '',
-            false
-        );
-        $mockSession->expects($this->any())
-            ->method('isAllowed')
-            ->will($this->returnValue(true));
-        $this->_model->setSession($mockSession);
         $this->assertEquals('adminhtml/user_role', (string)$this->_model->getStartupPageUrl());
     }
 
diff --git a/dev/tests/unit/testsuite/Mage/Centinel/Model/State/JcbTest.php b/dev/tests/unit/testsuite/Mage/Centinel/Model/State/JcbTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..a6bc7e91c30e6be8f068c80c2e5fab82d83239ce
--- /dev/null
+++ b/dev/tests/unit/testsuite/Mage/Centinel/Model/State/JcbTest.php
@@ -0,0 +1,619 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Magento
+ * @package     Mage_Centinel
+ * @subpackage  unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+/**
+ * Test class for Mage_Centinel_Model_State_Jcb.
+ */
+class Mage_Centinel_Model_State_JcbTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * State model
+     *
+     * @var Mage_Centinel_Model_State_Jcb
+     */
+    protected $_model;
+
+    public function setUp()
+    {
+        $this->_model = new Mage_Centinel_Model_State_Jcb();
+        $this->_model->setDataStorage(new Varien_Object());
+    }
+
+    /**
+     * @param bool $result
+     * @param array $lookupResults
+     * @param array $params
+     * @dataProvider testIsAuthenticateAllowedDataProvider
+     */
+    public function testIsAuthenticateAllowed($result, $lookupResults, $params)
+    {
+        $this->_model->setLookupResult(new Varien_Object($lookupResults));
+        $this->_model->setAuthenticateResult(new Varien_Object($params));
+        $this->assertEquals($result, $this->_model->isAuthenticateAllowed());
+    }
+
+    public function testIsAuthenticateAllowedDataProvider()
+    {
+        return array(
+            'successful lookup and empty authentication' => array(
+                true,
+                array(
+                    'enrolled' => 'Y',
+                    'acs_url' => 'no empty value',
+                    'payload' => 'no empty value',
+                    'error_no' => '0'
+                ),
+                array()
+            ),
+            'wrong lookup and empty authentication' => array(
+                false,
+                array(),
+                array()
+            ),
+            'successful lookup and not empty authentication' => array(
+                false,
+                array(
+                    'enrolled' => 'Y',
+                    'acs_url' => 'no empty value',
+                    'payload' => 'no empty value',
+                    'error_no' => '0'
+                ),
+                array(
+                    'eci_flag' => 'value'
+                )
+            ),
+            'wrong lookup and not empty authentication' => array(
+                false,
+                array(),
+                array(
+                    'eci_flag' => 'value'
+                )
+            ),
+        );
+    }
+
+    public function testIsAuthenticateSuccessfulWithSoftLookup()
+    {
+        $lookupResults = array(
+            'enrolled' => '',
+            'acs_url' => '',
+            'payload' => '',
+            'error_no' => '0'
+        );
+        $this->_model->setLookupResult(new Varien_Object($lookupResults));
+
+        $this->_model->setIsModeStrict(true);
+        $this->assertEquals(false, $this->_model->isAuthenticateSuccessful());
+
+        $this->_model->setIsModeStrict(false);
+        $this->assertEquals(true, $this->_model->isAuthenticateSuccessful());
+    }
+
+    /**
+     * @param bool $result
+     * @param bool $strictMode
+     * @param array $params
+     * @dataProvider isAuthenticateSuccessfulDataProvider
+     */
+    public function testIsAuthenticateSuccessful($result, $strictMode, $params)
+    {
+        $this->_model->setIsModeStrict($strictMode);
+        $lookupResult = array(
+            'enrolled' => 'Y',
+            'acs_url' => 'no empty value',
+            'payload' => 'no empty value',
+            'error_no' => '0'
+        );
+        $this->_model->setLookupResult(new Varien_Object($lookupResult));
+        $this->_model->setAuthenticateResult(new Varien_Object($params));
+
+        $this->assertEquals($result, $this->_model->isAuthenticateSuccessful());
+    }
+
+    public function isAuthenticateSuccessfulDataProvider()
+    {
+        return array_merge(
+            $this->_getAuthenticationSuccessfulData(),
+            $this->_getAuthenticationUnavailableData(),
+            $this->_getProcessingAttemptsPerformedData(),
+            array(
+                'Centinel case 2' => array(
+                    false, true,
+                    array('pa_res_status' => 'Y', 'eci_flag' => '05', 'xid' => 'some string', 'cavv' => 'some string',
+                        'error_no' => '0', 'signature_verification' => 'N'
+                    )
+                ),
+                'Centinel case 3' => array(
+                    false, true,
+                    array('pa_res_status' => 'N', 'signature_verification' => 'Y', 'eci_flag' => '07',
+                        'xid' => 'some string', 'cavv' => '', 'error_no' => '0'
+                    )
+                ),
+                'Centinel case 10' => array(
+                    false, true,
+                    array('pa_res_status' => '', 'signature_verification' => '', 'eci_flag' => '07', 'xid' => '',
+                        'cavv' => '', 'error_no' => 'not zero'
+                    )
+                ),
+            )
+        );
+    }
+
+    /**
+     * Data for successful authentication
+     *
+     * @return array
+     */
+    protected function _getAuthenticationSuccessfulData()
+    {
+        return array(
+            'Centinel case 1' => array(
+                true, true,
+                array('pa_res_status' => 'Y', 'eci_flag' => '05', 'xid' => 'some string', 'cavv' => 'some string',
+                    'error_no' => '0', 'signature_verification' => 'Y'
+                )
+            ),
+            'Centinel case 1 pa_res_status is absent' => array(
+                false, true,
+                array('eci_flag' => '05', 'xid' => 'some string', 'cavv' => 'some string', 'error_no' => '0',
+                    'signature_verification' => 'Y'
+                )
+            ),
+            'Centinel case 1 eci_flag is absent' => array(
+                false, true,
+                array('pa_res_status' => 'Y', 'xid' => 'some string', 'cavv' => 'some string', 'error_no' => '0',
+                    'signature_verification' => 'Y'
+                )
+            ),
+            'Centinel case 1 xid is absent' => array(
+                false, true,
+                array('pa_res_status' => 'Y', 'eci_flag' => '05', 'cavv' => 'some string', 'error_no' => '0',
+                    'signature_verification' => 'Y'
+                )
+            ),
+            'Centinel case 1 cavv is absent' => array(
+                false, true,
+                array('pa_res_status' => 'Y', 'eci_flag' => '05', 'xid' => 'some string', 'error_no' => '0',
+                    'signature_verification' => 'Y'
+                )
+            ),
+            'Centinel case 1 error_no is absent' => array(
+                false, true,
+                array('pa_res_status' => 'Y', 'eci_flag' => '05', 'xid' => 'some string', 'cavv' => 'some string',
+                    'signature_verification' => 'Y'
+                )
+            ),
+            'Centinel case 1 signature_verification is absent' => array(
+                false, true,
+                array('pa_res_status' => 'Y', 'eci_flag' => '05', 'xid' => 'some string', 'cavv' => 'some string',
+                    'error_no' => '0',
+                )
+            ),
+            'Centinel case 1 wrong pa_res_status' => array(
+                false, true,
+                array('pa_res_status' => 'wrong value', 'eci_flag' => '05', 'xid' => 'some string',
+                    'cavv' => 'some string', 'error_no' => '0', 'signature_verification' => 'Y'
+                )
+            ),
+            'Centinel case 1 wrong eci_flag' => array(
+                false, true,
+                array('pa_res_status' => 'Y', 'eci_flag' => 'wrong value', 'xid' => 'some string',
+                    'cavv' => 'some string', 'error_no' => '0', 'signature_verification' => 'Y'
+                )
+            ),
+            'Centinel case 1 empty xid' => array(
+                false, true,
+                array('pa_res_status' => 'Y', 'eci_flag' => '05', 'xid' => '', 'cavv' => 'some string',
+                    'error_no' => '0', 'signature_verification' => 'Y'
+                )
+            ),
+            'Centinel case 1 empty cavv' => array(
+                false, true,
+                array('pa_res_status' => 'Y', 'eci_flag' => '05', 'xid' => 'some string', 'cavv' => '',
+                    'error_no' => '0', 'signature_verification' => 'Y'
+                )
+            ),
+            'Centinel case 1 no zero error_no' => array(
+                false, true,
+                array('pa_res_status' => 'Y', 'eci_flag' => '05', 'xid' => 'some string', 'cavv' => 'some string',
+                    'error_no' => 'no zero', 'signature_verification' => 'Y'
+                )
+            ),
+            'Centinel case 1 wrong signature_verification' => array(
+                false, true,
+                array('pa_res_status' => 'Y', 'eci_flag' => '05', 'xid' => 'some string', 'cavv' => 'some string',
+                    'error_no' => '0', 'signature_verification' => 'wrong value'
+                )
+            ),
+            'Centinel case 1 no params' => array(
+                false, true, array()
+            ),
+        );
+    }
+
+    /**
+     * Data for unavailable authentication
+     *
+     * @return array
+     */
+    protected function _getAuthenticationUnavailableData()
+    {
+        return array(
+            'Centinel case 4,5 in strict mode' => array(
+                false, true,
+                array('pa_res_status' => 'U', 'signature_verification' => 'Y', 'eci_flag' => '07',
+                    'xid' => 'some string', 'cavv' => '', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 4,5' => array(
+                true, false,
+                array('pa_res_status' => 'U', 'signature_verification' => 'Y', 'eci_flag' => '07',
+                    'xid' => 'some string', 'cavv' => '', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 4,5 pa_res_status is absent' => array(
+                false, false,
+                array('signature_verification' => 'Y', 'eci_flag' => '07', 'xid' => 'some string',
+                    'cavv' => '', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 4,5 signature_verification is absent' => array(
+                false, false,
+                array('pa_res_status' => 'U', 'eci_flag' => '07', 'xid' => 'some string', 'cavv' => '',
+                    'error_no' => '0'
+                )
+            ),
+            'Centinel case 4,5 eci_flag is absent' => array(
+                false, false,
+                array('pa_res_status' => 'U', 'signature_verification' => 'Y', 'xid' => 'some string',
+                    'cavv' => '', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 4,5 xid is absent' => array(
+                false, false,
+                array('pa_res_status' => 'U', 'signature_verification' => 'Y', 'eci_flag' => '07',
+                    'cavv' => '', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 4,5 cavv is absent' => array(
+                false, false,
+                array('pa_res_status' => 'U', 'signature_verification' => 'Y', 'eci_flag' => '07',
+                    'xid' => 'some string', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 4,5 error_no is absent' => array(
+                false, false,
+                array('pa_res_status' => 'U', 'signature_verification' => 'Y', 'eci_flag' => '07',
+                    'xid' => 'some string', 'cavv' => '',
+                )
+            ),
+            'Centinel case 4,5 wrong pa_res_status' => array(
+                false, false,
+                array('pa_res_status' => 'wrong value', 'signature_verification' => 'Y', 'eci_flag' => '07',
+                    'xid' => 'some string', 'cavv' => '', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 4,5 wrong signature_verification' => array(
+                false, false,
+                array('pa_res_status' => 'U', 'signature_verification' => 'wrong value', 'eci_flag' => '07',
+                    'xid' => 'some string', 'cavv' => '', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 4,5 wrong eci_flag' => array(
+                false, false,
+                array('pa_res_status' => 'U', 'signature_verification' => 'Y', 'eci_flag' => 'wrong value',
+                    'xid' => '', 'cavv' => '', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 4,5 empty xid' => array(
+                false, false,
+                array('pa_res_status' => 'U', 'signature_verification' => 'Y', 'eci_flag' => '07',
+                    'xid' => '', 'cavv' => '', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 4,5 not empty cavv' => array(
+                false, false,
+                array('pa_res_status' => 'U', 'signature_verification' => 'Y', 'eci_flag' => '07',
+                    'xid' => 'some string', 'cavv' => 'not empty', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 4,5 no zero error_no' => array(
+                false, false,
+                array('pa_res_status' => 'U', 'signature_verification' => 'Y', 'eci_flag' => '07',
+                    'xid' => 'some string', 'cavv' => '', 'error_no' => 'no zero'
+                )
+            ),
+            'Centinel case 4,5 no params' => array(
+                false, false, array()
+            ),
+        );
+    }
+
+    /**
+     * Data for attempts performed processing
+     *
+     * @return array
+     */
+    protected function _getProcessingAttemptsPerformedData()
+    {
+        return array(
+            'Centinel case 11' => array(
+                true, true,
+                array('pa_res_status' => 'A', 'signature_verification' => 'Y', 'eci_flag' => '06',
+                    'xid' => 'some string', 'cavv' => 'some string', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 11 pa_res_status is absent' => array(
+                false, true,
+                array('signature_verification' => 'Y', 'eci_flag' => '06', 'xid' => 'some string',
+                    'cavv' => 'some string', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 11 signature_verification is absent' => array(
+                false, true,
+                array('pa_res_status' => 'A', 'eci_flag' => '06', 'xid' => 'some string', 'cavv' => 'some string',
+                    'error_no' => '0'
+                )
+            ),
+            'Centinel case 11 eci_flag is absent' => array(
+                false, true,
+                array('pa_res_status' => 'A', 'signature_verification' => 'Y', 'xid' => 'some string',
+                    'cavv' => 'some string', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 11 xid is absent' => array(
+                false, true,
+                array('pa_res_status' => 'A', 'signature_verification' => 'Y', 'eci_flag' => '06',
+                    'cavv' => 'some string', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 11 cavv is absent' => array(
+                false, true,
+                array('pa_res_status' => 'A', 'signature_verification' => 'Y', 'eci_flag' => '06',
+                    'xid' => 'some string', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 11 error_no is absent' => array(
+                false, true,
+                array('pa_res_status' => 'A', 'signature_verification' => 'Y', 'eci_flag' => '06',
+                    'xid' => 'some string', 'cavv' => 'some string',
+                )
+            ),
+            'Centinel case no params' => array(
+                false, true, array()
+            ),
+            'Centinel case 11 wrong pa_res_status' => array(
+                false, true,
+                array('pa_res_status' => 'wrong value', 'signature_verification' => 'Y', 'eci_flag' => '06',
+                    'xid' => 'some string', 'cavv' => 'some string', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 11 wrong signature_verification' => array(
+                false, true,
+                array('pa_res_status' => 'A', 'signature_verification' => 'wrong value', 'eci_flag' => '06',
+                    'xid' => 'some string', 'cavv' => 'some string', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 11 wrong eci_flag' => array(
+                false, true,
+                array('pa_res_status' => 'A', 'signature_verification' => 'Y', 'eci_flag' => 'wrong value',
+                    'xid' => 'some string', 'cavv' => 'some string', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 11 empty xid' => array(
+                false, true,
+                array('pa_res_status' => 'A', 'signature_verification' => 'Y', 'eci_flag' => '06',
+                    'xid' => '', 'cavv' => 'some string', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 11 empty cavv' => array(
+                false, true,
+                array('pa_res_status' => 'A', 'signature_verification' => 'Y', 'eci_flag' => '06',
+                    'xid' => 'some string', 'cavv' => '', 'error_no' => '0'
+                )
+            ),
+            'Centinel case 11 no zero' => array(
+                false, true,
+                array('pa_res_status' => 'A', 'signature_verification' => 'Y', 'eci_flag' => '06',
+                    'xid' => 'some string', 'cavv' => 'some string', 'error_no' => 'no zero'
+                )
+            ),
+        );
+    }
+
+    /**
+     * @param bool $result
+     * @param bool $strictMode
+     * @param array $params
+     * @dataProvider isLookupSuccessfulDataProvider
+     */
+    public function testIsLookupSuccessful($result, $strictMode, $params)
+    {
+        $this->_model->setLookupResult(new Varien_Object($params));
+        $this->_model->setIsModeStrict($strictMode);
+        $this->assertEquals($result, $this->_model->isLookupSuccessful());
+    }
+
+    public function isLookupSuccessfulDataProvider()
+    {
+        return array_merge(
+            $this->_getSoftSuccessfulLookupData(),
+            $this->_getStrictSuccessfulLookupData()
+        );
+    }
+
+    /**
+     * Data for soft successful lookup
+     *
+     * @return array
+     */
+    protected function _getSoftSuccessfulLookupData()
+    {
+        return array(
+            'Centinel case 5' => array(
+                true, false,
+                array('enrolled' => '', 'acs_url' => '', 'payload' => '', 'error_no' => '0'),
+            ),
+            'Centinel case 5 enrolled is absent' => array(
+                false, false,
+                array('acs_url' => '', 'payload' => '', 'error_no' => '0'),
+            ),
+            'Centinel case 5 acs_url is absent' => array(
+                false, false,
+                array('enrolled' => '', 'payload' => '', 'error_no' => '0'),
+            ),
+            'Centinel case 5 payload is absent' => array(
+                false, false,
+                array('enrolled' => '', 'acs_url' => '', 'error_no' => '0'),
+            ),
+            'Centinel case 5 error_no is absent' => array(
+                false, false,
+                array('enrolled' => '', 'acs_url' => '', 'payload' => ''),
+            ),
+            'Centinel case 5 no params' => array(
+                false, false, array(),
+            ),
+            'Centinel case 5 not empty enrolled' => array(
+                false, false,
+                array('enrolled' => 'not empty', 'acs_url' => '', 'payload' => '', 'error_no' => '0'),
+            ),
+            'Centinel case 5 not empty acs_url' => array(
+                false, false,
+                array('enrolled' => '', 'acs_url' => 'not empty', 'payload' => '', 'error_no' => '0'),
+            ),
+            'Centinel case 5 not empty payload' => array(
+                false, false,
+                array('enrolled' => '', 'acs_url' => '', 'payload' => 'not empty', 'error_no' => '0'),
+            ),
+            'Centinel case 5 no zero error_no' => array(
+                false, false,
+                array('enrolled' => '', 'acs_url' => '', 'payload' => '', 'error_no' => 'not zero'),
+            ),
+            'Centinel case 5 empty error_no' => array(
+                false, false,
+                array('enrolled' => '', 'acs_url' => '', 'payload' => '', 'error_no' => ''),
+            ),
+            'Centinel case 7' => array(
+                true, false,
+                array('enrolled' => 'U', 'acs_url' => '', 'payload' => '', 'error_no' => '0'),
+            ),
+            'Centinel case 8,9' => array(
+                true, false,
+                array('enrolled' => 'U', 'acs_url' => '', 'payload' => '', 'error_no' => 'some string'),
+            ),
+            'Centinel case 7,8,9 enrolled is absent' => array(
+                false, false,
+                array('acs_url' => '', 'payload' => '', 'error_no' => '0'),
+            ),
+            'Centinel case 7,8,9 acs_url is absent' => array(
+                false, false,
+                array('enrolled' => 'U', 'payload' => '', 'error_no' => '0'),
+            ),
+            'Centinel case 7,8,9 payload is absent' => array(
+                false, false,
+                array('enrolled' => 'U', 'acs_url' => '', 'error_no' => '0'),
+            ),
+            'Centinel case 7,8,9 error_no no params' => array(
+                false,false, array(),
+            ),
+            'Centinel case 7,8,9 wrong enrolled' => array(
+                false, false,
+                array('enrolled' => 'wrong value', 'acs_url' => '', 'payload' => '', 'error_no' => '0'),
+            ),
+            'Centinel case 7,8,9 not empty acs_url' => array(
+                false, false,
+                array('enrolled' => 'U', 'acs_url' => 'not empty', 'payload' => '', 'error_no' => '0'),
+            ),
+            'Centinel case 7,8,9 not empty payload' => array(
+                false, false,
+                array('enrolled' => 'U', 'acs_url' => '', 'payload' => 'not empty', 'error_no' => '0'),
+            ),
+        );
+    }
+
+    /**
+     * Data for strict successful lookup
+     *
+     * @return array
+     */
+    protected function _getStrictSuccessfulLookupData()
+    {
+        return array(
+            'Centinel cases 1-4, 6, 10-11' => array(
+                true, true,
+                array('enrolled' => 'Y', 'acs_url' => 'some string', 'payload' => 'some string', 'error_no' => '0'),
+            ),
+            'Centinel cases 1-4, 6, 10-11 enrolled is absent' => array(
+                false, true,
+                array('acs_url' => 'some string', 'payload' => 'some string', 'error_no' => '0'),
+            ),
+            'Centinel cases 1-4, 6, 10-11 acs_url is absent' => array(
+                false, true,
+                array('enrolled' => 'Y', 'payload' => 'some string', 'error_no' => '0'),
+            ),
+            'Centinel cases 1-4, 6, 10-11 payload is absent' => array(
+                false, true,
+                array('enrolled' => 'Y', 'acs_url' => 'some string', 'error_no' => '0'),
+            ),
+            'Centinel cases 1-4, 6, 10-11 error_no is absent' => array(
+                false, true,
+                array('enrolled' => 'Y', 'acs_url' => 'some string', 'payload' => 'some string'),
+            ),
+            'Centinel cases 1-4, 6, 10-11 no params' => array(
+                false, true, array(),
+            ),
+            'Centinel cases 1-4, 6, 10-11 wrong enrolled' => array(
+                false, true,
+                array('enrolled' => 'wrong value', 'acs_url' => 'some string', 'payload' => 'some string',
+                    'error_no' => '0'
+                ),
+            ),
+            'Centinel cases 1-4, 6, 10-11 empty enrolled' => array(
+                false, true,
+                array('enrolled' => '', 'acs_url' => 'some string', 'payload' => 'some string', 'error_no' => '0'),
+            ),
+            'Centinel cases 1-4, 6, 10-11 empty acs_url' => array(
+                false, true,
+                array('enrolled' => 'Y', 'acs_url' => '', 'payload' => 'some string', 'error_no' => '0'),
+            ),
+            'Centinel cases 1-4, 6, 10-11 empty payload' => array(
+                false, true,
+                array('enrolled' => 'Y', 'acs_url' => 'some string', 'payload' => '', 'error_no' => '0'),
+            ),
+            'Centinel cases 1-4, 6, 10-11 wrong error_no' => array(
+                false, true,
+                array('enrolled' => 'Y', 'acs_url' => 'some string', 'payload' => 'some string',
+                    'error_no' => 'wrong value'
+                ),
+            ),
+            'Centinel cases 1-4, 6, 10-11 empty error_no' => array(
+                false, true,
+                array('enrolled' => 'Y', 'acs_url' => 'some string', 'payload' => 'some string', 'error_no' => ''),
+            )
+        );
+    }
+}
diff --git a/dev/tests/unit/testsuite/Mage/Core/Helper/CookieTest.php b/dev/tests/unit/testsuite/Mage/Core/Helper/CookieTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..5d7c338f6cbf792c3ba2ea10cee1c5662df246e4
--- /dev/null
+++ b/dev/tests/unit/testsuite/Mage/Core/Helper/CookieTest.php
@@ -0,0 +1,151 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Mage
+ * @package     Mage_Core
+ * @subpackage  unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+class Mage_Core_Helper_CookieTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Mage_Core_Helper_Cookie
+     */
+    protected $_object = null;
+
+    protected function setUp()
+    {
+        $this->_object = new Mage_Core_Helper_Cookie(
+            array(
+                'current_store' => $this->_getStoreStub(),
+                'cookie_model' => $this->_getCookieStub(array(1 => 1)),
+                'website' => $this->_getWebsiteStub(),
+            )
+        );
+    }
+
+    public function testIsUserNotAllowSaveCookie()
+    {
+        $this->assertFalse($this->_object->isUserNotAllowSaveCookie());
+        $this->_object = new Mage_Core_Helper_Cookie(
+            array(
+                'current_store' => $this->_getStoreStub(),
+                'cookie_model' => $this->_getCookieStub(array()),
+                'website' => $this->_getWebsiteStub(),
+            )
+        );
+        $this->assertTrue($this->_object->isUserNotAllowSaveCookie());
+    }
+
+    public function testGetAcceptedSaveCookiesWebsiteIds()
+    {
+        $this->assertEquals(
+            $this->_object->getAcceptedSaveCookiesWebsiteIds(),
+            json_encode(array(1 => 1))
+        );
+    }
+
+    public function testGetCookieRestrictionLifetime()
+    {
+        $storeStub = $this->_getStoreStub();
+        $storeStub->expects($this->once())
+            ->method('getConfig')
+            ->will($this->returnCallback('Mage_Core_Helper_CookieTest::getConfigMethodStub'))
+            ->with($this->equalTo('web/cookie/cookie_restriction_lifetime'));
+        $this->_object = new Mage_Core_Helper_Cookie(
+            array(
+                'current_store' => $storeStub,
+                'cookie_model' => $this->_getCookieStub(array(1 => 1)),
+                'website' => $this->_getWebsiteStub()
+            )
+        );
+        $this->assertEquals($this->_object->getCookieRestrictionLifetime(), 60*60*24*365);
+    }
+
+    /**
+     * Create store stub
+     * @return Mage_Core_Model_Store
+     */
+    protected function _getStoreStub()
+    {
+        $store = $this->getMock('Mage_Core_Model_Store', array('getConfig'), array(), '', false);
+
+        $store->expects($this->any())
+            ->method('getConfig')
+            ->will($this->returnCallback('Mage_Core_Helper_CookieTest::getConfigMethodStub'));
+
+        return $store;
+    }
+
+    /**
+     * Create cookie model stub
+     * @param array $cookieString
+     * @return Mage_Core_Model_Cookie
+     */
+    protected function _getCookieStub($cookieString = array())
+    {
+        $cookie = $this->getMock('Mage_Core_Model_Cookie', array('get'), array(), '', false);
+
+        $cookie->expects($this->any())
+            ->method('get')
+            ->will($this->returnValue(json_encode($cookieString)));
+
+        return $cookie;
+    }
+
+    /**
+     * Create Website Stub
+     * @return Mage_Core_Model_Website
+     */
+    protected function _getWebsiteStub()
+    {
+        $website = $this->getMock('Mage_Core_Model_Website', array('getId'), array(), '', false);
+
+        $website->expects($this->any())
+            ->method('getId')
+            ->will($this->returnValue(1));
+
+        return $website;
+    }
+
+    /**
+     * Mock get config method
+     * @static
+     * @param string $hashName
+     * @return string
+     * @throws InvalidArgumentException
+     */
+    public static function getConfigMethodStub($hashName)
+    {
+
+        $defaultConfig = array(
+            'web/cookie/cookie_restriction' => 1,
+            'web/cookie/cookie_restriction_lifetime' => 60*60*24*365,
+        );
+
+        if (array_key_exists($hashName, $defaultConfig)) {
+            return $defaultConfig[$hashName];
+        }
+
+        throw new InvalidArgumentException('Unknow id = ' . $hashName);
+    }
+}
diff --git a/dev/tests/unit/testsuite/Mage/Core/Model/AuthorizationTest.php b/dev/tests/unit/testsuite/Mage/Core/Model/AuthorizationTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..6c9786cd822d06dc4544b762a4933c55b4313229
--- /dev/null
+++ b/dev/tests/unit/testsuite/Mage/Core/Model/AuthorizationTest.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Magento
+ * @package     Mage_Core
+ * @subpackage  unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+/**
+ * Test class for Mage_Core_Model_Authorization.
+ */
+class Mage_Core_Model_AuthorizationTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * Authorization model
+     *
+     * @var Mage_Core_Model_Authorization
+     */
+    protected $_model;
+
+    /**
+     * @var PHPUnit_Framework_MockObject_MockObject
+     */
+    protected $_policyMock;
+
+    public function setUp()
+    {
+        $this->_policyMock = $this->getMock('Magento_Authorization_Policy', array(), array(), '', false);
+        $roleLocatorMock = $this->getMock('Magento_Authorization_RoleLocator', array(), array(), '', false);
+        $roleLocatorMock->expects($this->any())->method('getAclRoleId')->will($this->returnValue('U1'));
+
+        $data = array(
+            'policy' => $this->_policyMock,
+            'roleLocator' => $roleLocatorMock
+        );
+        $this->_model = new Mage_Core_Model_Authorization($data);
+    }
+
+    public function tearDown()
+    {
+        unset($this->_model);
+    }
+
+    public function testIsAllowedReturnPositiveValue()
+    {
+        $this->_policyMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
+        $this->assertTrue($this->_model->isAllowed('Mage_Module::acl_resource'));
+    }
+
+    public function testIsAllowedReturnNegativeValue()
+    {
+        $this->_policyMock->expects($this->once())->method('isAllowed')->will($this->returnValue(false));
+        $this->assertFalse($this->_model->isAllowed('Mage_Module::acl_resource'));
+    }
+}
diff --git a/dev/tests/unit/testsuite/Mage/Eav/Model/Resource/Entity/AttributeTest.php b/dev/tests/unit/testsuite/Mage/Eav/Model/Resource/Entity/AttributeTest.php
index 0d2de949b8fa80b258c0258b40a732d9dd640d37..dcc7c1d38944529216336adfe13411d1fd1c6dd3 100644
--- a/dev/tests/unit/testsuite/Mage/Eav/Model/Resource/Entity/AttributeTest.php
+++ b/dev/tests/unit/testsuite/Mage/Eav/Model/Resource/Entity/AttributeTest.php
@@ -62,7 +62,8 @@ class Mage_Eav_Model_Resource_Entity_AttributeTest extends Magento_Test_TestCase
             array('eav_attribute', $attributeData, 1),
         )));
 
-        $adapter->expects($this->never())->method('update');
+        //this line causes crash on windows environment
+        //$adapter->expects($this->never())->method('update');
         $adapter->expects($this->never())->method('delete');
 
         $adapter->expects($this->once())
diff --git a/dev/tests/unit/testsuite/Mage/Backend/Model/Acl/Config/ReaderTest.php b/dev/tests/unit/testsuite/Magento/Acl/Config/ReaderTest.php
similarity index 79%
rename from dev/tests/unit/testsuite/Mage/Backend/Model/Acl/Config/ReaderTest.php
rename to dev/tests/unit/testsuite/Magento/Acl/Config/ReaderTest.php
index f177cdbd5cd2915408054f1eccfbcf7a1138cebf..1249b2917ab20759b7d902eb4f8448bc929c08bf 100644
--- a/dev/tests/unit/testsuite/Mage/Backend/Model/Acl/Config/ReaderTest.php
+++ b/dev/tests/unit/testsuite/Magento/Acl/Config/ReaderTest.php
@@ -25,25 +25,25 @@
  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  */
 
-class Mage_Backend_Model_Acl_Config_ReaderTest extends PHPUnit_Framework_TestCase
+class Magento_Acl_Config_ReaderTest extends PHPUnit_Framework_TestCase
 {
     /**
-     * @var Mage_Backend_Model_Acl_Config_Reader
+     * @var Magento_Acl_Config_Reader
      */
     protected $_model;
 
     public function setUp()
     {
         $files = array(
-            realpath(__DIR__) . '/../../_files/acl_1.xml',
-            realpath(__DIR__) . '/../../_files/acl_2.xml'
+            realpath(__DIR__) . '/../_files/acl_1.xml',
+            realpath(__DIR__) . '/../_files/acl_2.xml'
         );
-        $this->_model = new Mage_Backend_Model_Acl_Config_Reader($files);
+        $this->_model = new Magento_Acl_Config_Reader($files);
     }
 
     public function testReaderImplementRequiredInterface()
     {
-        $this->assertInstanceOf('Mage_Backend_Model_Acl_Config_ReaderInterface', $this->_model);
+        $this->assertInstanceOf('Magento_Acl_Config_ReaderInterface', $this->_model);
     }
 
     public function testGetAclResources()
@@ -56,7 +56,7 @@ class Mage_Backend_Model_Acl_Config_ReaderTest extends PHPUnit_Framework_TestCas
 
     public function testGetAclResourcesMergedCorrectly()
     {
-        $expectedFile = realpath(__DIR__) . '/../../_files/acl_merged.xml';
+        $expectedFile = realpath(__DIR__) . '/../_files/acl_merged.xml';
         $expectedResources = new DOMDocument();
         $expectedResources->load($expectedFile);
 
diff --git a/dev/tests/unit/testsuite/Magento/Acl/_files/acl_1.xml b/dev/tests/unit/testsuite/Magento/Acl/_files/acl_1.xml
new file mode 100644
index 0000000000000000000000000000000000000000..063bc80b13d7d99764fc93b539a8518f4c3c8d13
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Acl/_files/acl_1.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Academic Free License (AFL 3.0)
+ * that is bundled with this package in the file LICENSE_AFL.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/afl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Magento
+ * @package     Framework
+ * @subpackage  unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
+ */
+-->
+<config>
+    <acl>
+        <resources>
+            <resource id="Dummy1::all" title="Allow everything" module="Dummy1" />
+            <resource id="Dummy1::parent" title="Dummy Parent Resource" module="Dummy1">
+                <resource id="Dummy1::first" title="Dummy Resource #1" module="Dummy1" sortOrder="0" />
+                <resource id="Dummy1::second" title="Dummy Resource #2" module="Dummy1" sortOrder="10"/>
+                <resource id="Dummy1::third" title="Dummy Resource #3" module="Dummy1" sortOrder="50" />
+            </resource>
+        </resources>
+    </acl>
+</config>
diff --git a/dev/tests/unit/testsuite/Magento/Acl/_files/acl_2.xml b/dev/tests/unit/testsuite/Magento/Acl/_files/acl_2.xml
new file mode 100644
index 0000000000000000000000000000000000000000..78dc8b3ba035074e457e4e2b03ddcd316f3fc7c9
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Acl/_files/acl_2.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Academic Free License (AFL 3.0)
+ * that is bundled with this package in the file LICENSE_AFL.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/afl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Magento
+ * @package     Framework
+ * @subpackage  unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
+ */
+-->
+<config>
+    <acl>
+        <resources>
+            <resource id="Dummy1::parent">
+                <resource id="Dummy1::first">
+                    <resource id="Dummy2::parent" title="Dummy 2 Resource Parent" module="Dummy2" sortOrder="0">
+                        <resource id="Dummy2::first" title="Dummy 2 Resource #1" module="Dummy2" sortOrder="10" />
+                        <resource id="Dummy2::second" title="Dummy 2 Resource #2" module="Dummy2" sortOrder="20" />
+                    </resource>
+                </resource>
+            </resource>
+        </resources>
+    </acl>
+</config>
diff --git a/dev/tests/unit/testsuite/Magento/Acl/_files/acl_merged.xml b/dev/tests/unit/testsuite/Magento/Acl/_files/acl_merged.xml
new file mode 100644
index 0000000000000000000000000000000000000000..52eceba783bf2e0a905d7d64a0ecd7ec1f84b7c2
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Acl/_files/acl_merged.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Academic Free License (AFL 3.0)
+ * that is bundled with this package in the file LICENSE_AFL.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/afl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Magento
+ * @package     Framework
+ * @subpackage  unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
+ */
+-->
+<config>
+    <acl>
+        <resources>
+            <resource id="Dummy1::all" title="Allow everything" module="Dummy1" />
+            <resource id="Dummy1::parent" title="Dummy Parent Resource" module="Dummy1">
+                <resource id="Dummy1::first" title="Dummy Resource #1" module="Dummy1" sortOrder="0">
+                    <resource id="Dummy2::parent" title="Dummy 2 Resource Parent" module="Dummy2" sortOrder="0">
+                        <resource id="Dummy2::first" title="Dummy 2 Resource #1" module="Dummy2" sortOrder="10" />
+                        <resource id="Dummy2::second" title="Dummy 2 Resource #2" module="Dummy2" sortOrder="20" />
+                    </resource>
+                </resource>
+                <resource id="Dummy1::second" title="Dummy Resource #2" module="Dummy1" sortOrder="10"/>
+                <resource id="Dummy1::third" title="Dummy Resource #3" module="Dummy1" sortOrder="50" />
+            </resource>
+        </resources>
+    </acl>
+</config>
diff --git a/dev/tests/unit/testsuite/Magento/Authorization/Policy/AclTest.php b/dev/tests/unit/testsuite/Magento/Authorization/Policy/AclTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..9a55b9fa00ec4af7f0f206bb8cdf8945215760df
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Authorization/Policy/AclTest.php
@@ -0,0 +1,86 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Magento
+ * @package     unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+class Magento_Authorization_Policy_AclTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Magento_Authorization_Policy_Acl
+     */
+    protected $_model;
+
+    protected $_aclMock;
+
+    public function setUp()
+    {
+        $this->_aclMock = $this->getMock('Magento_Acl');
+        $this->_model = new Magento_Authorization_Policy_Acl($this->_aclMock);
+    }
+
+    public function testIsAllowedReturnsTrueIfResourceIsAllowedToRole()
+    {
+        $this->_aclMock->expects($this->once())
+            ->method('isAllowed')
+            ->with('some_role', 'some_resource')
+            ->will($this->returnValue(true));
+
+        $this->assertTrue($this->_model->isAllowed('some_role', 'some_resource'));
+    }
+
+    public function testIsAllowedReturnsFalseIfRoleDoesntExist()
+    {
+        $this->_aclMock->expects($this->once())
+            ->method('isAllowed')
+            ->with('some_role', 'some_resource')
+            ->will($this->throwException(new Zend_Acl_Role_Registry_Exception));
+
+        $this->_aclMock->expects($this->once())
+            ->method('has')
+            ->with('some_resource')
+            ->will($this->returnValue(true));
+
+        $this->assertFalse($this->_model->isAllowed('some_role', 'some_resource'));
+    }
+
+    public function testIsAllowedReturnsTrueIfResourceDoesntExistAndAllResourcesAreNotPermitted()
+    {
+        $this->_aclMock->expects($this->at(0))
+            ->method('isAllowed')
+            ->with('some_role', 'some_resource')
+            ->will($this->throwException(new Zend_Acl_Role_Registry_Exception));
+
+        $this->_aclMock->expects($this->once())
+            ->method('has')
+            ->with('some_resource')
+            ->will($this->returnValue(false));
+
+        $this->_aclMock->expects($this->at(2))
+            ->method('isAllowed')
+            ->with('some_role', null)
+            ->will($this->returnValue(true));
+
+        $this->assertTrue($this->_model->isAllowed('some_role', 'some_resource'));
+    }
+}
diff --git a/dev/tests/unit/testsuite/Magento/Authorization/Policy/DefaultTest.php b/dev/tests/unit/testsuite/Magento/Authorization/Policy/DefaultTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..b563e90f62212e90ceae53bd8ad88737db167c38
--- /dev/null
+++ b/dev/tests/unit/testsuite/Magento/Authorization/Policy/DefaultTest.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Magento
+ * @package     unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+class Magento_Authorization_Policy_DefaultTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Magento_Authorization_Policy_Default
+     */
+    protected $_model;
+
+    public function setUp()
+    {
+        $this->_model = new Magento_Authorization_Policy_Default();
+    }
+
+    public function testIsAllowedReturnsTrueForAnyResource()
+    {
+        $this->assertTrue($this->_model->isAllowed('any_role', 'any_resource'));
+    }
+}
diff --git a/dev/tests/unit/testsuite/Varien/Simplexml/ElementTest.php b/dev/tests/unit/testsuite/Varien/Simplexml/ElementTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..5246894de88b46e5b22a3568179854a2546ccefc
--- /dev/null
+++ b/dev/tests/unit/testsuite/Varien/Simplexml/ElementTest.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+class Varien_Simplexml_ElementTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @dataProvider xmlDataProvider
+     */
+    public function testUnsetSelf($xmlData)
+    {
+        /** @var $xml Varien_Simplexml_Element */
+        $xml = simplexml_load_file($xmlData[0], $xmlData[1]);
+        $this->assertTrue(isset($xml->node3->node4));
+        $xml->node3->unsetSelf();
+        $this->assertFalse(isset($xml->node3->node4));
+        $this->assertFalse(isset($xml->node3));
+        $this->assertTrue(isset($xml->node1));
+    }
+
+    /**
+     * @dataProvider xmlDataProvider
+     * @expectedException InvalidArgumentException
+     * @expectedExceptionMessage Root node could not be unset.
+     */
+    public function testGetParent($xmlData)
+    {
+        /** @var $xml Varien_Simplexml_Element */
+        $xml = simplexml_load_file($xmlData[0], $xmlData[1]);
+        $this->assertTrue($xml->getName() == 'root');
+        $xml->unsetSelf();
+    }
+
+    /**
+     * Data Provider for testUnsetSelf and testUnsetSelfException
+     */
+    public static function xmlDataProvider()
+    {
+        return array(
+            array(array(__DIR__ . '/_files/data.xml', 'Varien_Simplexml_Element'))
+        );
+    }
+}
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/_files/template_document.xml b/dev/tests/unit/testsuite/Varien/Simplexml/_files/data.xml
similarity index 85%
rename from dev/tests/unit/testsuite/tools/migration/Acl/_files/template_document.xml
rename to dev/tests/unit/testsuite/Varien/Simplexml/_files/data.xml
index ea183ee9d55fcfa34055652c7f9e8fbb0ab8a7aa..c16ccd36cc795b995503ad36c7282c69a906da07 100644
--- a/dev/tests/unit/testsuite/tools/migration/Acl/_files/template_document.xml
+++ b/dev/tests/unit/testsuite/Varien/Simplexml/_files/data.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0"?>
+<?xml version="1.0"?>
 <!--
 /**
  * Magento
@@ -19,14 +19,15 @@
  * versions in the future. If you wish to customize Magento for your
  * needs please refer to http://www.magentocommerce.com for more information.
  *
- * @category    Category
- * @package     Module_Name
  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
  */
 -->
-<config>
-  <acl>
-    <resources xpath="config/acl/resources"/>
-  </acl>
-</config>
+<root>
+    <node1>
+        <node2/>
+    </node1>
+    <node3>
+        <node4/>
+    </node3>
+</root>
\ No newline at end of file
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/Db/Adapter/FactoryTest.php b/dev/tests/unit/testsuite/tools/migration/Acl/Db/Adapter/FactoryTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..4987643fb5f776ea0ba09ac770ef03976ebdcc2d
--- /dev/null
+++ b/dev/tests/unit/testsuite/tools/migration/Acl/Db/Adapter/FactoryTest.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Tools
+ * @package     unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+require_once realpath(dirname(__FILE__) . '/../../../../../../../../') . '/tools/migration/Acl/Db/Adapter/Factory.php';
+
+class Tools_Migration_Acl_Db_Adapter_FactoryTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Tools_Migration_Acl_Db_Adapter_Factory
+     */
+    protected $_model;
+
+    /**
+     * @var array
+     */
+    protected $_config;
+
+    public function setUp()
+    {
+        $this->_model = new Tools_Migration_Acl_Db_Adapter_Factory();
+        $this->_config = array(
+            'dbname' => 'some_db_name',
+            'password' => '',
+            'username' => '',
+
+        );
+    }
+
+    public function tearDown()
+    {
+        unset($this->_model);
+    }
+
+    /**
+     * @return array
+     */
+    public function getAdapterDataProvider()
+    {
+        return array(
+            array('Varien_Db_Adapter_Pdo_Mysql'),
+            array(''),
+            array(null),
+        );
+    }
+
+    /**
+     * @param $adapterType
+     * @dataProvider getAdapterDataProvider
+     */
+    public function testGetAdapter($adapterType)
+    {
+        $this->assertInstanceOf('Zend_Db_Adapter_Abstract',
+            $this->_model->getAdapter($this->_config, $adapterType)
+        );
+    }
+
+    /**
+     * @expectedException InvalidArgumentException
+     */
+    public function testGetAdapterWithInvalidType()
+    {
+        $this->_model->getAdapter($this->_config, 'Mage_Core_Helper_Data');
+    }
+}
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/Db/FileReaderTest.php b/dev/tests/unit/testsuite/tools/migration/Acl/Db/FileReaderTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..a5548395eab3140a0ed15e2a996a36bb810352e1
--- /dev/null
+++ b/dev/tests/unit/testsuite/tools/migration/Acl/Db/FileReaderTest.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Tools
+ * @package     unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+require_once realpath(dirname(__FILE__) . '/../../../../../../../') . '/tools/migration/Acl/Db/FileReader.php';
+
+class Tools_Migration_Acl_Db_FileReaderTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Tools_Migration_Acl_Db_FileReader
+     */
+    protected $_model;
+
+    public function setUp()
+    {
+        $this->_model = new Tools_Migration_Acl_Db_FileReader();
+    }
+
+    public function testExtractData()
+    {
+        $filePath = __DIR__ . DIRECTORY_SEPARATOR . '../_files' . DIRECTORY_SEPARATOR . 'log'
+            . DIRECTORY_SEPARATOR . 'AclXPathToAclId.log';
+        $expectedMap = array(
+            "admin/test1/test2"        => "Test1_Test2::all",
+            "admin/test1/test2/test3"  => "Test1_Test2::test3",
+            "admin/test1/test2/test4"  => "Test1_Test2::test4",
+            "admin/test1/test2/test5"  => "Test1_Test2::test5",
+            "admin/test6"              => "Test6_Test6::all"
+        );
+        $this->assertEquals($expectedMap, $this->_model->extractData($filePath));
+    }
+
+    /**
+     * @expectedException InvalidArgumentException
+     */
+    public function testExtractDataThrowsExceptionIfInvalidFileProvided()
+    {
+        $this->_model->extractData('invalidFile.log');
+    }
+}
+
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/Db/Logger/ConsoleTest.php b/dev/tests/unit/testsuite/tools/migration/Acl/Db/Logger/ConsoleTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..4d5b6d7afe17ef89ef2ebd701a383a3237dfbcef
--- /dev/null
+++ b/dev/tests/unit/testsuite/tools/migration/Acl/Db/Logger/ConsoleTest.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Tools
+ * @package     unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+require_once realpath(dirname(__FILE__) . '/../../../../../../../../') . '/tools/migration/Acl/Db/LoggerAbstract.php';
+require_once realpath(dirname(__FILE__) . '/../../../../../../../../') . '/tools/migration/Acl/Db/Logger/Console.php';
+
+class Tools_Migration_Acl_Db_Logger_ConsoleTest extends PHPUnit_Extensions_OutputTestCase
+{
+    public function testReport()
+    {
+        $this->expectOutputRegex('/^Mapped items count: 0(.)*/');
+        $model = new Tools_Migration_Acl_Db_Logger_Console();
+        $model->report();
+    }
+}
+
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/Db/Logger/FactoryTest.php b/dev/tests/unit/testsuite/tools/migration/Acl/Db/Logger/FactoryTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..51153394cb1fbc4b32bb8dde8de87bc27a95c9df
--- /dev/null
+++ b/dev/tests/unit/testsuite/tools/migration/Acl/Db/Logger/FactoryTest.php
@@ -0,0 +1,80 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Tools
+ * @package     unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+require_once realpath(dirname(__FILE__) . '/../../../../../../../../') . '/tools/migration/Acl/Db/LoggerAbstract.php';
+require_once realpath(dirname(__FILE__) . '/../../../../../../../../') . '/tools/migration/Acl/Db/Logger/Factory.php';
+require_once realpath(dirname(__FILE__) . '/../../../../../../../../') . '/tools/migration/Acl/Db/Logger/Console.php';
+require_once realpath(dirname(__FILE__) . '/../../../../../../../../') . '/tools/migration/Acl/Db/Logger/File.php';
+
+
+
+class Tools_Migration_Acl_Db_Logger_FactoryTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Tools_Migration_Acl_Db_Logger_Factory
+     */
+    protected $_model;
+
+    public function setUp()
+    {
+        $this->_model = new Tools_Migration_Acl_Db_Logger_Factory();
+    }
+
+    public function tearDown()
+    {
+        unset($this->_model);
+    }
+
+    /**
+     * @return array
+     */
+    public function getLoggerDataProvider()
+    {
+        return array(
+            array('console', null),
+            array('file', realpath(dirname(__FILE__) . '/../../../../../') . '/tmp') ,
+        );
+    }
+
+    /**
+     * @param string $loggerType
+     * @param string $file
+     * @dataProvider getLoggerDataProvider
+     */
+    public function testGetLogger($loggerType, $file)
+    {
+        $this->assertInstanceOf('Tools_Migration_Acl_Db_LoggerAbstract', $this->_model->getLogger($loggerType, $file));
+    }
+
+    /**
+     * @expectedException InvalidArgumentException
+     */
+    public function testGetLoggerWithInvalidType()
+    {
+        $this->_model->getLogger('invalid type');
+    }
+}
+
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/Db/Logger/FileTest.php b/dev/tests/unit/testsuite/tools/migration/Acl/Db/Logger/FileTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..60251f249cb907759f72ef53c7161cd1e5e32fe3
--- /dev/null
+++ b/dev/tests/unit/testsuite/tools/migration/Acl/Db/Logger/FileTest.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Tools
+ * @package     unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+require_once realpath(dirname(__FILE__) . '/../../../../../../../../') . '/tools/migration/Acl/Db/LoggerAbstract.php';
+require_once realpath(dirname(__FILE__) . '/../../../../../../../../') . '/tools/migration/Acl/Db/Logger/File.php';
+
+class Tools_Migration_Acl_Db_Logger_FileTest extends PHPUnit_Framework_TestCase
+{
+    public function testConstructWithValidFile()
+    {
+        new Tools_Migration_Acl_Db_Logger_File(realpath(dirname(__FILE__) . '/../../../../../') . '/tmp/');
+    }
+
+    /**
+     * @expectedException InvalidArgumentException
+     */
+    public function testConstructWithInValidFile()
+    {
+        new Tools_Migration_Acl_Db_Logger_File(null);
+    }
+}
+
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/Db/LoggerAbstractTest.php b/dev/tests/unit/testsuite/tools/migration/Acl/Db/LoggerAbstractTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..874274888efb3f2f86267070ec77266f17258136
--- /dev/null
+++ b/dev/tests/unit/testsuite/tools/migration/Acl/Db/LoggerAbstractTest.php
@@ -0,0 +1,73 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Tools
+ * @package     unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+require_once realpath(dirname(__FILE__) . '/../../../../../../../') . '/tools/migration/Acl/Db/LoggerAbstract.php';
+
+class Tools_Migration_Acl_Db_LoggerAbstractTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Tools_Migration_Acl_Db_LoggerAbstract
+     */
+    protected $_model;
+
+    public function setUp()
+    {
+        $this->_model = $this->getMockForAbstractClass('Tools_Migration_Acl_Db_LoggerAbstract');
+    }
+
+    public function tearDown()
+    {
+        unset($this->_model);
+    }
+
+    /**
+     * @covers Tools_Migration_Acl_Db_LoggerAbstract::add()
+     * @covers Tools_Migration_Acl_Db_LoggerAbstract::__toString()
+     */
+    public function testToString()
+    {
+        $this->_model->add('key1', 'key2', 3); // mapped item
+        $this->_model->add('key2', null, false); // not mapped item
+        $this->_model->add(null, 'Some_Module::acl_resource', false); //item in actual format
+
+        $expected = 'Mapped items count: 1' . PHP_EOL 
+            . 'Not mapped items count: 1' . PHP_EOL
+            . 'Items in actual format count: 1' . PHP_EOL
+            . '------------------------------' . PHP_EOL
+            . 'Mapped items:' . PHP_EOL
+            . 'key1 => key2 :: Count updated rules: 3' . PHP_EOL
+            . '------------------------------' . PHP_EOL
+            . 'Not mapped items:' . PHP_EOL
+            . 'key2' . PHP_EOL
+            . '------------------------------' . PHP_EOL
+            . 'Items in actual format:' . PHP_EOL
+            . 'Some_Module::acl_resource' . PHP_EOL
+            . '------------------------------' . PHP_EOL;
+
+        $this->assertEquals($expected, (string)$this->_model);
+    }
+}
+
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/Db/ReaderTest.php b/dev/tests/unit/testsuite/tools/migration/Acl/Db/ReaderTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..6dd21a620def1f644a7f8b052abfb9988a3829be
--- /dev/null
+++ b/dev/tests/unit/testsuite/tools/migration/Acl/Db/ReaderTest.php
@@ -0,0 +1,79 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Tools
+ * @package     unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+require_once realpath(dirname(__FILE__) . '/../../../../../../../') . '/tools/migration/Acl/Db/Reader.php';
+
+class Tools_Migration_Acl_Db_ReaderTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Tools_Migration_Acl_Db_Reader
+     */
+    protected $_model;
+
+    /**
+     * DB adapter
+     *
+     * @var PHPUnit_Framework_MockObject_MockObject
+     */
+    protected $_adapterMock;
+
+    public function setUp()
+    {
+        $this->_adapterMock = $this->getMockForAbstractClass(
+            'Zend_Db_Adapter_Abstract',
+            array(),
+            '',
+            false,
+            false,
+            false,
+            array('select', 'fetchPairs')
+        );
+        $this->_model = new Tools_Migration_Acl_Db_Reader($this->_adapterMock, 'dummy');
+    }
+
+    public function tearDown()
+    {
+        unset($this->_model);
+        unset($this->_adapterMock);
+    }
+
+    public function testFetchAll()
+    {
+        $expected = array(
+            'all' => 10,
+            'catalog' => 100,
+        );
+        $selectMock = $this->getMock('Zend_Db_Select', array(), array(), '', false);
+        $this->_adapterMock->expects($this->once())->method('select')->will($this->returnValue($selectMock));
+        $selectMock->expects($this->once())->method('from')->will($this->returnSelf());
+        $selectMock->expects($this->once())->method('columns')->will($this->returnSelf());
+        $selectMock->expects($this->once())->method('group')->will($this->returnSelf());
+        $this->_adapterMock->expects($this->once())->method('fetchPairs')->will($this->returnValue($expected));
+        $actual = $this->_model->fetchAll();
+        $this->assertEquals($expected, $actual);
+    }
+}
+
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/Db/UpdaterTest.php b/dev/tests/unit/testsuite/tools/migration/Acl/Db/UpdaterTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..11906fed772281db440155b9b86ba94004adde52
--- /dev/null
+++ b/dev/tests/unit/testsuite/tools/migration/Acl/Db/UpdaterTest.php
@@ -0,0 +1,107 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Tools
+ * @package     unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+require_once realpath(dirname(__FILE__) . '/../../../../../../../') . '/tools/migration/Acl/Db/Updater.php';
+
+class Tools_Migration_Acl_Db_UpdaterTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var PHPUnit_Framework_MockObject_MockObject
+     */
+    protected $_readerMock;
+
+    /**
+     * @var PHPUnit_Framework_MockObject_MockObject
+     */
+    protected $_writerMock;
+
+    /**
+     * @var PHPUnit_Framework_MockObject_MockObject
+     */
+    protected $_loggerMock;
+
+    /**
+     * @var array
+     */
+    protected $_map = array();
+
+    public function setUp()
+    {
+        $this->_readerMock = $this->getMock('Tools_Migration_Acl_Db_Reader', array(), array(), '', false);
+        $this->_readerMock->expects($this->once())->method('fetchAll')->will($this->returnValue(array(
+            'oldResource1' => 1,
+            'oldResource2' => 2,
+            'Test::newResource3'  => 3,
+            'additionalResource'  => 4,
+        )));
+
+        $this->_map = array(
+            "oldResource1"  => "Test::newResource1",
+            "oldResource2"  => "Test::newResource2",
+            "oldResource3"  => "Test::newResource3",
+            "oldResource4"  => "Test::newResource4",
+            "oldResource5"  => "Test::newResource5"
+        );
+
+        $this->_writerMock = $this->getMock('Tools_Migration_Acl_Db_Writer', array(), array(), '', false);
+        $this->_loggerMock = $this->getMockForAbstractClass(
+            'Tools_Migration_Acl_Db_LoggerAbstract', array(), '', false, false, false, array('add')
+        );
+    }
+
+    public function testMigrateInPreviewModeDoesntWriteToDb()
+    {
+        $model = new Tools_Migration_Acl_Db_Updater(
+            $this->_readerMock, $this->_writerMock, $this->_loggerMock, null
+        );
+
+        $this->_writerMock->expects($this->never())->method('update');
+
+        $this->_loggerMock->expects($this->at(0))->method('add')->with('oldResource1', 'Test::newResource1', 1);
+        $this->_loggerMock->expects($this->at(1))->method('add')->with('oldResource2', 'Test::newResource2', 2);
+        $this->_loggerMock->expects($this->at(2))->method('add')->with(null, 'Test::newResource3', 3);
+        $this->_loggerMock->expects($this->at(3))->method('add')->with('additionalResource', null, 4);
+
+        $model->migrate($this->_map);
+    }
+
+    public function testMigrateInRealModeWritesToDb()
+    {
+        $model = new Tools_Migration_Acl_Db_Updater(
+            $this->_readerMock, $this->_writerMock, $this->_loggerMock, Tools_Migration_Acl_Db_Updater::WRITE_MODE
+        );
+
+        $this->_writerMock->expects($this->at(0))->method('update')->with('oldResource1', 'Test::newResource1');
+        $this->_writerMock->expects($this->at(1))->method('update')->with('oldResource2', 'Test::newResource2');
+
+        $this->_loggerMock->expects($this->at(0))->method('add')->with('oldResource1', 'Test::newResource1', 1);
+        $this->_loggerMock->expects($this->at(1))->method('add')->with('oldResource2', 'Test::newResource2', 2);
+        $this->_loggerMock->expects($this->at(2))->method('add')->with(null, 'Test::newResource3', 3);
+        $this->_loggerMock->expects($this->at(3))->method('add')->with('additionalResource', null, 4);
+
+        $model->migrate($this->_map);
+    }
+}
+
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/Db/WriterTest.php b/dev/tests/unit/testsuite/tools/migration/Acl/Db/WriterTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..6769da0facad8111f728ddda24e91bbadbfde8c8
--- /dev/null
+++ b/dev/tests/unit/testsuite/tools/migration/Acl/Db/WriterTest.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Tools
+ * @package     unit_tests
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+require_once realpath(dirname(__FILE__) . '/../../../../../../../') . '/tools/migration/Acl/Db/Writer.php';
+
+class Tools_Migration_Acl_Db_WriterTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Tools_Migration_Acl_Db_Writer
+     */
+    protected $_model;
+
+    /**
+     * DB adapter
+     *
+     * @var PHPUnit_Framework_MockObject_MockObject
+     */
+    protected $_adapterMock;
+
+    public function setUp()
+    {
+        $this->_adapterMock = $this->getMockForAbstractClass('Zend_Db_Adapter_Abstract',
+            array(),
+            '',
+            false,
+            false,
+            false,
+            array('update')
+        );
+        $this->_model = new Tools_Migration_Acl_Db_Writer($this->_adapterMock, 'dummy');
+    }
+
+    public function tearDown()
+    {
+        unset($this->_model);
+        unset($this->_adapterMock);
+    }
+
+    public function testUpdate()
+    {
+        $this->_adapterMock->expects($this->once())
+            ->method('update')->with('dummy', array('resource_id' => 'new'), array('resource_id = ?' => 'old'));
+        $this->_model->update('old', 'new');
+    }
+}
+
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/GeneratorRemoveTest.php b/dev/tests/unit/testsuite/tools/migration/Acl/GeneratorRemoveTest.php
index 0d2a246a0497e5e40e4b4f88eb5f7cce65bbe7d7..29e5efbb6c80a62b1aae032a25a4e5abcb521452 100644
--- a/dev/tests/unit/testsuite/tools/migration/Acl/GeneratorRemoveTest.php
+++ b/dev/tests/unit/testsuite/tools/migration/Acl/GeneratorRemoveTest.php
@@ -25,7 +25,7 @@
  */
 
 require_once realpath(dirname(__FILE__) . '/../../../../../../') . '/tools/migration/Acl/Generator.php';
-require_once realpath(dirname(__FILE__) . '/../../../../../../') . '/tools/migration/Acl/FileWriter.php';
+require_once realpath(dirname(__FILE__) . '/../../../../../../') . '/tools/migration/Acl/FileManager.php';
 require_once realpath(dirname(__FILE__) . '/../../../../../../') . '/tools/migration/Acl/Formatter.php';
 
 /**
@@ -56,7 +56,7 @@ class Tools_Migration_Acl_GeneratorRemoveTest extends PHPUnit_Framework_TestCase
     /**
      * @var PHPUnit_Framework_MockObject_MockObject
      */
-    protected $_fileWriterMock;
+    protected $_fileManagerMock;
 
     public function setUp()
     {
@@ -67,9 +67,9 @@ class Tools_Migration_Acl_GeneratorRemoveTest extends PHPUnit_Framework_TestCase
         $this->_notEmptyFile = $path . 'not_empty.xml';
 
         $this->_xmlFormatterMock = $this->getMock('Tools_Migration_Acl_Formatter');
-        $this->_fileWriterMock = $this->getMock('Tools_Migration_Acl_FileWriter');
-        $this->_fileWriterMock->expects($this->once())->method('remove')->with($this->equalTo($this->_emptyFile));
-        $this->_model = new Tools_Migration_Acl_Generator($this->_xmlFormatterMock, $this->_fileWriterMock);
+        $this->_fileManagerMock = $this->getMock('Tools_Migration_Acl_FileManager');
+        $this->_fileManagerMock->expects($this->once())->method('remove')->with($this->equalTo($this->_emptyFile));
+        $this->_model = new Tools_Migration_Acl_Generator($this->_xmlFormatterMock, $this->_fileManagerMock);
     }
 
     public function tearDown()
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/GeneratorSaveTest.php b/dev/tests/unit/testsuite/tools/migration/Acl/GeneratorSaveTest.php
index b4bed22eeec7cf58303156ed6120bb94cebbfc0d..89015251906a5973c44bad54103605f8a3d2b93d 100644
--- a/dev/tests/unit/testsuite/tools/migration/Acl/GeneratorSaveTest.php
+++ b/dev/tests/unit/testsuite/tools/migration/Acl/GeneratorSaveTest.php
@@ -25,7 +25,7 @@
  */
 
 require_once realpath(dirname(__FILE__) . '/../../../../../../') . '/tools/migration/Acl/Generator.php';
-require_once realpath(dirname(__FILE__) . '/../../../../../../') . '/tools/migration/Acl/FileWriter.php';
+require_once realpath(dirname(__FILE__) . '/../../../../../../') . '/tools/migration/Acl/FileManager.php';
 require_once realpath(dirname(__FILE__) . '/../../../../../../') . '/tools/migration/Acl/Formatter.php';
 
 /**
@@ -61,13 +61,13 @@ class Tools_Migration_Acl_GeneratorSaveTest extends PHPUnit_Framework_TestCase
     /**
      * @var PHPUnit_Framework_MockObject_MockObject
      */
-    protected $_fileWriterMock;
+    protected $_fileManagerMock;
 
     public function setUp()
     {
         $this->_xmlFormatterMock = $this->getMock('Tools_Migration_Acl_Formatter');
-        $this->_fileWriterMock = $this->getMock('Tools_Migration_Acl_FileWriter');
-        $this->_model = new Tools_Migration_Acl_Generator($this->_xmlFormatterMock, $this->_fileWriterMock);
+        $this->_fileManagerMock = $this->getMock('Tools_Migration_Acl_FileManager');
+        $this->_model = new Tools_Migration_Acl_Generator($this->_xmlFormatterMock, $this->_fileManagerMock);
 
         $this->_fixturePath = realpath(__DIR__) . DIRECTORY_SEPARATOR . '_files';
         $path = $this->_fixturePath . DIRECTORY_SEPARATOR . 'save' . DIRECTORY_SEPARATOR;
@@ -106,7 +106,7 @@ class Tools_Migration_Acl_GeneratorSaveTest extends PHPUnit_Framework_TestCase
     {
         unset($this->_model);
         unset($this->_xmlFormatterMock);
-        unset($this->_fileWriterMock);
+        unset($this->_fileManagerMock);
     }
 
     public function testSaveAclFiles()
@@ -132,7 +132,7 @@ class Tools_Migration_Acl_GeneratorSaveTest extends PHPUnit_Framework_TestCase
                 }
             ));
 
-        $this->_fileWriterMock->expects($this->once())
+        $this->_fileManagerMock->expects($this->once())
             ->method('write')
             ->with(
                 $this->equalTo($this->_aclFile),
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/GeneratorTest.php b/dev/tests/unit/testsuite/tools/migration/Acl/GeneratorTest.php
index 2ac0377e2425c86f4ccedaaedd52a87c34d297f4..4f093c2acd26c4eb3dba472261ec45c77e5aac2b 100644
--- a/dev/tests/unit/testsuite/tools/migration/Acl/GeneratorTest.php
+++ b/dev/tests/unit/testsuite/tools/migration/Acl/GeneratorTest.php
@@ -25,7 +25,7 @@
  */
 
 require_once realpath(dirname(__FILE__) . '/../../../../../../') . '/tools/migration/Acl/Generator.php';
-require_once realpath(dirname(__FILE__) . '/../../../../../../') . '/tools/migration/Acl/FileWriter.php';
+require_once realpath(dirname(__FILE__) . '/../../../../../../') . '/tools/migration/Acl/FileManager.php';
 require_once realpath(dirname(__FILE__) . '/../../../../../../') . '/tools/migration/Acl/Formatter.php';
 
 /**
@@ -58,13 +58,13 @@ class Tools_Migration_Acl_GeneratorTest extends PHPUnit_Framework_TestCase
     /**
      * @var PHPUnit_Framework_MockObject_MockObject
      */
-    protected $_fileWriterMock;
+    protected $_fileManagerMock;
 
     public function setUp()
     {
         $this->_xmlFormatterMock = $this->getMock('Tools_Migration_Acl_Formatter');
-        $this->_fileWriterMock = $this->getMock('Tools_Migration_Acl_FileWriter');
-        $this->_model = new Tools_Migration_Acl_Generator($this->_xmlFormatterMock, $this->_fileWriterMock);
+        $this->_fileManagerMock = $this->getMock('Tools_Migration_Acl_FileManager');
+        $this->_model = new Tools_Migration_Acl_Generator($this->_xmlFormatterMock, $this->_fileManagerMock);
 
         $this->_fixturePath = realpath(__DIR__) . DIRECTORY_SEPARATOR . '_files';
 
@@ -76,8 +76,8 @@ class Tools_Migration_Acl_GeneratorTest extends PHPUnit_Framework_TestCase
         $this->_adminhtmlFiles = array(
             $prefix . 'local' . DIRECTORY_SEPARATOR . 'Namespace' . DIRECTORY_SEPARATOR . 'Module' . $suffix,
             $prefix . 'community' . DIRECTORY_SEPARATOR . 'Namespace' . DIRECTORY_SEPARATOR . 'Module' . $suffix,
-            $prefix . 'core' . DIRECTORY_SEPARATOR . 'Enterprise' . DIRECTORY_SEPARATOR . 'Module' . $suffix,
-            $prefix . 'core' . DIRECTORY_SEPARATOR . 'Mage' . DIRECTORY_SEPARATOR . 'Module' . $suffix,
+            $prefix . 'core' . DIRECTORY_SEPARATOR . 'ANamespace' . DIRECTORY_SEPARATOR . 'Module' . $suffix,
+            $prefix . 'core' . DIRECTORY_SEPARATOR . 'BNamespace' . DIRECTORY_SEPARATOR . 'Module' . $suffix,
         );
 
         $this->_model->setAdminhtmlFiles($this->_adminhtmlFiles);
@@ -85,19 +85,19 @@ class Tools_Migration_Acl_GeneratorTest extends PHPUnit_Framework_TestCase
         $this->_model->setBasePath($this->_fixturePath);
     }
 
-    public function testGetCommentText()
+    /**
+     * @param $file
+     * @param $expected
+     *
+     */
+    public function testGetLicenseTemplate()
     {
-        $expected = PHP_EOL;
-        $expected .= '/**' . PHP_EOL;
-        $expected .= ' * {license_notice}' . PHP_EOL;
-        $expected .= ' *' . PHP_EOL;
-        $expected .= ' * @category    Category' . PHP_EOL;
-        $expected .= ' * @package     Module_Name' . PHP_EOL;
-        $expected .= ' * @copyright   {copyright}' . PHP_EOL;
-        $expected .= ' * @license     {license_link}' . PHP_EOL;
-        $expected .= ' */' . PHP_EOL;
-
-        $this->assertEquals($expected, $this->_model->getCommentText('Category', 'Module_Name'));
+        $this->_fileManagerMock->expects($this->once())
+            ->method('getContents')
+            ->with('someFile')
+            ->will($this->returnValue('<?xml version="1.0"?> <!-- /** license_notice */ -->'));
+        $actual = $this->_model->getLicenseTemplate('someFile');
+        $this->assertEquals(' /** license_notice */ ', $actual);
     }
 
     /**
@@ -111,17 +111,6 @@ class Tools_Migration_Acl_GeneratorTest extends PHPUnit_Framework_TestCase
         $this->assertEquals($expectedModuleName, $this->_model->getModuleName($filePath), 'Incorrect Module Name');
     }
 
-    /**
-     * @param $filePath
-     * @param $expectedCategory
-     *
-     * @dataProvider getCategoryDataProvider
-     */
-    public function testGetCategory($filePath, $expectedCategory)
-    {
-        $this->assertEquals($expectedCategory, $this->_model->getCategory($filePath), 'Incorrect Category Name');
-    }
-
     /**
      * @return array
      */
@@ -130,52 +119,25 @@ class Tools_Migration_Acl_GeneratorTest extends PHPUnit_Framework_TestCase
         return array(
             array(
                 'filePath' => DIRECTORY_SEPARATOR
-                    . 'app ' . DIRECTORY_SEPARATOR
-                    . 'core ' . DIRECTORY_SEPARATOR
-                    . 'Enterprise' . DIRECTORY_SEPARATOR
-                    . 'ModuleOne' . DIRECTORY_SEPARATOR
-                    . 'etc' . DIRECTORY_SEPARATOR
-                    . 'adminhtml.xml',
-                'moduleName' => 'Enterprise_ModuleOne',
-            ),
-            array(
-                'filePath' => DIRECTORY_SEPARATOR
-                    . 'app ' . DIRECTORY_SEPARATOR
-                    . 'core ' . DIRECTORY_SEPARATOR
-                    . 'Mage' . DIRECTORY_SEPARATOR
-                    . 'ModuleOne' . DIRECTORY_SEPARATOR
-                    . 'etc' . DIRECTORY_SEPARATOR
-                    . 'adminhtml.xml',
-                'moduleName' => 'Mage_ModuleOne',
-            ),
-        );
-    }
-
-    /**
-     * @return array
-     */
-    public function getCategoryDataProvider()
-    {
-        return array(
-            array(
-                'filePath' => DIRECTORY_SEPARATOR
-                    . 'app ' . DIRECTORY_SEPARATOR
-                    . 'core ' . DIRECTORY_SEPARATOR
-                    . 'Enterprise' . DIRECTORY_SEPARATOR
+                    . 'app' . DIRECTORY_SEPARATOR
+                    . 'code' . DIRECTORY_SEPARATOR
+                    . 'core' . DIRECTORY_SEPARATOR
+                    . 'ANamespace' . DIRECTORY_SEPARATOR
                     . 'ModuleOne' . DIRECTORY_SEPARATOR
                     . 'etc' . DIRECTORY_SEPARATOR
                     . 'adminhtml.xml',
-                'category' => 'Enterprise',
+                'moduleName' => 'ANamespace_ModuleOne',
             ),
             array(
                 'filePath' => DIRECTORY_SEPARATOR
-                    . 'app ' . DIRECTORY_SEPARATOR
-                    . 'core ' . DIRECTORY_SEPARATOR
-                    . 'Mage' . DIRECTORY_SEPARATOR
+                    . 'app' . DIRECTORY_SEPARATOR
+                    . 'code' . DIRECTORY_SEPARATOR
+                    . 'core' . DIRECTORY_SEPARATOR
+                    . 'BNamespace' . DIRECTORY_SEPARATOR
                     . 'ModuleOne' . DIRECTORY_SEPARATOR
                     . 'etc' . DIRECTORY_SEPARATOR
                     . 'adminhtml.xml',
-                'category' => 'Mage',
+                'moduleName' => 'BNamespace_ModuleOne',
             ),
         );
     }
@@ -323,14 +285,19 @@ class Tools_Migration_Acl_GeneratorTest extends PHPUnit_Framework_TestCase
 
     public function testGetResultDomDocument()
     {
-        $dom = $this->_model->getResultDomDocument('Module_Name', 'Category');
+        $expectedDccument = <<<TEMPLATE
+<config>
+  <acl>
+    <resources xpath="config/acl/resources"/>
+  </acl>
+</config>
+TEMPLATE;
+        $dom = $this->_model->getResultDomDocument('license_placeholder');
         $expectedDom = new DOMDocument();
         $expectedDom->formatOutput = true;
 
-        $file = $this->_fixturePath . DIRECTORY_SEPARATOR . 'template_document.xml';
-        $expectedDom->load($file);
-        $this->assertContains('{license_notice}', $dom->saveXML());
-        $this->assertEquals($expectedDom->saveXML($expectedDom->documentElement), $dom->saveXML($dom->documentElement));
+        $this->assertContains('license_placeholder', $dom->saveXML());
+        $this->assertEquals($expectedDccument, $dom->saveXML($dom->documentElement));
     }
 
     public function testParseAdminhtmlFiles()
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/Menu/GeneratorTest.php b/dev/tests/unit/testsuite/tools/migration/Acl/Menu/GeneratorTest.php
index 183d80a24e7140b5ab3bead6c44fe61180fa3016..361297116e2ce20571c85c353ce3677cc6bf5008 100644
--- a/dev/tests/unit/testsuite/tools/migration/Acl/Menu/GeneratorTest.php
+++ b/dev/tests/unit/testsuite/tools/migration/Acl/Menu/GeneratorTest.php
@@ -54,7 +54,7 @@ class Tools_Migration_Acl_Menu_GeneratorTest extends PHPUnit_Framework_TestCase
     /**
      * @var PHPUnit_Framework_MockObject_MockObject
      */
-    protected $_fileWriterMock;
+    protected $_fileManagerMock;
 
 
     public function setUp()
@@ -67,13 +67,13 @@ class Tools_Migration_Acl_Menu_GeneratorTest extends PHPUnit_Framework_TestCase
             'config/acl/resources/admin/area_config' => 'Module_Name::acl_resource_area',
             'config/acl/resources/admin/some_other_resource' => 'Module_Name::some_other_resource',
         );
-        $this->_fileWriterMock = $this->getMock('Tools_Migration_Acl_FileWriter');
+        $this->_fileManagerMock = $this->getMock('Tools_Migration_Acl_FileManager');
 
         $this->_model = new Tools_Migration_Acl_Menu_Generator(
             $this->_fixturePath,
             array(1),
             $aclXPathToId,
-            $this->_fileWriterMock,
+            $this->_fileManagerMock,
             false
         );
 
@@ -84,8 +84,8 @@ class Tools_Migration_Acl_Menu_GeneratorTest extends PHPUnit_Framework_TestCase
 
         $this->_menuFiles = array(
             $prefix . 'community' . DIRECTORY_SEPARATOR . 'Namespace' . DIRECTORY_SEPARATOR . 'Module' . $suffix,
-            $prefix . 'core' . DIRECTORY_SEPARATOR . 'Enterprise' . DIRECTORY_SEPARATOR . 'Module' . $suffix,
-            $prefix . 'core' . DIRECTORY_SEPARATOR . 'Mage' . DIRECTORY_SEPARATOR . 'Module' . $suffix,
+            $prefix . 'core' . DIRECTORY_SEPARATOR . 'ANamespace' . DIRECTORY_SEPARATOR . 'Module' . $suffix,
+            $prefix . 'core' . DIRECTORY_SEPARATOR . 'BNamespace' . DIRECTORY_SEPARATOR . 'Module' . $suffix,
             $prefix . 'local' . DIRECTORY_SEPARATOR . 'Namespace' . DIRECTORY_SEPARATOR . 'Module' . $suffix,
         );
 
@@ -259,15 +259,15 @@ class Tools_Migration_Acl_Menu_GeneratorTest extends PHPUnit_Framework_TestCase
         );
         $this->_model->setMenuDomList($menuDomList);
 
-        $this->_fileWriterMock->expects($this->at(0))
+        $this->_fileManagerMock->expects($this->at(0))
             ->method('write')
             ->with($this->equalTo('file1'), $this->equalTo($dom->saveXML()));
 
-        $this->_fileWriterMock->expects($this->at(1))
+        $this->_fileManagerMock->expects($this->at(1))
             ->method('write')
             ->with($this->equalTo('file2'), $this->equalTo($dom->saveXML()));
 
-        $this->_fileWriterMock->expects($this->at(2))
+        $this->_fileManagerMock->expects($this->at(2))
             ->method('write')
             ->with($this->equalTo('file3'), $this->equalTo($dom->saveXML()));
 
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/Enterprise/Module/etc/adminhtml.xml b/dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/ANamespace/Module/etc/adminhtml.xml
similarity index 100%
rename from dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/Enterprise/Module/etc/adminhtml.xml
rename to dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/ANamespace/Module/etc/adminhtml.xml
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/Mage/Module/etc/adminhtml/menu.xml b/dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/ANamespace/Module/etc/adminhtml/menu.xml
similarity index 100%
rename from dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/Mage/Module/etc/adminhtml/menu.xml
rename to dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/ANamespace/Module/etc/adminhtml/menu.xml
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/Mage/Module/etc/adminhtml.xml b/dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/BNamespace/Module/etc/adminhtml.xml
similarity index 100%
rename from dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/Mage/Module/etc/adminhtml.xml
rename to dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/BNamespace/Module/etc/adminhtml.xml
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/Enterprise/Module/etc/adminhtml/menu.xml b/dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/BNamespace/Module/etc/adminhtml/menu.xml
similarity index 100%
rename from dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/Enterprise/Module/etc/adminhtml/menu.xml
rename to dev/tests/unit/testsuite/tools/migration/Acl/_files/app/code/core/BNamespace/Module/etc/adminhtml/menu.xml
diff --git a/dev/tests/unit/testsuite/tools/migration/Acl/_files/log/AclXPathToAclId.log b/dev/tests/unit/testsuite/tools/migration/Acl/_files/log/AclXPathToAclId.log
new file mode 100644
index 0000000000000000000000000000000000000000..8cf88f78d10cc542d3de9eec67ff82e68b7eaa47
--- /dev/null
+++ b/dev/tests/unit/testsuite/tools/migration/Acl/_files/log/AclXPathToAclId.log
@@ -0,0 +1 @@
+{"config\/acl\/resources\/admin\/test1\/test2":"Test1_Test2::all","config\/acl\/resources\/admin\/test1\/test2\/test3":"Test1_Test2::test3","config\/acl\/resources\/admin\/test1\/test2\/test4":"Test1_Test2::test4","config\/acl\/resources\/admin\/test1\/test2\/test5":"Test1_Test2::test5","config\/acl\/resources\/admin\/test6":"Test6_Test6::all"}
\ No newline at end of file
diff --git a/dev/tools/migration/Acl/Db/Adapter/Factory.php b/dev/tools/migration/Acl/Db/Adapter/Factory.php
new file mode 100644
index 0000000000000000000000000000000000000000..facb9d0f5fb75aae52e3ecd72bf8f0fb9560550c
--- /dev/null
+++ b/dev/tools/migration/Acl/Db/Adapter/Factory.php
@@ -0,0 +1,59 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category   Magento
+ * @package    tools
+ * @copyright  Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+/**
+ * Db adapters factory
+ */
+class Tools_Migration_Acl_Db_Adapter_Factory
+{
+    /**
+     * Get db adapter
+     *
+     * @param array $config
+     * @param string $type
+     * @throws InvalidArgumentException
+     * @return Zend_Db_Adapter_Abstract
+     */
+    public function getAdapter(array $config, $type = null)
+    {
+        $dbAdapterClassName = 'Varien_Db_Adapter_Pdo_Mysql';
+
+        if (false == empty($type)) {
+            $dbAdapterClassName = $type;
+        }
+
+        if (false == class_exists($dbAdapterClassName, true)) {
+            throw new InvalidArgumentException('Specified adapter not exists: ' . $dbAdapterClassName);
+        }
+        $adapter = new $dbAdapterClassName($config);
+
+        if (false == ($adapter instanceof Zend_Db_Adapter_Abstract)) {
+            unset($adapter);
+            throw new InvalidArgumentException('Specified adapter is not instance of Zend_Db_Adapter_Abstract');
+        }
+        return $adapter;
+    }
+}
diff --git a/dev/tools/migration/Acl/Db/FileReader.php b/dev/tools/migration/Acl/Db/FileReader.php
new file mode 100644
index 0000000000000000000000000000000000000000..81cba10b124a449bfa17d480fc31871415cb480c
--- /dev/null
+++ b/dev/tools/migration/Acl/Db/FileReader.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category   Magento
+ * @package    tools
+ * @copyright  Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+class Tools_Migration_Acl_Db_FileReader
+{
+    /**
+     * Extract resource id map from provided file
+     *
+     * @param string $fileName
+     * @return array
+     * @throws InvalidArgumentException
+     */
+    public function extractData($fileName)
+    {
+        if (empty($fileName)) {
+            throw new InvalidArgumentException('Please specify correct name of a file that contains identifier map');
+        }
+        if (false == file_exists($fileName)) {
+            throw new InvalidArgumentException('Provided identifier map file (' . $fileName . ') doesn\'t exist');
+        }
+        $data = json_decode(file_get_contents($fileName), true);
+
+        $output = array();
+        foreach ($data as $key => $value) {
+            $newKey = str_replace('config/acl/resources/', '', $key);
+            $output[$newKey] = $value;
+        }
+        return $output;
+    }
+}
diff --git a/dev/tools/migration/Acl/Db/Logger/Console.php b/dev/tools/migration/Acl/Db/Logger/Console.php
new file mode 100644
index 0000000000000000000000000000000000000000..632c1f09c20e5889d2866ae5f6d256d0e6d3e3e6
--- /dev/null
+++ b/dev/tools/migration/Acl/Db/Logger/Console.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category   Magento
+ * @package    tools
+ * @copyright  Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+/**
+ * Db migration logger. Output result print to console
+ */
+class Tools_Migration_Acl_Db_Logger_Console extends Tools_Migration_Acl_Db_LoggerAbstract
+{
+    /**
+     * Print logs to console
+     */
+    public function report()
+    {
+        echo $this;
+    }
+}
diff --git a/dev/tools/migration/Acl/Db/Logger/Factory.php b/dev/tools/migration/Acl/Db/Logger/Factory.php
new file mode 100644
index 0000000000000000000000000000000000000000..c63e208e02f7c52b594564a2ca75d0f0e303bd06
--- /dev/null
+++ b/dev/tools/migration/Acl/Db/Logger/Factory.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category   Magento
+ * @package    tools
+ * @copyright  Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+class Tools_Migration_Acl_Db_Logger_Factory
+{
+    /**
+     * List of allowed logger types
+     * @var array
+     */
+    protected $_allowedLoggerTypes = array();
+
+    public function __construct()
+    {
+        $this->_allowedLoggerTypes = array(
+            'console',
+            'file',
+        );
+    }
+
+    /**
+     * @param string $loggerType
+     * @param string $filePath
+     * @return Tools_Migration_Acl_Db_LoggerAbstract
+     * @throws InvalidArgumentException
+     */
+    public function getLogger($loggerType, $filePath = null)
+    {
+        $loggerType = empty($loggerType) ? 'console' : $loggerType;
+        if (false == in_array($loggerType, $this->_allowedLoggerTypes)) {
+            throw new InvalidArgumentException('Invalid logger type: ' . $loggerType);
+        }
+
+        $loggerClassName = null;
+        switch ($loggerType) {
+            case 'file':
+                $loggerClassName = 'Tools_Migration_Acl_Db_Logger_File';
+                break;
+            default:
+                $loggerClassName = 'Tools_Migration_Acl_Db_Logger_Console';
+                break;
+        }
+
+        return new $loggerClassName($filePath);
+    }
+}
diff --git a/dev/tools/migration/Acl/Db/Logger/File.php b/dev/tools/migration/Acl/Db/Logger/File.php
new file mode 100644
index 0000000000000000000000000000000000000000..9f1bed50bf99793376dca58c105c380f286f8590
--- /dev/null
+++ b/dev/tools/migration/Acl/Db/Logger/File.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category   Magento
+ * @package    tools
+ * @copyright  Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+/**
+ * Db migration logger. Output result put to file
+ */
+class Tools_Migration_Acl_Db_Logger_File extends Tools_Migration_Acl_Db_LoggerAbstract
+{
+    /**
+     * Path to log file
+     *
+     * @var string
+     */
+    protected $_file = null;
+
+    public function __construct($file)
+    {
+        $logDir = realpath(__DIR__ . '/../../') . '/log/';
+        if (false == is_dir($logDir)) {
+            mkdir($logDir, 0777, true);
+        }
+        if (false == is_writeable($logDir)) {
+            throw new InvalidArgumentException('Directory ' . dirname($logDir) . ' is not writeable');
+        }
+
+        if (empty($file)) {
+            throw new InvalidArgumentException('Log file name is required');
+        }
+        $this->_file = $logDir . $file;
+    }
+
+    /**
+     * Put report to file
+     */
+    public function report()
+    {
+        file_put_contents($this->_file, (string)$this);
+    }
+}
+
diff --git a/dev/tools/migration/Acl/Db/LoggerAbstract.php b/dev/tools/migration/Acl/Db/LoggerAbstract.php
new file mode 100644
index 0000000000000000000000000000000000000000..354c2ff7b54978dd1b4be2827a9f0246ff57f0fc
--- /dev/null
+++ b/dev/tools/migration/Acl/Db/LoggerAbstract.php
@@ -0,0 +1,116 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category   Magento
+ * @package    tools
+ * @copyright  Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+/**
+ * DB migration logger
+ */
+abstract class Tools_Migration_Acl_Db_LoggerAbstract
+{
+    /**
+     * List of logs
+     *
+     * @var array
+     */
+    protected $_logs = array();
+
+    /**
+     * Convert list of logs to nice text block
+     *
+     * @param string $message block header text
+     * @param array $list list of logs
+     * @return string
+     */
+    protected function _logsListToString($message, $list)
+    {
+        $outputString = $message . ':' . PHP_EOL;
+        $outputString .= implode(PHP_EOL, $list);
+        $outputString .= PHP_EOL . str_repeat('-', 30) . PHP_EOL;
+
+        return $outputString;
+    }
+
+    /**
+     * Add log data
+     *
+     * @param string $oldKey
+     * @param string $newKey
+     * @param int|null $updateResult
+     * @return Tools_Migration_Acl_Db_LoggerAbstract
+     */
+    public function add($oldKey, $newKey, $updateResult)
+    {
+        if (empty($oldKey)) {
+            $oldKey = $newKey;
+        }
+        $this->_logs[$oldKey]['newKey'] = $newKey;
+        $this->_logs[$oldKey]['updateResult'] = $updateResult;
+        return $this;
+    }
+
+    /**
+     * Convert logger object to string
+     *
+     * @return string
+     */
+    public function __toString()
+    {
+        $output = array(
+            'Mapped items' => array(),
+            'Not mapped items' => array(),
+            'Items in actual format' => array(),
+        );
+        foreach ($this->_logs as $oldKey => $data) {
+            $newKey = $data['newKey'];
+            $countItems = $data['updateResult'];
+
+            if ($oldKey == $newKey) {
+                $output['Items in actual format'][$oldKey] = $oldKey;
+            } elseif (empty($newKey)) {
+                $output['Not mapped items'][$oldKey] = $oldKey;
+            } else {
+                $output['Mapped items'][$oldKey] = $oldKey . ' => ' . $newKey
+                    . ' :: Count updated rules: ' . $countItems;
+            }
+        }
+
+        $generalBlock = $detailsBlock = '';
+        foreach ($output as $key => $data) {
+            $generalBlock .= $key . ' count: ' . count($data) . PHP_EOL;
+            if (count($data)) {
+                $detailsBlock .= $this->_logsListToString($key, $data);
+            }
+        }
+        return $generalBlock . str_repeat('-', 30) . PHP_EOL . $detailsBlock;
+    }
+
+    /**
+     * Generate report
+     *
+     * @abstract
+     * @return mixed
+     */
+    public abstract function report();
+}
diff --git a/dev/tools/migration/Acl/Db/Reader.php b/dev/tools/migration/Acl/Db/Reader.php
new file mode 100644
index 0000000000000000000000000000000000000000..c598d22f01c804182d6698e73505e369b3ec5208
--- /dev/null
+++ b/dev/tools/migration/Acl/Db/Reader.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category   Magento
+ * @package    tools
+ * @copyright  Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+/**
+ * Db adapter. Reader.
+ * Get unique acl resource identifiers from source table
+ */
+class Tools_Migration_Acl_Db_Reader
+{
+    /**
+     * Source table name
+     *
+     * @var string
+     */
+    protected $_tableName;
+
+    /**
+     * DB adapter
+     *
+     * @var Zend_Db_Adapter_Abstract
+     */
+    protected $_adapter;
+
+    /**
+     * @param Zend_Db_Adapter_Abstract $adapter
+     * @param string $tableName source table
+     */
+    public function __construct(Zend_Db_Adapter_Abstract $adapter, $tableName)
+    {
+        $this->_tableName = $tableName;
+        $this->_adapter = $adapter;
+    }
+
+    /**
+     * Get list of unique resource identifiers
+     * Format: [resource] => [count items]
+     * @return array
+     */
+    public function fetchAll()
+    {
+        $select = $this->_adapter->select();
+        $select->from($this->_tableName, array())
+            ->columns(array('resource_id' => 'resource_id', 'itemsCount' => new Zend_Db_Expr('count(*)')))
+            ->group('resource_id');
+        return $this->_adapter->fetchPairs($select);
+    }
+}
+
+
diff --git a/dev/tools/migration/Acl/Db/Updater.php b/dev/tools/migration/Acl/Db/Updater.php
new file mode 100644
index 0000000000000000000000000000000000000000..be1e7df72032ef64d6576fa669909687f6ff725f
--- /dev/null
+++ b/dev/tools/migration/Acl/Db/Updater.php
@@ -0,0 +1,96 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category   Magento
+ * @package    tools
+ * @copyright  Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+class Tools_Migration_Acl_Db_Updater
+{
+    const WRITE_MODE = 'write';
+
+    /**
+     * Resource id reader
+     *
+     * @var Tools_Migration_Acl_Db_Reader
+     */
+    protected $_reader;
+
+    /**
+     * Resource id writer
+     *
+     * @var Tools_Migration_Acl_Db_Writer
+     */
+    protected $_writer;
+
+    /**
+     * Operation logger
+     *
+     * @var Tools_Migration_Acl_Db_LoggerAbstract
+     */
+    protected $_logger;
+
+    /**
+     * Migration mode
+     *
+     * @var string
+     */
+    protected $_mode;
+
+    /**
+     * @param Tools_Migration_Acl_Db_Reader $reader
+     * @param Tools_Migration_Acl_Db_Writer $writer
+     * @param Tools_Migration_Acl_Db_LoggerAbstract $logger
+     * @param string $mode - if value is "preview" migration does not happen
+     */
+    public function __construct(
+        Tools_Migration_Acl_Db_Reader $reader,
+        Tools_Migration_Acl_Db_Writer $writer,
+        Tools_Migration_Acl_Db_LoggerAbstract $logger,
+        $mode
+    ) {
+        $this->_reader = $reader;
+        $this->_writer = $writer;
+        $this->_logger = $logger;
+        $this->_mode = $mode;
+    }
+
+    /**
+     * Migrate old keys to new
+     *
+     * @param array $map
+     */
+    public function migrate($map)
+    {
+        foreach ($this->_reader->fetchAll() as $oldKey => $count) {
+            $newKey = isset($map[$oldKey]) ? $map[$oldKey] : null;
+            if (in_array($oldKey, $map)) {
+                $newKey = $oldKey;
+                $oldKey = null;
+            }
+            if ($newKey && $oldKey && $this->_mode == self::WRITE_MODE) {
+                $this->_writer->update($oldKey, $newKey);
+            }
+            $this->_logger->add($oldKey, $newKey, $count);
+        }
+    }
+}
diff --git a/dev/tools/migration/Acl/Db/Writer.php b/dev/tools/migration/Acl/Db/Writer.php
new file mode 100644
index 0000000000000000000000000000000000000000..c304adaa35c74a2607b5d4dfcbfd1232444cef4e
--- /dev/null
+++ b/dev/tools/migration/Acl/Db/Writer.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category   Magento
+ * @package    tools
+ * @copyright  Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+class Tools_Migration_Acl_Db_Writer
+{
+    /**
+     * DB adapter
+     *
+     * @var Zend_Db_Adapter_Abstract
+     */
+    protected $_adapter;
+
+    /**
+     * Source table name
+     *
+     * @var string
+     */
+    protected $_tableName;
+
+    /**
+     * @param Zend_Db_Adapter_Abstract $adapter
+     * @param string $tableName source table
+     */
+    public function __construct(Zend_Db_Adapter_Abstract $adapter, $tableName)
+    {
+        $this->_tableName = $tableName;
+        $this->_adapter = $adapter;
+    }
+
+    /**
+     * Update records in database
+     *
+     * @param $oldKey
+     * @param $newKey
+     */
+    public function update($oldKey, $newKey)
+    {
+        $this->_adapter->update($this->_tableName,
+            array('resource_id' => $newKey),
+            array('resource_id = ?' => $oldKey)
+        );
+    }
+}
diff --git a/dev/tools/migration/Acl/FileWriter.php b/dev/tools/migration/Acl/FileManager.php
similarity index 84%
rename from dev/tools/migration/Acl/FileWriter.php
rename to dev/tools/migration/Acl/FileManager.php
index 3761d63f578bf47ac377569e49ab5885a9788879..ade090f193a6d4e98fb729be6d5dfd43f6ced700 100644
--- a/dev/tools/migration/Acl/FileWriter.php
+++ b/dev/tools/migration/Acl/FileManager.php
@@ -24,7 +24,7 @@
  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  */
 
-class Tools_Migration_Acl_FileWriter
+class Tools_Migration_Acl_FileManager
 {
     /**
      * @param string $fileName
@@ -47,4 +47,15 @@ class Tools_Migration_Acl_FileWriter
     {
         unlink($fileName);
     }
+
+    /**
+     * Retrieve contents of a file
+     *
+     * @param string $fileName
+     * @return string
+     */
+    public function getContents($fileName)
+    {
+        return file_get_contents($fileName);
+    }
 }
diff --git a/dev/tools/migration/Acl/Generator.php b/dev/tools/migration/Acl/Generator.php
index 3dda9e046d42020a6b21f24213a7177cd92cd4a9..2db187f02dfefd897e15cef1c189af480510e5dd 100644
--- a/dev/tools/migration/Acl/Generator.php
+++ b/dev/tools/migration/Acl/Generator.php
@@ -24,7 +24,7 @@
  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  */
 require_once ( __DIR__ . '/Menu/Generator.php');
-require_once ( __DIR__ . '/FileWriter.php');
+require_once ( __DIR__ . '/FileManager.php');
 
 class Tools_Migration_Acl_Generator
 {
@@ -106,22 +106,22 @@ class Tools_Migration_Acl_Generator
     protected $_xmlFormatter;
 
     /**
-     * @var Tools_Migration_Acl_FileWriter
+     * @var Tools_Migration_Acl_FileManager
      */
-    protected $_fileWriter;
+    protected $_fileManager;
 
     /**
      * @param Tools_Migration_Acl_Formatter $xmlFormatter
-     * @param Tools_Migration_Acl_FileWriter $fileWriter
+     * @param Tools_Migration_Acl_FileManager $fileManager
      * @param array $options configuration options
      */
     public function __construct(
         Tools_Migration_Acl_Formatter $xmlFormatter,
-        Tools_Migration_Acl_FileWriter $fileWriter,
+        Tools_Migration_Acl_FileManager $fileManager,
         $options = array()
     ) {
         $this->_xmlFormatter = $xmlFormatter;
-        $this->_fileWriter = $fileWriter;
+        $this->_fileManager = $fileManager;
         $this->_printHelp = array_key_exists('h', $options);
         $this->_isPreviewMode = array_key_exists('p', $options);
 
@@ -136,25 +136,21 @@ class Tools_Migration_Acl_Generator
     }
 
     /**
-     * Get Comment text
+     * Get License Template for a file
      *
-     * @param $category string
-     * @param $package string
+     * @param $file string File path
      * @return string
      */
-    public function getCommentText($category, $package)
+    public function getLicenseTemplate($file)
     {
-        $comment = PHP_EOL;
-        $comment .= '/**' . PHP_EOL;
-        $comment .= ' * {license_notice}' . PHP_EOL;
-        $comment .= ' *' . PHP_EOL;
-        $comment .= ' * @category    ' . $category . PHP_EOL;
-        $comment .= ' * @package     ' . $package . PHP_EOL;
-        $comment .= ' * @copyright   {copyright}' . PHP_EOL;
-        $comment .= ' * @license     {license_link}' . PHP_EOL;
-        $comment .= ' */' . PHP_EOL;
+        $content = $this->_fileManager->getContents($file);
 
-        return $comment;
+        $licenseTemplate = '';
+        if (preg_match('#<\?xml[^>]+>\s+<\!--(\s+/\*\*[\w\W\d\s]+\*/\s+)-->#', $content, $matches)) {
+            $licenseTemplate = $matches[1];
+        }
+
+        return $licenseTemplate;
     }
 
     /**
@@ -170,18 +166,6 @@ class Tools_Migration_Acl_Generator
         return $module;
     }
 
-    /**
-     * Get category name from file name
-     *
-     * @param $fileName string
-     * @return string
-     */
-    public function getCategory($fileName)
-    {
-        $parts = array_reverse(explode(DIRECTORY_SEPARATOR, $fileName));
-        return $parts[3];
-    }
-
     /**
      * Get is forward node
      *
@@ -363,9 +347,8 @@ class Tools_Migration_Acl_Generator
         if (null === $this->_adminhtmlFiles) {
             $localFiles = glob($this->getEtcDirPattern('local') . 'adminhtml.xml');
             $communityFiles = glob($this->getEtcDirPattern('community') . 'adminhtml.xml');
-            $coreEnterpriseFiles = glob($this->getEtcDirPattern('core', 'Enterprise') . 'adminhtml.xml');
-            $coreMageFiles = glob($this->getEtcDirPattern('core', 'Mage') . 'adminhtml.xml');
-            $this->_adminhtmlFiles = array_merge($localFiles, $communityFiles, $coreEnterpriseFiles, $coreMageFiles);
+            $coreFiles = glob($this->getEtcDirPattern('core') . 'adminhtml.xml');
+            $this->_adminhtmlFiles = array_merge($localFiles, $communityFiles, $coreFiles);
         }
         return $this->_adminhtmlFiles;
     }
@@ -443,16 +426,16 @@ class Tools_Migration_Acl_Generator
 
     /**
      * Get template for result DOMDocument
-     * @param $module
-     * @param $category
+     *
+     * @param $licenseTemplate
      * @return DOMDocument
      */
-    public function getResultDomDocument($module, $category)
+    public function getResultDomDocument($licenseTemplate)
     {
         $resultDom = new DOMDocument();
         $resultDom->formatOutput = true;
 
-        $comment = $resultDom->createComment($this->getCommentText($category, $module));
+        $comment = $resultDom->createComment($licenseTemplate);
         $resultDom->appendChild($comment);
 
         $config = $resultDom->createElement('config');
@@ -474,8 +457,8 @@ class Tools_Migration_Acl_Generator
     {
         foreach ($this->getAdminhtmlFiles() as $file) {
             $module = $this->getModuleName($file);
-            $category = $this->getCategory($file);
-            $resultDom = $this->getResultDomDocument($module, $category);
+            $licenseTemplate = $this->getLicenseTemplate($file);
+            $resultDom = $this->getResultDomDocument($licenseTemplate);
 
             $adminhtmlDom = new DOMDocument();
             $adminhtmlDom->load($file);
@@ -568,7 +551,7 @@ class Tools_Migration_Acl_Generator
                 'indent-spaces' => 4,
                 'wrap' => 1000
             ));
-            $this->_fileWriter->write($file, $output);
+            $this->_fileManager->write($file, $output);
         }
     }
 
@@ -623,7 +606,7 @@ class Tools_Migration_Acl_Generator
             }
             if ($this->isNodeEmpty($acl)) {
                 if (false == $this->_isPreviewMode) {
-                    $this->_fileWriter->remove($file);
+                    $this->_fileManager->remove($file);
                 }
                 $output['removed'][] = $file;
             } else {
@@ -745,7 +728,7 @@ class Tools_Migration_Acl_Generator
     public function saveArtifacts($artifacts)
     {
         foreach ($artifacts as $file => $data) {
-            $this->_fileWriter->write($this->_artifactsPath . $file, $data);
+            $this->_fileManager->write($this->_artifactsPath . $file, $data);
         }
     }
 
@@ -760,6 +743,7 @@ class Tools_Migration_Acl_Generator
             $this->getBasePath(),
             $this->getValidNodeTypes(),
             $this->_aclResourceMaps,
+            $this->_fileManager,
             $this->_isPreviewMode
         );
         return $menu->run();
diff --git a/dev/tools/migration/Acl/Menu/Generator.php b/dev/tools/migration/Acl/Menu/Generator.php
index 62f4666f675fa70ed51edce95cfa070ef51095db..9d81e39f62f1147f3e159fe66cb2b159e86a3c78 100644
--- a/dev/tools/migration/Acl/Menu/Generator.php
+++ b/dev/tools/migration/Acl/Menu/Generator.php
@@ -79,26 +79,26 @@ class Tools_Migration_Acl_Menu_Generator
     protected $_isPreviewMode;
 
     /**
-     * @var Tools_Migration_Acl_FileWriter
+     * @var Tools_Migration_Acl_FileManager
      */
-    protected $_fileWriter;
+    protected $_fileManager;
 
 
     /**
      * @param $basePath
      * @param $validNodeTypes
      * @param $aclXPathToId
-     * @param Tools_Migration_Acl_FileWriter $fileWriter
+     * @param Tools_Migration_Acl_FileManager $fileManager
      * @param bool $preview
      */
     public function __construct(
         $basePath,
         $validNodeTypes,
         $aclXPathToId,
-        Tools_Migration_Acl_FileWriter $fileWriter,
+        Tools_Migration_Acl_FileManager $fileManager,
         $preview = true
     ) {
-        $this->_fileWriter = $fileWriter;
+        $this->_fileManager = $fileManager;
         $this->_basePath = $basePath;
         $this->_validNodeTypes = $validNodeTypes;
         $this->_aclXPathToId = $aclXPathToId;
@@ -402,7 +402,7 @@ class Tools_Migration_Acl_Menu_Generator
         /** @var $dom DOMDocument **/
         foreach ($this->_menuDomList as $file => $dom) {
             $dom->formatOutput = true;
-            $this->_fileWriter->write($file, $dom->saveXML());
+            $this->_fileManager->write($file, $dom->saveXML());
         }
     }
 
diff --git a/dev/tools/migration/Acl/db.php b/dev/tools/migration/Acl/db.php
new file mode 100644
index 0000000000000000000000000000000000000000..5d5151b3581d4d1af4596d1fd021bd5644e89787
--- /dev/null
+++ b/dev/tools/migration/Acl/db.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category   Tools
+ * @package    acl_db
+ * @copyright  Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+$rootDir = realpath(__DIR__ . '/../../../..');
+require_once $rootDir . '/lib/Magento/Autoload.php';
+$paths[] = $rootDir . '/lib';
+$paths[] = $rootDir . '/dev';
+Magento_Autoload::getInstance()->addIncludePath($paths);
+$defaultReportFile = 'report.log';
+
+try {
+    $options = new Zend_Console_Getopt(array(
+        'file=s' => "File containing json encoded acl identifier map (old => new)",
+        'mode|w' => "Application mode.  Preview mode is default. If set to 'write' - database is updated.",
+        'output|f-w' => "Report output type. Report is flushed to console by default."
+            . "If set to 'file', report is written to file /log/report.log",
+        'dbprovider=w' => "Database adapter class name. Default: Varien_Db_Adapter_Pdo_Mysql",
+        'dbhost=s' => "Database server host",
+        'dbuser=s' => "Database server user",
+        'dbpassword=s' => "Database server password",
+        'dbname=s' => "Database name",
+        'dbtable=s' => "Table containing resource ids",
+    ));
+
+    $fileReader = new Tools_Migration_Acl_Db_FileReader();
+
+    $map = $fileReader->extractData($options->getOption('file'));
+
+    $dbAdapterFactory = new Tools_Migration_Acl_Db_Adapter_Factory();
+
+    $dbAdapter = $dbAdapterFactory->getAdapter(
+        $dbConfig = array(
+            'host' => $options->getOption('dbhost'),
+            'username' => $options->getOption('dbuser'),
+            'password' => $options->getOption('dbpassword'),
+            'dbname' => $options->getOption('dbname'),
+        ),
+        $options->getOption('dbprovider')
+    );
+
+    $loggerFactory = new Tools_Migration_Acl_Db_Logger_Factory();
+    $logger = $loggerFactory->getLogger($options->getOption('output'), $defaultReportFile);
+
+    $writer = new Tools_Migration_Acl_Db_Writer($dbAdapter, $options->getOption('dbtable'));
+    $reader = new Tools_Migration_Acl_Db_Reader($dbAdapter, $options->getOption('dbtable'));
+
+    $updater = new Tools_Migration_Acl_Db_Updater($reader, $writer, $logger, $options->getOption('mode'));
+    $updater->migrate($map);
+
+    $logger->report();
+} catch (Zend_Console_Getopt_Exception $e) {
+    echo $e->getUsageMessage();
+    exit;
+} catch (InvalidArgumentException $exp) {
+    echo $exp->getMessage();
+} catch (Exception $exp) {
+    echo $exp->getMessage();
+}
diff --git a/dev/tools/migration/acl.php b/dev/tools/migration/acl.php
index 09b99325e44aa2dd200b50256a93a502ed1b83d4..7a2c178bd549423a7e0920f47e3df11704494330 100644
--- a/dev/tools/migration/acl.php
+++ b/dev/tools/migration/acl.php
@@ -25,7 +25,7 @@
  */
 
 require_once ('./Acl/Generator.php');
-require_once ('./Acl/FileWriter.php');
+require_once ('./Acl/FileManager.php');
 require_once ('./Acl/Formatter.php');
 
 $shortOpts = 'ph';
@@ -33,7 +33,7 @@ $options = getopt($shortOpts);
 try {
     $tool = new Tools_Migration_Acl_Generator(
         new Tools_Migration_Acl_Formatter(),
-        new Tools_Migration_Acl_FileWriter(), $options
+        new Tools_Migration_Acl_FileManager(), $options
     );
     $tool->run();
 } catch (Exception $exp) {
diff --git a/downloader/Maged/Model/Session.php b/downloader/Maged/Model/Session.php
index fd027677bbc026a365d90c70aa8c3a3daa869d23..5cd3923d6e8f01047366c80864a3cdb4c5579646 100644
--- a/downloader/Maged/Model/Session.php
+++ b/downloader/Maged/Model/Session.php
@@ -138,7 +138,7 @@ class Maged_Model_Session extends Maged_Model
             $this->addMessage('error', 'Invalid user name or password');
             $this->controller()->setAction('login');
         } elseif ($this->getUserId() || ($user && $user->getId())) {
-            if ($this->_session->isAllowed('Mage_Adminhtml::all')) {
+            if (Mage::getSingleton('Mage_Core_Model_Authorization')->isAllowed('Mage_Adminhtml::all')) {
                 return true;
             } else {
                 $this->logout();
diff --git a/app/code/core/Mage/Backend/Model/Acl/Config/Reader.php b/lib/Magento/Acl/Config/Reader.php
similarity index 87%
rename from app/code/core/Mage/Backend/Model/Acl/Config/Reader.php
rename to lib/Magento/Acl/Config/Reader.php
index c7bd8562400fe8e29ae0ca35a889b2a8cdafc60a..5098a04f216b4ab0326ca2923be2878dc7fe11e9 100644
--- a/app/code/core/Mage/Backend/Model/Acl/Config/Reader.php
+++ b/lib/Magento/Acl/Config/Reader.php
@@ -18,21 +18,22 @@
  * versions in the future. If you wish to customize Magento for your
  * needs please refer to http://www.magentocommerce.com for more information.
  *
- * @category    Mage
- * @package     Mage_Backend
+ * @category    Magento
+ * @package     Framework
+ * @subpackage  ACL
  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  */
 
 /**
- * Backend Acl Resources reader
+ * Magento Acl Resources reader
  *
- * @category    Mage
- * @package     Mage_Backend
+ * @category    Magento
+ * @package     Framework
  * @author      Magento Core Team <core@magentocommerce.com>
  */
-class Mage_Backend_Model_Acl_Config_Reader extends Magento_Config_XmlAbstract
-    implements Mage_Backend_Model_Acl_Config_ReaderInterface
+class Magento_Acl_Config_Reader extends Magento_Config_XmlAbstract
+    implements Magento_Acl_Config_ReaderInterface
 {
     /**
      * Get absolute path to the XML-schema file
@@ -82,7 +83,7 @@ class Mage_Backend_Model_Acl_Config_Reader extends Magento_Config_XmlAbstract
     protected function _getDomConfigModel()
     {
         if (is_null($this->_domConfig)) {
-            $this->_domConfig = new Mage_Backend_Model_Acl_Config_Reader_Dom(
+            $this->_domConfig = new Magento_Acl_Config_Reader_Dom(
                 $this->_getInitialXml(),
                 $this->_getIdAttributes()
             );
diff --git a/app/code/core/Mage/Backend/Model/Acl/Config/Reader/Dom.php b/lib/Magento/Acl/Config/Reader/Dom.php
similarity index 87%
rename from app/code/core/Mage/Backend/Model/Acl/Config/Reader/Dom.php
rename to lib/Magento/Acl/Config/Reader/Dom.php
index 8724baf3416bae39415e144bf861ecedaff1c83f..f2093becdea8ee0e0760a088bddc71fa1c123223 100644
--- a/app/code/core/Mage/Backend/Model/Acl/Config/Reader/Dom.php
+++ b/lib/Magento/Acl/Config/Reader/Dom.php
@@ -18,18 +18,19 @@
  * versions in the future. If you wish to customize Magento for your
  * needs please refer to http://www.magentocommerce.com for more information.
  *
- * @category    Mage
- * @package     Mage_Backend
+ * @category    Magento
+ * @package     Framework
+ * @subpackage  ACL
  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  */
 
 /**
- * @category    Mage
- * @package     Mage_Backend
+ * @category    Magento
+ * @package     Framework
  * @author      Magento Core Team <core@magentocommerce.com>
  */
-class Mage_Backend_Model_Acl_Config_Reader_Dom extends Magento_Config_Dom
+class Magento_Acl_Config_Reader_Dom extends Magento_Config_Dom
 {
     /**
      * Return attribute for resource node that identify it as unique
diff --git a/app/code/core/Mage/Backend/Model/Acl/Config/ReaderInterface.php b/lib/Magento/Acl/Config/ReaderInterface.php
similarity index 87%
rename from app/code/core/Mage/Backend/Model/Acl/Config/ReaderInterface.php
rename to lib/Magento/Acl/Config/ReaderInterface.php
index aa066d7c1137d1fd04c11778bb47f5ddada0ce27..5f7f17c76f5877dc1df457cc45d0604ea06d23b0 100644
--- a/app/code/core/Mage/Backend/Model/Acl/Config/ReaderInterface.php
+++ b/lib/Magento/Acl/Config/ReaderInterface.php
@@ -18,8 +18,9 @@
  * versions in the future. If you wish to customize Magento for your
  * needs please refer to http://www.magentocommerce.com for more information.
  *
- * @category    Mage
- * @package     Mage_Backend
+ * @category    Magento
+ * @package     Framework
+ * @subpackage  ACL
  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  */
@@ -28,11 +29,11 @@
 /**
  * Acl resources reader interface
  *
- * @category    Mage
- * @package     Mage_Backend
+ * @category    Magento
+ * @package     Framework
  * @author      Magento Core Team <core@magentocommerce.com>
  */
-interface Mage_Backend_Model_Acl_Config_ReaderInterface
+interface Magento_Acl_Config_ReaderInterface
 {
     /**
      * Retrieve ACL resources
diff --git a/app/code/core/Mage/Backend/Model/Acl/Config/acl.xsd b/lib/Magento/Acl/Config/acl.xsd
similarity index 100%
rename from app/code/core/Mage/Backend/Model/Acl/Config/acl.xsd
rename to lib/Magento/Acl/Config/acl.xsd
diff --git a/lib/Magento/Authorization/Policy.php b/lib/Magento/Authorization/Policy.php
new file mode 100644
index 0000000000000000000000000000000000000000..7228ab8e0618f44e019c531e4cfb82699404d947
--- /dev/null
+++ b/lib/Magento/Authorization/Policy.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Magento
+ * @package     Framework
+ * @subpackage  Authorization
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+interface Magento_Authorization_Policy
+{
+    /**
+     * Check whether given role has access to given resource
+     *
+     * @abstract
+     * @param string $roleId
+     * @param string $resourceId
+     * @param mixed $privilege
+     * @return bool
+     */
+    public function isAllowed($roleId, $resourceId, $privilege = null);
+}
diff --git a/lib/Magento/Authorization/Policy/Acl.php b/lib/Magento/Authorization/Policy/Acl.php
new file mode 100644
index 0000000000000000000000000000000000000000..da9bd2350a8ca5a38f6ad5f386a64385e825d5d4
--- /dev/null
+++ b/lib/Magento/Authorization/Policy/Acl.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Magento
+ * @package     Framework
+ * @subpackage  Authorization
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+/**
+ * Uses ACL to control access. If ACL doesn't contain provided resource,
+ * permission for all resources is checked
+ */
+class Magento_Authorization_Policy_Acl implements Magento_Authorization_Policy
+{
+    /**
+     * @var Magento_Acl
+     */
+    protected $_acl;
+
+    /**
+     * @param Magento_Acl $acl
+     */
+    public function __construct(Magento_Acl $acl)
+    {
+        $this->_acl = $acl;
+    }
+
+    /**
+     * Check whether given role has access to give id
+     *
+     * @param string $roleId
+     * @param string $resourceId
+     * @param mixed $privilege
+     * @return bool
+     */
+    public function isAllowed($roleId, $resourceId, $privilege = null)
+    {
+        try {
+            return $this->_acl->isAllowed($roleId, $resourceId, $privilege);
+        } catch (Exception $e) {
+            try {
+                if (!$this->_acl->has($resourceId)) {
+                    return $this->_acl->isAllowed($roleId, null, $privilege);
+                }
+            } catch (Exception $e) {
+            }
+        }
+        return false;
+    }
+}
diff --git a/lib/Magento/Authorization/Policy/Default.php b/lib/Magento/Authorization/Policy/Default.php
new file mode 100644
index 0000000000000000000000000000000000000000..edfebf7de478fb6f85b6c2a8f8f793bf8c9a1054
--- /dev/null
+++ b/lib/Magento/Authorization/Policy/Default.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Magento
+ * @package     Framework
+ * @subpackage  Authorization
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+/**
+ * Default authorization policy. Allows access to all resources
+ */
+class Magento_Authorization_Policy_Default implements Magento_Authorization_Policy
+{
+    /**
+     * Check whether given role has access to give id
+     *
+     * @param string $roleId
+     * @param string $resourceId
+     * @param mixed $privilege
+     * @return bool
+     */
+    public function isAllowed($roleId, $resourceId, $privilege = null)
+    {
+        return true;
+    }
+}
diff --git a/lib/Magento/Authorization/RoleLocator.php b/lib/Magento/Authorization/RoleLocator.php
new file mode 100644
index 0000000000000000000000000000000000000000..f5d5be6087aeb81fc8d534a1cd345afe9157dc6b
--- /dev/null
+++ b/lib/Magento/Authorization/RoleLocator.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Magento
+ * @package     Framework
+ * @subpackage  Authorization
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+interface Magento_Authorization_RoleLocator
+{
+    /**
+     * Retrieve current role
+     *
+     * @return string
+     */
+    public function getAclRoleId();
+}
diff --git a/lib/Magento/Authorization/RoleLocator/Default.php b/lib/Magento/Authorization/RoleLocator/Default.php
new file mode 100644
index 0000000000000000000000000000000000000000..1139a71453f69d0dd0222e84edaaf8f5a6f705a0
--- /dev/null
+++ b/lib/Magento/Authorization/RoleLocator/Default.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category    Magento
+ * @package     Framework
+ * @subpackage  Authorization
+ * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */
+
+class Magento_Authorization_RoleLocator_Default implements Magento_Authorization_RoleLocator
+{
+    /**
+     * Retrieve current role
+     *
+     * @return string
+     */
+    public function getAclRoleId()
+    {
+        return '';
+    }
+}
diff --git a/lib/Magento/Data/Structure.php b/lib/Magento/Data/Structure.php
index 3c20e3aac08bc917ba68f2a9f2529ea4f74693cc..cf2e45d0879048c7d75fc8cbce5e0204c27ae2de 100644
--- a/lib/Magento/Data/Structure.php
+++ b/lib/Magento/Data/Structure.php
@@ -293,6 +293,7 @@ class Magento_Data_Structure
      *
      * @param string $elementId ID of an element or its parent element
      * @param string|null $alias
+     * @return Magento_Data_Structure
      */
     public function unsetChild($elementId, $alias = null)
     {
@@ -309,6 +310,7 @@ class Magento_Data_Structure
                 unset($this->_elements[$parentId][self::CHILDREN]);
             }
         }
+        return $this;
     }
 
     /**
@@ -340,8 +342,7 @@ class Magento_Data_Structure
                 }
             }
         }
-        $this->unsetChild($childId);
-        $this->_insertChild($parentId, $childId, $offset, $alias);
+        $this->unsetChild($childId)->_insertChild($parentId, $childId, $offset, $alias);
         return $this->_getChildOffset($parentId, $childId) + 1;
     }
 
@@ -369,8 +370,7 @@ class Magento_Data_Structure
             return $this->reorderChild($parentId, $childId, $newOffset);
         }
         $alias = $this->getChildAlias($parentId, $childId);
-        $this->unsetChild($childId);
-        $newOffset = $this->_getRelativeOffset($parentId, $siblingId, $offset);
+        $newOffset = $this->unsetChild($childId)->_getRelativeOffset($parentId, $siblingId, $offset);
         $this->_insertChild($parentId, $childId, $newOffset, $alias);
         return $this->_getChildOffset($parentId, $childId) + 1;
     }
diff --git a/lib/Varien/Simplexml/Element.php b/lib/Varien/Simplexml/Element.php
index a15471524d3ab528a2650ad7233b459e47930ba8..d86785da4066b4bc42fe2eddd46cd815cdf2b250 100644
--- a/lib/Varien/Simplexml/Element.php
+++ b/lib/Varien/Simplexml/Element.php
@@ -53,7 +53,7 @@ class Varien_Simplexml_Element extends SimpleXMLElement
      */
     public function setParent($element)
     {
-        #$this->_parent = $element;
+        //$this->_parent = $element;
     }
 
     /**
@@ -61,6 +61,7 @@ class Varien_Simplexml_Element extends SimpleXMLElement
      *
      * Currently using xpath
      *
+     * @throws InvalidArgumentException
      * @return Varien_Simplexml_Element
      */
     public function getParent()
@@ -69,6 +70,9 @@ class Varien_Simplexml_Element extends SimpleXMLElement
             $parent = $this->_parent;
         } else {
             $arr = $this->xpath('..');
+            if (!isset($arr[0])) {
+                throw new InvalidArgumentException('Root node could not be unset.');
+            }
             $parent = $arr[0];
         }
         return $parent;
@@ -95,7 +99,8 @@ class Varien_Simplexml_Element extends SimpleXMLElement
     /**
      * Returns attribute value by attribute name
      *
-     * @return string
+     * @param string $name
+     * @return string|null
      */
     public function getAttribute($name){
         $attrs = $this->attributes();
@@ -497,6 +502,24 @@ class Varien_Simplexml_Element extends SimpleXMLElement
         return $this;
     }
 
+    /**
+     * Unset self from the XML-node tree
+     *
+     * Note: trying to refer this object as a variable after "unsetting" like this will result in E_WARNING
+     */
+    public function unsetSelf()
+    {
+        $uniqueId = uniqid();
+        $this['_unique_id'] = $uniqueId;
+        $children = $this->getParent()->xpath('*');
+        for ($i = count($children); $i > 0; $i--) {
+            if ($children[$i - 1][0]['_unique_id'] == $uniqueId) {
+                unset($children[$i - 1][0]);
+                return;
+            }
+        }
+    }
+
 /*
     public function extendChildByNode($source, $overwrite=false, $mergeBy='name')
     {