diff --git a/lib/Drupal/masquerade/Tests/MasqueradeTest.php b/lib/Drupal/masquerade/Tests/MasqueradeTest.php
new file mode 100644
index 0000000..ad63d2f
--- /dev/null
+++ b/lib/Drupal/masquerade/Tests/MasqueradeTest.php
@@ -0,0 +1,74 @@
+<?php
+
+/**
+ * @file
+ * Contains Drupal\masquerade\Tests\MasqueradeTest.
+ */
+
+namespace Drupal\masquerade\Tests;
+
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests form permissions and user switching functionality.
+ *
+ * Requires Drupal core fix from http://drupal.org/node/1555862
+ */
+class MasqueradeTest extends WebTestBase {
+
+  public static $modules = array('masquerade');
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Masquerade functionality',
+      'description' => 'Tests form permissions and user switching functionality.',
+      'group' => 'Masquerade',
+    );
+  }
+
+  public function testMasquerade() {
+    $admin_perms = array(
+      'administer masquerade',
+      'masquerade as user',
+    );
+    $this->admin_user = $this->drupalCreateUser($admin_perms);
+    $this->web_user = $this->drupalCreateUser();
+
+    $this->drupalLogin($this->admin_user);
+
+    //test admin form
+    $this->drupalGet('admin/config/people/masquerade');
+    $this->assertResponse(200);
+
+    //test switch
+    $this->drupalGet('masquerade/switch/' . $this->web_user->uid);
+    $this->assertResponse(403);
+    $this->drupalGet('masquerade/switch/' . $this->web_user->uid, array(
+      'query' => array(
+        'token' => $this->drupalGetToken('masquerade/switch/' . $this->web_user->uid),
+      ),
+    ));
+    $this->assertResponse(200);
+    $this->assertText('You are now masquerading as ' . $this->web_user->name);
+
+    //test unswitch
+    $this->drupalGet('masquerade/unswitch');
+    $this->assertResponse(403);
+    $this->drupalGet('masquerade/unswitch', array(
+      'query' => array(
+        'token' => $this->drupalGetToken('masquerade/unswitch'),
+      ),
+    ));
+    $this->assertResponse(200);
+    $this->assertText('You are no longer masquerading as ' . $this->web_user->name);
+  }
+
+  /**
+   * @see http://drupal.org/node/1555862
+   */
+  protected function drupalGetToken($value = '') {
+    $private_key = drupal_get_private_key();
+    return drupal_hmac_base64($value, $this->session_id . $private_key . drupal_get_hash_salt());
+  }
+}
+
diff --git a/masquerade.info b/masquerade.info
index 1a15a80..b403416 100644
--- a/masquerade.info
+++ b/masquerade.info
@@ -1,5 +1,4 @@
 name = Masquerade
-description = "This module allows permitted users to masquerade as other users."
-core = 7.x
-files[] = masquerade.test
+description = Allows privileged users to masquerade as another user.
+core = 8.x
 configure = admin/config/people/masquerade
diff --git a/masquerade.install b/masquerade.install
index a10d092..ca0592a 100644
--- a/masquerade.install
+++ b/masquerade.install
@@ -2,15 +2,11 @@
 
 /**
  * @file
- * masquerade.install
- *
- * Install, uninstall and update hooks for the Masquarade module.
+ * Install, uninstall, and update hooks for the Masquerade module.
  */
 
 /**
  * Implements hook_schema().
- *
- * @return array
  */
 function masquerade_schema() {
   return array(
@@ -68,10 +64,7 @@ function masquerade_schema() {
  * Implements hook_install().
  */
 function masquerade_install() {
-  db_update('system')
-    ->fields(array('weight' => -10))
-    ->condition('name', 'masquerade')
-    ->execute();
+  module_set_weight('masquerade', -10);
 }
 
 /**
@@ -84,100 +77,8 @@ function masquerade_uninstall() {
 }
 
 /**
- * Reformat variable value.
+ * Implements hook_update_last_removed().
  */
-function masquerade_update_6001() {
-  variable_set('masquerade_quick_switches', implode(',', variable_get('masquerade_quick_switches', array())));
-}
-
-/**
- * Make the sid column match the length of the core sessions table (64 characters).
- */
-function masquerade_update_6002() {
-  db_drop_index('masquerade', 'sid');
-  db_drop_index('masquerade', 'sid_2');
-  db_change_field('masquerade', 'sid', 'sid', array(
-    'type' => 'varchar',
-    'length' => '64',
-    'not null' => TRUE,
-    'default' => '')
-  );
-  db_add_index('masquerade', 'sid', array('sid', 'uid_from'));
-  db_add_index('masquerade', 'sid_2', array('sid', 'uid_as'));
-}
-
-/**
- * Change masquerade_quick_switches variable to store a serialized array of
- * user ID's. Reverts update 6001.
- */
-function masquerade_update_6003() {
-  $users = variable_get('masquerade_quick_switches', NULL);
-  if (!empty($users)) {
-    $user_ids = drupal_explode_tags($users);
-    if (!empty($user_ids)) {
-      variable_set('masquerade_quick_switches', $user_ids);
-    }
-  }
-  else {
-    variable_del('masquerade_quick_switches');
-  }
-}
-
-/**
- * Set the weight of the masquerade module to -10, but only if it hasn't
- * previously been changed.
- */
-function masquerade_update_6004() {
-  db_update('system')
-    ->fields(array('weight' => -10))
-    ->condition('name', 'masquerade')
-    ->execute();
-}
-
-/**
- * Add a table storing specific user pairings a user can masquerade as.
- */
-function masquerade_update_6005() {
-  $schema = array(
-    'masquerade_users' => array(
-      'fields' => array(
-        'uid_from' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'default' => 0,
-          'disp-width' => 10,
-        ),
-        'uid_to' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'default' => 0,
-          'disp-width' => 10,
-        ),
-      ),
-      'primary key' => array('uid_from', 'uid_to'),
-    )
-  );
-  db_create_table('masquerade_users', $schema['masquerade_users']);
-}
-
-/**
- * Update masquerade block delta.
- */
-function masquerade_update_7000() {
-  db_update('block')
-    ->fields(array('delta' => 'masquerade'))
-    ->condition('module', 'masquerade')
-    ->condition('delta', 0)
-    ->execute();
-}
-
-/**
- * Update masquerade block caching.
- */
-function masquerade_update_7001() {
-  db_update('block')
-    ->fields(array('cache' => DRUPAL_NO_CACHE))
-    ->condition('module', 'masqurade')
-    ->condition('delta', 'masquerade')
-    ->execute();
+function masquerade_update_last_removed() {
+  return 7001;
 }
diff --git a/masquerade.module b/masquerade.module
index a487b60..b1c07a3 100644
--- a/masquerade.module
+++ b/masquerade.module
@@ -2,9 +2,13 @@
 
 /**
  * @file
- * The masquerade module allows administrators to masquerade as other user.
+ * Allows privileged users to masquerade as another user.
  */
 
+use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+
 /**
  * Implements hook_help().
  */
@@ -12,6 +16,7 @@ function masquerade_help($path, $arg) {
   switch ($path) {
     case 'admin/help#masquerade':
       return t('<p>The masquerade module adds a link on a user\'s profile page that allows permitted users to masquerade as that user. Upon masquerading, a link to "switch back" to the original user will appear in the menu. While masquerading, the option to masquerade as another user will not appear. All masquerading transactions are logged, and $user->masquerading will be set; this could be displayed via theme.</p><p>In the masquerade settings a list of roles are presented; any checked role is considered an "administrator" and requires the second level "masquerade as admin" permission to masquerade as. User #1 is automatically considered an administrator, regardless of roles.</p>');
+
     case 'admin/settings/masquerade':
       return t('Only the users with <strong>masquerade as admin</strong> permission, will be able to masquerade as the users who belong to the roles selected below. User #1 is automatically considered an administrator, regardless of roles.');
   }
@@ -19,8 +24,6 @@ function masquerade_help($path, $arg) {
 
 /**
  * Implements hook_permission().
- *
- * @return array
  */
 function masquerade_permission() {
   return array(
@@ -84,8 +87,6 @@ function masquerade_cron() {
  * Implements hook_menu().
  */
 function masquerade_menu() {
-  $items = array();
-
   $default_test_user = _masquerade_user_load(variable_get('masquerade_test_user', ''));
   if ($default_test_user && ($default_test_user->uid || $default_test_user->name == variable_get('anonymous', t('Anonymous')))) {
     $items['masquerade/switch/' . $default_test_user->uid] = array(
@@ -95,7 +96,6 @@ function masquerade_menu() {
       'page arguments' => array(2),
       'access callback' => 'masquerade_menu_access',
       'access arguments' => array('switch'),
-      'type' => MENU_NORMAL_ITEM,
     );
   }
 
@@ -105,14 +105,12 @@ function masquerade_menu() {
     'page arguments' => array(2),
     'access callback' => 'masquerade_menu_access',
     'access arguments' => array('switch', 2),
-    'type' => MENU_NORMAL_ITEM,
   );
   $items['masquerade/unswitch'] = array(
     'title' => 'Switch back',
     'page callback' => 'masquerade_switch_back_page',
     'access callback' => 'masquerade_menu_access',
     'access arguments' => array('unswitch'),
-    'type' => MENU_NORMAL_ITEM,
   );
   $items['masquerade/autocomplete'] = array(
     'title' => '',
@@ -142,7 +140,6 @@ function masquerade_menu() {
     'page arguments' => array('masquerade_admin_settings'),
     'access callback' => 'user_access',
     'access arguments' => array('administer masquerade'),
-    'type' => MENU_NORMAL_ITEM,
   );
 
   return $items;
@@ -217,18 +214,18 @@ function masquerade_user_operations_masquerade(array $accounts) {
  * @return
  *   TRUE, if the user can perform the requested action, FALSE otherwise.
  */
-
 function masquerade_menu_access($type, $uid = NULL) {
   switch ($type) {
     case 'unswitch':
       return isset($_SESSION['masquerading']) || arg(2) == 'menu-customize' || arg(2) == 'menu';
+
     case 'autocomplete':
       return isset($_SESSION['masquerading']) || (user_access('masquerade as user') || user_access('masquerade as admin'));
-      break;
+
     case 'user':
       global $user;
       return db_query("SELECT 1 FROM {masquerade_users} WHERE uid_from = :uid_from", array(':uid_from' => $user->uid))->fetchField();
-      break;
+
     case 'switch':
       $switch_to_account = FALSE;
       global $user;
@@ -244,7 +241,6 @@ function masquerade_menu_access($type, $uid = NULL) {
         }
       }
       return !isset($_SESSION['masquerading']) && (user_access('masquerade as user') || user_access('masquerade as admin') || $switch_to_account);
-      break;
   }
 }
 
@@ -359,7 +355,8 @@ function _masquerade_user_load($username) {
 function masquerade_user_logout($account) {
   if (!empty($account->masquerading)) {
     global $user;
-    cache_clear_all($user->uid, 'cache_menu', TRUE);
+    // @todo No such cache item/prefix exists, neither in D8 nor D7.
+    //cache_clear_all($user->uid, 'cache_menu', TRUE);
     $real_user = user_load($user->masquerading);
     watchdog('masquerade', "User %user no longer masquerading as %masq_as.", array('%user' => $real_user->name, '%masq_as' => $user->name), WATCHDOG_INFO);
 
@@ -388,7 +385,7 @@ function masquerade_user_view($account, $view_mode, $langcode) {
         'masquerade/switch/' . $account->uid,
         array('query' => array(
           'token' => drupal_get_token('masquerade/switch/' . $account->uid)),
-          'destination' => $_GET['q'],
+          'destination' => current_path(),
           'attributes' => array('class' => 'masquerade-switch'),
         )),
       '#weight' => 10,
@@ -400,16 +397,12 @@ function masquerade_user_view($account, $view_mode, $langcode) {
  * Implements hook_form_FORM_ID_alter().
  */
 function masquerade_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
-  if ($form['#user_category'] != 'account') {
-    // Do not show this form for different categories.
-    return;
-  }
   $form['masquerade'] = array(
     '#type' => 'fieldset',
     '#title' => t('Masquerade settings'),
     '#access' => user_access('administer masquerade'),
   );
-  $edit_user = $form['#user'];
+  $edit_user = $form_state['controller']->getEntity($form_state);
   $uids = db_query("SELECT uid_to FROM {masquerade_users} WHERE uid_from = :uid_from", array(':uid_from' => $edit_user->uid))
     ->fetchCol();
   $users = user_load_multiple($uids);
@@ -459,14 +452,14 @@ function masquerade_user_submit(&$form, $form_state) {
 /**
  * Implements hook_user_update().
  */
-function masquerade_user_update(&$edit, $account, $category) {
+function masquerade_user_update($account) {
   global $_masquerade_old_session_id;
-  if ($category == 'account' && isset($edit['masquerade_users'])) {
+  if (isset($account->masquerade_users)) {
     $query = db_delete('masquerade_users');
     $query->condition('uid_from', $account->uid);
     $query->execute();
     // Save users from settings form.
-    $users = drupal_explode_tags($edit['masquerade_users']);
+    $users = drupal_explode_tags($account->masquerade_users);
     $query = db_insert('masquerade_users')->fields(array('uid_from', 'uid_to'));
     foreach ($users as $username) {
       if ($to_user = _masquerade_user_load($username)) {
@@ -477,7 +470,7 @@ function masquerade_user_update(&$edit, $account, $category) {
       }
     }
     $query->execute();
-    $edit['masquerade_users'] = NULL;
+    $account->masquerade_users = NULL;
 
     // Update user session...
     // @TODO check other way of session API.
@@ -517,7 +510,6 @@ function masquerade_user_delete($account) {
  * Implements hook_block_info().
  */
 function masquerade_block_info() {
-  $blocks = array();
   $blocks['masquerade'] = array(
     'info' => t('Masquerade'),
     'cache' => DRUPAL_NO_CACHE,
@@ -649,7 +641,7 @@ function masquerade_block_1_submit($form, &$form_state) {
   //unset($form);
   $masq_user = _masquerade_user_load($form_state['values']['masquerade_user_field']);
   if (!masquerade_switch_user($masq_user->uid)) {
-    drupal_access_denied();
+    throw new AccessDeniedHttpException();
   }
   else {
     drupal_goto($_SERVER['HTTP_REFERER']);
@@ -676,7 +668,7 @@ function masquerade_autocomplete($string) {
   if (module_exists('devel')) {
     $GLOBALS['devel_shutdown'] = FALSE;
   }
-  drupal_json_output($matches);
+  return new JsonResponse($matches);
 }
 
 /**
@@ -728,18 +720,19 @@ function masquerade_autocomplete_multiple($string, $add_anonymous = TRUE) {
   if (module_exists('devel')) {
     $GLOBALS['devel_shutdown'] = FALSE;
   }
-  drupal_json_output($matches);
+  return new JsonResponse($matches);
 }
 
 /**
  * Page callback to switch users.
  */
 function masquerade_switch_user_page($uid) {
-  if (isset($_GET['token']) && drupal_valid_token($_GET['token'], 'masquerade/switch/' . $uid) && masquerade_switch_user($uid)) {
+  $token = drupal_container()->get('request')->query->get('token');
+  if (isset($token) && drupal_valid_token($token, 'masquerade/switch/' . $uid) && masquerade_switch_user($uid)) {
     drupal_goto($_SERVER['HTTP_REFERER']);
   }
   else {
-    drupal_access_denied();
+    throw new AccessDeniedHttpException();
   }
 }
 
@@ -806,8 +799,7 @@ function masquerade_switch_user($uid) {
   $user = $new_user;
 
   // Call all login hooks when switching to masquerading user.
-  $edit = array(); // Passed by reference.
-  user_module_invoke('login', $edit, $user);
+  module_invoke_all('user_login', array(), $user);
 
   return TRUE;
 }
@@ -816,7 +808,8 @@ function masquerade_switch_user($uid) {
  * Allows a user who is currently masquerading to become a new user.
  */
 function masquerade_switch_back_page() {
-  if (isset($_GET['token']) && drupal_valid_token($_GET['token'], 'masquerade/unswitch')) {
+  $token = drupal_container()->get('request')->query->get('token');
+  if (isset($token) && drupal_valid_token($token, 'masquerade/unswitch')) {
     global $user;
     $olduser = $user;
     masquerade_switch_back();
@@ -824,7 +817,7 @@ function masquerade_switch_back_page() {
     drupal_goto($_SERVER['HTTP_REFERER']);
   }
   else {
-    drupal_access_denied();
+    throw new AccessDeniedHttpException();
   }
 }
 
@@ -834,7 +827,8 @@ function masquerade_switch_back_page() {
 function masquerade_switch_back() {
   // switch user
   global $user;
-  cache_clear_all($user->uid, 'cache_menu', TRUE);
+  // @todo No such cache item/prefix exists, neither in D8 nor D7.
+  //cache_clear_all($user->uid, 'cache_menu', TRUE);
   $uid = db_query("SELECT m.uid_from FROM {masquerade} m WHERE m.sid = :sid AND m.uid_as = :uid_as ", array(
     ':sid' => session_id(),
     ':uid_as' => $user->uid,
@@ -855,8 +849,7 @@ function masquerade_switch_back() {
   $user = user_load($uid);
 
   // Call all login hooks when switching back to original user.
-  $edit = array(); // Passed by reference.
-  user_module_invoke('login', $edit, $user);
+  module_invoke_all('user_login', array(), $user);
 
   watchdog('masquerade', 'User %user no longer masquerading as %masq_as.', array('%user' => $user->name, '%masq_as' => $oldname), WATCHDOG_INFO);
 }
diff --git a/masquerade.test b/masquerade.test
deleted file mode 100644
index ac01d08..0000000
--- a/masquerade.test
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-
-/**
- * @file
- * masquerade.test
- *
- * Test the form permissions and switch ability of the Masquarade module.
- */
-
-class MasqueradeTestCase extends DrupalWebTestCase {
-  public static function getInfo() {
-    return array(
-      'name' => 'Masquerade tests',
-      'description' => 'Tests user switching with the Masquerade module.',
-      'group' => 'Masquerade',
-    );
-  }
-
-  public function setUp() {
-    parent::setUp('masquerade');
-  }
-
-  public function testMasquerade() {
-    $admin_perms = array(
-      'administer site configuration',
-      'administer permissions',
-      'masquerade as user',
-    );
-    $admin = $this->drupalCreateUser($admin_perms);
-    $user = $this->drupalCreateUser();
-
-    $this->drupalLogin($admin);
-
-    //test admin form
-    $this->drupalGet('admin/config/development/masquerade');
-
-    //test switch
-    $this->drupalGet('masquerade/switch/' . $user->uid);
-    $this->assertText('Now masquerading as ' . $user->name);
-
-    //test unswitch
-    $this->drupalGet('masquerade/unswitch');
-    $this->assertText('No longer masquerading as ' . $user->name);
-  }
-
-}
-
