diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index ab06260..e695ad9 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -145,16 +145,6 @@ const DRUPAL_BOOTSTRAP_LANGUAGE = 6;
 const DRUPAL_BOOTSTRAP_FULL = 7;
 
 /**
- * Role ID for anonymous users; should match what's in the "role" table.
- */
-const DRUPAL_ANONYMOUS_RID = 1;
-
-/**
- * Role ID for authenticated users; should match what's in the "role" table.
- */
-const DRUPAL_AUTHENTICATED_RID = 2;
-
-/**
  * The number of bytes in a kilobyte.
  *
  * For more information, visit http://en.wikipedia.org/wiki/Kilobyte.
@@ -2121,12 +2111,35 @@ function drupal_anonymous_user() {
   $user->uid = 0;
   $user->hostname = ip_address();
   $user->roles = array();
-  $user->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user';
+  $anonymous_role = drupal_anonymous_role();
+  if (!empty($anonymous_role)) {
+    $user->roles[$anonymous_role->rid] = $anonymous_role->name;
+  }
   $user->cache = 0;
   return $user;
 }
 
 /**
+ * Returns the anonymous user role, if there is one.
+ */
+function drupal_anonymous_role() {
+  $anonymous_rid = variable_get('drupal_anonymous_rid');
+  if (!empty($anonymous_rid)) {
+    return user_role_load($anonymous_rid);
+  }
+}
+
+/**
+ * Returns the role that users get upon registration, if there is one.
+ */
+function drupal_registration_role() {
+  $registration_rid = variable_get('drupal_registration_rid');
+  if (!empty($registration_rid)) {
+    return user_role_load($registration_rid);
+  }
+}
+
+/**
  * Ensures Drupal is bootstrapped to the specified phase.
  *
  * The bootstrap phase is an integer constant identifying a phase of Drupal
diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index c21cd68..e230820 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -1857,6 +1857,14 @@ function install_configure_form_submit($form, &$form_state) {
 
   // We precreated user 1 with placeholder values. Let's save the real values.
   $account = user_load(1);
+  // Make sure that the first user account has the role that is supposed to
+  // be assigned to newly-registered users. This is necessary since this
+  // account is not created via the normal user_save() process.
+  $registration_role = drupal_registration_role();
+  if (!empty($registration_role)) {
+    $account->roles[$registration_role->rid] = $registration_role->name;
+  }
+  
   $merge_data = array('init' => $form_state['values']['account']['mail'], 'roles' => !empty($account->roles) ? $account->roles : array(), 'status' => 1, 'timezone' => $form_state['values']['date_default_timezone']);
   user_save($account, array_merge($form_state['values']['account'], $merge_data));
   // Load global $user and perform final login tasks.
diff --git a/core/includes/session.inc b/core/includes/session.inc
index df70f0e..5ff6ea9 100644
--- a/core/includes/session.inc
+++ b/core/includes/session.inc
@@ -110,7 +110,6 @@ function _drupal_session_read($sid) {
 
     // Add roles element to $user.
     $user->roles = array();
-    $user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
     $user->roles += db_query("SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = :uid", array(':uid' => $user->uid))->fetchAllKeyed(0, 1);
   }
   elseif ($user) {
diff --git a/core/modules/block/block.module b/core/modules/block/block.module
index 4d942ed..333dfc3 100644
--- a/core/modules/block/block.module
+++ b/core/modules/block/block.module
@@ -601,31 +601,33 @@ function block_custom_block_save($edit, $delta) {
 function block_form_user_profile_form_alter(&$form, &$form_state) {
   $account = $form['#user'];
   $rids = array_keys($account->roles);
-  $result = db_query("SELECT DISTINCT b.* FROM {block} b LEFT JOIN {block_role} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom <> 0 AND (r.rid IN (:rids) OR r.rid IS NULL) ORDER BY b.weight, b.module", array(':rids' => $rids));
+  if (!empty($rids)) {
+    $result = db_query("SELECT DISTINCT b.* FROM {block} b LEFT JOIN {block_role} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom <> 0 AND (r.rid IN (:rids) OR r.rid IS NULL) ORDER BY b.weight, b.module", array(':rids' => $rids));
 
-  $blocks = array();
-  foreach ($result as $block) {
-    $data = module_invoke($block->module, 'block_info');
-    if ($data[$block->delta]['info']) {
-      $blocks[$block->module][$block->delta] = array(
-        '#type' => 'checkbox',
-        '#title' => check_plain($data[$block->delta]['info']),
-        '#default_value' => isset($account->data['block'][$block->module][$block->delta]) ? $account->data['block'][$block->module][$block->delta] : ($block->custom == 1),
+    $blocks = array();
+    foreach ($result as $block) {
+      $data = module_invoke($block->module, 'block_info');
+      if ($data[$block->delta]['info']) {
+        $blocks[$block->module][$block->delta] = array(
+          '#type' => 'checkbox',
+          '#title' => check_plain($data[$block->delta]['info']),
+          '#default_value' => isset($account->data['block'][$block->module][$block->delta]) ? $account->data['block'][$block->module][$block->delta] : ($block->custom == 1),
+        );
+      }
+    }
+    // Only display the fieldset if there are any personalizable blocks.
+    if ($blocks) {
+      $form['block'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Personalize blocks'),
+        '#description' => t('Blocks consist of content or information that complements the main content of the page. Enable or disable optional blocks using the checkboxes below.'),
+        '#weight' => 3,
+        '#collapsible' => TRUE,
+        '#tree' => TRUE,
       );
+      $form['block'] += $blocks;
     }
   }
-  // Only display the fieldset if there are any personalizable blocks.
-  if ($blocks) {
-    $form['block'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Personalize blocks'),
-      '#description' => t('Blocks consist of content or information that complements the main content of the page. Enable or disable optional blocks using the checkboxes below.'),
-      '#weight' => 3,
-      '#collapsible' => TRUE,
-      '#tree' => TRUE,
-    );
-    $form['block'] += $blocks;
-  }
 }
 
 /**
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 70218a5..620c8e2 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -1357,9 +1357,11 @@ function comment_node_update_index($node) {
 
     // Prevent indexing of comments if there are any roles that can search but
     // not view comments.
+    // @todo Check if comments can be indexed even if certain roles have no
+    // access to them.
     $index_comments = TRUE;
     foreach ($perms['search content'] as $rid) {
-      if (!isset($perms['access comments'][$rid]) && ($rid <= DRUPAL_AUTHENTICATED_RID || !isset($perms['access comments'][DRUPAL_AUTHENTICATED_RID]))) {
+      if (!isset($perms['access comments'][$rid])) {
         $index_comments = FALSE;
         break;
       }
@@ -2187,17 +2189,17 @@ function theme_comment_post_forbidden($variables) {
 
   // Since this is expensive to compute, we cache it so that a page with many
   // comments only has to query the database once for all the links.
-  $authenticated_post_comments = &drupal_static(__FUNCTION__, NULL);
+  $registered_post_comments = &drupal_static(__FUNCTION__, NULL);
 
   if (!$user->uid) {
-    if (!isset($authenticated_post_comments)) {
+    if (!isset($registered_post_comments)) {
       // We only output a link if we are certain that users will get permission
       // to post comments by logging in.
-      $comment_roles = user_roles(TRUE, 'post comments');
-      $authenticated_post_comments = isset($comment_roles[DRUPAL_AUTHENTICATED_RID]);
+      $registration_rid = variable_get('drupal_registration_rid');
+      $registered_post_comments = !empty($registration_rid) && array_key_exists($registration_rid, user_roles('post comments') + user_roles('post comments without approval'));
     }
 
-    if ($authenticated_post_comments) {
+    if ($registered_post_comments) {
       // We cannot use drupal_get_destination() because these links
       // sometimes appear on /node and taxonomy listing pages.
       if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_SEPARATE_PAGE) {
diff --git a/core/modules/search/search.test b/core/modules/search/search.test
index 1ee4e6f..76826ac 100644
--- a/core/modules/search/search.test
+++ b/core/modules/search/search.test
@@ -763,11 +763,17 @@ class SearchCommentTestCase extends DrupalWebTestCase {
       'filters[filter_html_escape][status]' => TRUE,
     );
     $this->drupalPost('admin/config/content/formats/' . $filtered_html_format_id, $edit, t('Save configuration'));
+    // Create and set anonymous role if there isn't one set.
+    $anonymous_rid = variable_get('drupal_anonymous_rid');
+    if (empty($anonymous_rid)) {
+      $anonymous_rid = $this->drupalCreateRole();
+      variable_set('drupal_anonymous_rid', $anonymous_rid);
+    }
     // Allow anonymous users to search content.
     $edit = array(
-      DRUPAL_ANONYMOUS_RID . '[search content]' => 1,
-      DRUPAL_ANONYMOUS_RID . '[access comments]' => 1,
-      DRUPAL_ANONYMOUS_RID . '[post comments]' => 1,
+      $anonymous_rid . '[search content]' => 1,
+      $anonymous_rid . '[access comments]' => 1,
+      $anonymous_rid . '[post comments]' => 1,
     );
     $this->drupalPost('admin/people/permissions', $edit, t('Save permissions'));
 
diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc
index f7d4552..cbd7213 100644
--- a/core/modules/user/user.admin.inc
+++ b/core/modules/user/user.admin.inc
@@ -191,7 +191,7 @@ function user_admin_account() {
   $destination = drupal_get_destination();
 
   $status = array(t('blocked'), t('active'));
-  $roles = array_map('check_plain', user_roles(TRUE));
+  $roles = array_map('check_plain', user_roles());
   $accounts = array();
   foreach ($result as $account) {
     $users_roles = array();
@@ -277,11 +277,7 @@ function user_admin_settings() {
     '#title' => t('Administrator role'),
   );
 
-  // Do not allow users to set the anonymous or authenticated user roles as the
-  // administrator role.
   $roles = user_roles();
-  unset($roles[DRUPAL_ANONYMOUS_RID]);
-  unset($roles[DRUPAL_AUTHENTICATED_RID]);
   $roles[0] = t('disabled');
 
   $form['admin_role']['user_admin_role'] = array(
@@ -313,6 +309,21 @@ function user_admin_settings() {
     '#default_value' => variable_get('user_email_verification', TRUE),
     '#description' => t('New users will be required to validate their e-mail address prior to logging into the site, and will be assigned a system-generated password. With this setting disabled, users will be logged in immediately upon registering, and may select their own passwords during registration.')
   );
+  $user_roles = array(0 => t('<none>')) + user_roles();
+  $form['registration_cancellation']['drupal_anonymous_rid'] = array(
+    '#type' => 'select',
+    '#title' => t('Role to assign to users who are not logged in'),
+    '#default_value' => variable_get('drupal_anonymous_rid'),
+    '#options' => $user_roles,
+    '#description' => t('Visitors to the site who have not yet registered for an account or logged in will be given the permissions associated with this role, if one is selected.'),
+  );
+  $form['registration_cancellation']['drupal_registration_rid'] = array(
+    '#type' => 'select',
+    '#title' => t('Role to assign to users when they register for an account'),
+    '#default_value' => variable_get('drupal_registration_rid'),
+    '#options' => $user_roles,
+    '#description' => t('New users who register for an account on the site will be given this role when their account is first created. Note that if you change this role after your site is in operation, your site may no longer have a single role that all logged-in users are guaranteed to have.'),
+  );
   module_load_include('inc', 'user', 'user.pages');
   $form['registration_cancellation']['user_cancel_method'] = array(
     '#type' => 'item',
@@ -655,6 +666,13 @@ function user_admin_permissions($form, $form_state, $rid = NULL) {
   if (is_numeric($rid)) {
     $role_names = array($rid => $role_names[$rid]);
   }
+  
+  // Show a message if no roles exist.
+  if (empty($role_names)) {
+    $form['no_roles'] = array('#markup' => t('This site does not have any user roles. You can create new ones on the <a href="@role_url">role administration page</a>.', array('@role_url' => url('admin/user/roles'))));
+    return $form;
+  }
+  
   // Fetch permissions for all roles or the one selected role.
   $role_permissions = user_role_permissions($role_names);
 
@@ -719,8 +737,6 @@ function user_admin_permissions($form, $form_state, $rid = NULL) {
   $form['actions'] = array('#type' => 'actions');
   $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save permissions'));
 
-  $form['#attached']['js'][] = drupal_get_path('module', 'user') . '/user.permissions.js';
-
   return $form;
 }
 
@@ -753,6 +769,9 @@ function theme_user_admin_permissions($variables) {
   $form = $variables['form'];
 
   $roles = user_roles();
+  if (empty($roles)) {
+    return drupal_render_children($form);
+  }
   foreach (element_children($form['permission']) as $key) {
     $row = array();
     // Module name
@@ -896,18 +915,10 @@ function theme_user_admin_roles($variables) {
   foreach (element_children($form['roles']) as $rid) {
     $name = $form['roles'][$rid]['#role']->name;
     $row = array();
-    if (in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
-      $row[] = t('@name <em>(locked)</em>', array('@name' => $name));
-      $row[] = drupal_render($form['roles'][$rid]['weight']);
-      $row[] = '';
-      $row[] = l(t('edit permissions'), 'admin/people/permissions/' . $rid);
-    }
-    else {
-      $row[] = check_plain($name);
-      $row[] = drupal_render($form['roles'][$rid]['weight']);
-      $row[] = l(t('edit role'), 'admin/people/permissions/roles/edit/' . $rid);
-      $row[] = l(t('edit permissions'), 'admin/people/permissions/' . $rid);
-    }
+    $row[] = check_plain($name);
+    $row[] = drupal_render($form['roles'][$rid]['weight']);
+    $row[] = l(t('edit role'), 'admin/people/permissions/roles/edit/' . $rid);
+    $row[] = l(t('edit permissions'), 'admin/people/permissions/' . $rid);
     $rows[] = array('data' => $row, 'class' => array('draggable'));
   }
   $rows[] = array(array('data' => drupal_render($form['name']) . drupal_render($form['add']), 'colspan' => 4, 'class' => 'edit-name'));
@@ -928,10 +939,6 @@ function theme_user_admin_roles($variables) {
  * @see user_admin_role_submit()
  */
 function user_admin_role($form, $form_state, $role) {
-  if ($role->rid == DRUPAL_ANONYMOUS_RID || $role->rid == DRUPAL_AUTHENTICATED_RID) {
-    drupal_goto('admin/people/permissions/roles');
-  }
-
   // Display the edit role form.
   $form['name'] = array(
     '#type' => 'textfield',
diff --git a/core/modules/user/user.entity.inc b/core/modules/user/user.entity.inc
index 5549c77..103a44f 100644
--- a/core/modules/user/user.entity.inc
+++ b/core/modules/user/user.entity.inc
@@ -19,11 +19,8 @@ class UserController extends DrupalDefaultEntityController {
       $picture_fids[] = $record->picture;
       $queried_users[$key]->data = unserialize($record->data);
       $queried_users[$key]->roles = array();
-      if ($record->uid) {
-        $queried_users[$record->uid]->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
-      }
-      else {
-        $queried_users[$record->uid]->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user';
+      if (!$record->uid && ($anonymous_role = drupal_anonymous_role())) {
+        $queried_users[$record->uid]->roles[$anonymous_role->rid] = $anonymous_role_>name;
       }
     }
 
diff --git a/core/modules/user/user.install b/core/modules/user/user.install
index f7175c3..3741a53 100644
--- a/core/modules/user/user.install
+++ b/core/modules/user/user.install
@@ -310,30 +310,6 @@ function user_install() {
       'data' => NULL,
     ))
     ->execute();
-
-  // Built-in roles.
-  $rid_anonymous = db_insert('role')
-    ->fields(array('name' => 'anonymous user', 'weight' => 0))
-    ->execute();
-  $rid_authenticated = db_insert('role')
-    ->fields(array('name' => 'authenticated user', 'weight' => 1))
-    ->execute();
-
-  // Sanity check to ensure the anonymous and authenticated role IDs are the
-  // same as the drupal defined constants. In certain situations, this will
-  // not be true.
-  if ($rid_anonymous != DRUPAL_ANONYMOUS_RID) {
-    db_update('role')
-      ->fields(array('rid' => DRUPAL_ANONYMOUS_RID))
-      ->condition('rid', $rid_anonymous)
-      ->execute();
-  }
-  if ($rid_authenticated != DRUPAL_AUTHENTICATED_RID) {
-    db_update('role')
-      ->fields(array('rid' => DRUPAL_AUTHENTICATED_RID))
-      ->condition('rid', $rid_authenticated)
-      ->execute();
-  }
 }
 
 /**
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index 928daad..bf44b2f 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -473,12 +473,10 @@ function user_save($account, $edit = array()) {
 
         $query = db_insert('users_roles')->fields(array('uid', 'rid'));
         foreach (array_keys($account->roles) as $rid) {
-          if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
-            $query->values(array(
-              'uid' => $account->uid,
-              'rid' => $rid,
-            ));
-          }
+          $query->values(array(
+            'uid' => $account->uid,
+            'rid' => $rid,
+          ));
         }
         $query->execute();
       }
@@ -533,24 +531,26 @@ function user_save($account, $edit = array()) {
         return FALSE;
       }
 
-      // Make sure $account is properly initialized.
-      $account->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
-
       field_attach_insert('user', $account);
       $edit = (array) $account;
       user_module_invoke('insert', $edit, $account);
       module_invoke_all('entity_insert', $account, 'user');
+      
+      // Make sure that the user gets the role they were supposed to be
+      // assigned when they registered.
+      $registration_role = drupal_registration_role();
+      if (!empty($registration_role) && !isset($edit['roles'][$registration_role->rid])) {
+        $account->roles[$registration_role->rid] = $registration_role->name;
+      }
 
       // Save user roles.
       if (count($account->roles) > 1) {
         $query = db_insert('users_roles')->fields(array('uid', 'rid'));
         foreach (array_keys($account->roles) as $rid) {
-          if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
-            $query->values(array(
-              'uid' => $account->uid,
-              'rid' => $rid,
-            ));
-          }
+          $query->values(array(
+            'uid' => $account->uid,
+            'rid' => $rid,
+          ));
         }
         $query->execute();
       }
@@ -1033,26 +1033,19 @@ function user_account_form(&$form, &$form_state) {
     '#access' => $admin,
   );
 
-  $roles = array_map('check_plain', user_roles(TRUE));
-  // The disabled checkbox subelement for the 'authenticated user' role
-  // must be generated separately and added to the checkboxes element,
-  // because of a limitation in Form API not supporting a single disabled
-  // checkbox within a set of checkboxes.
-  // @todo This should be solved more elegantly. See issue #119038.
-  $checkbox_authenticated = array(
-    '#type' => 'checkbox',
-    '#title' => $roles[DRUPAL_AUTHENTICATED_RID],
-    '#default_value' => TRUE,
-    '#disabled' => TRUE,
-  );
-  unset($roles[DRUPAL_AUTHENTICATED_RID]);
+  $roles = array_map('check_plain', user_roles());
+  $default = (!$register && isset($account->roles) ? array_keys($account->roles) : array());
+  $registration_rid = variable_get('drupal_registration_rid');
+  if ($register && !empty($registration_rid) && !in_array($registration_rid, $default)) {
+    $default[] = $registration_rid;
+  }
+
   $form['account']['roles'] = array(
     '#type' => 'checkboxes',
     '#title' => t('Roles'),
-    '#default_value' => (!$register && isset($account->roles) ? array_keys($account->roles) : array()),
+    '#default_value' => $default,
     '#options' => $roles,
     '#access' => $roles && user_access('administer permissions'),
-    DRUPAL_AUTHENTICATED_RID => $checkbox_authenticated,
   );
 
   $form['account']['notify'] = array(
@@ -2795,8 +2788,6 @@ function user_mail_tokens(&$replacements, $data, $options) {
 /**
  * Retrieve an array of roles matching specified conditions.
  *
- * @param $membersonly
- *   Set this to TRUE to exclude the 'anonymous' role.
  * @param $permission
  *   A string containing a permission. If set, only roles containing that
  *   permission are returned.
@@ -2805,16 +2796,14 @@ function user_mail_tokens(&$replacements, $data, $options) {
  *   An associative array with the role id as the key and the role name as
  *   value.
  */
-function user_roles($membersonly = FALSE, $permission = NULL) {
+function user_roles($permission = NULL) {
   $user_roles = &drupal_static(__FUNCTION__);
 
-  // Do not cache roles for specific permissions. This data is not requested
-  // frequently enough to justify the additional memory use.
-  if (empty($permission)) {
-    $cid = $membersonly ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
-    if (isset($user_roles[$cid])) {
-      return $user_roles[$cid];
-    }
+  // Only cache roles when no specific permission is requested. Do not cache 
+  // roles for specific permissions. This data is not requested frequently 
+  // enough to justify the additional memory use.
+  if (empty($permission) && !empty($user_roles)) {
+    return $user_roles;
   }
 
   $query = db_select('role', 'r');
@@ -2830,24 +2819,12 @@ function user_roles($membersonly = FALSE, $permission = NULL) {
 
   $roles = array();
   foreach ($result as $role) {
-    switch ($role->rid) {
-      // We only translate the built in role names
-      case DRUPAL_ANONYMOUS_RID:
-        if (!$membersonly) {
-          $roles[$role->rid] = t($role->name);
-        }
-        break;
-      case DRUPAL_AUTHENTICATED_RID:
-        $roles[$role->rid] = t($role->name);
-        break;
-      default:
-        $roles[$role->rid] = $role->name;
-    }
+    $roles[$role->rid] = $role->name;
   }
 
   if (empty($permission)) {
-    $user_roles[$cid] = $roles;
-    return $user_roles[$cid];
+    $user_roles = $roles;
+    return $user_roles;
   }
 
   return $roles;
@@ -2972,11 +2949,6 @@ function user_role_delete($role) {
  * Menu access callback for user role editing.
  */
 function user_role_edit_access($role) {
-  // Prevent the system-defined roles from being altered or removed.
-  if ($role->rid == DRUPAL_ANONYMOUS_RID || $role->rid == DRUPAL_AUTHENTICATED_RID) {
-    return FALSE;
-  }
-
   return user_access('administer permissions');
 }
 
@@ -3112,8 +3084,7 @@ function user_user_operations($form = array(), $form_state = array()) {
   );
 
   if (user_access('administer permissions')) {
-    $roles = user_roles(TRUE);
-    unset($roles[DRUPAL_AUTHENTICATED_RID]);  // Can't edit authenticated role.
+    $roles = user_roles();
 
     $add_roles = array();
     foreach ($roles as $key => $value) {
@@ -3329,8 +3300,7 @@ function user_multiple_cancel_confirm_submit($form, &$form_state) {
 function user_filters() {
   // Regular filters
   $filters = array();
-  $roles = user_roles(TRUE);
-  unset($roles[DRUPAL_AUTHENTICATED_RID]); // Don't list authorized role.
+  $roles = user_roles();
   if (count($roles)) {
     $filters['role'] = array(
       'title' => t('role'),
@@ -3386,12 +3356,6 @@ function user_build_filter_query(SelectQuery $query) {
     // the authenticated role. If so, then all users would be listed, and we can
     // skip adding it to the filter query.
     if ($key == 'permission') {
-      $account = new stdClass();
-      $account->uid = 'user_filter';
-      $account->roles = array(DRUPAL_AUTHENTICATED_RID => 1);
-      if (user_access($value, $account)) {
-        continue;
-      }
       $users_roles_alias = $query->join('users_roles', 'ur', '%alias.uid = u.uid');
       $permission_alias = $query->join('role_permission', 'p', $users_roles_alias . '.rid = %alias.rid');
       $query->condition($permission_alias . '.permission', $value);
diff --git a/core/modules/user/user.permissions.js b/core/modules/user/user.permissions.js
deleted file mode 100644
index 988820e..0000000
--- a/core/modules/user/user.permissions.js
+++ /dev/null
@@ -1,69 +0,0 @@
-(function ($) {
-
-/**
- * Shows checked and disabled checkboxes for inherited permissions.
- */
-Drupal.behaviors.permissions = {
-  attach: function (context) {
-    var self = this;
-    $('table#permissions').once('permissions', function () {
-      // On a site with many roles and permissions, this behavior initially has
-      // to perform thousands of DOM manipulations to inject checkboxes and hide
-      // them. By detaching the table from the DOM, all operations can be
-      // performed without triggering internal layout and re-rendering processes
-      // in the browser.
-      var $table = $(this);
-      if ($table.prev().length) {
-        var $ancestor = $table.prev(), method = 'after';
-      }
-      else {
-        var $ancestor = $table.parent(), method = 'append';
-      }
-      $table.detach();
-
-      // Create dummy checkboxes. We use dummy checkboxes instead of reusing
-      // the existing checkboxes here because new checkboxes don't alter the
-      // submitted form. If we'd automatically check existing checkboxes, the
-      // permission table would be polluted with redundant entries. This
-      // is deliberate, but desirable when we automatically check them.
-      var $dummy = $('<input type="checkbox" class="dummy-checkbox" disabled="disabled" checked="checked" />')
-        .attr('title', Drupal.t("This permission is inherited from the authenticated user role."))
-        .hide();
-
-      $('input[type=checkbox]', this).not('.rid-2, .rid-1').addClass('real-checkbox').each(function () {
-        $dummy.clone().insertAfter(this);
-      });
-
-      // Initialize the authenticated user checkbox.
-      $('input[type=checkbox].rid-2', this)
-        .bind('click.permissions', self.toggle)
-        // .triggerHandler() cannot be used here, as it only affects the first
-        // element.
-        .each(self.toggle);
-
-      // Re-insert the table into the DOM.
-      $ancestor[method]($table);
-    });
-  },
-
-  /**
-   * Toggles all dummy checkboxes based on the checkboxes' state.
-   *
-   * If the "authenticated user" checkbox is checked, the checked and disabled
-   * checkboxes are shown, the real checkboxes otherwise.
-   */
-  toggle: function () {
-    var authCheckbox = this, $row = $(this).closest('tr');
-    // jQuery performs too many layout calculations for .hide() and .show(),
-    // leading to a major page rendering lag on sites with many roles and
-    // permissions. Therefore, we toggle visibility directly.
-    $row.find('.real-checkbox').each(function () {
-      this.style.display = (authCheckbox.checked ? 'none' : '');
-    });
-    $row.find('.dummy-checkbox').each(function () {
-      this.style.display = (authCheckbox.checked ? '' : 'none');
-    });
-  }
-};
-
-})(jQuery);
diff --git a/profiles/minimal/minimal.install b/profiles/minimal/minimal.install
index d5b85c5..90fc477 100644
--- a/profiles/minimal/minimal.install
+++ b/profiles/minimal/minimal.install
@@ -77,8 +77,4 @@ function minimal_install() {
 
   // Allow visitor account creation, but with administrative approval.
   variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
-
-  // Enable default permissions for system roles.
-  user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content'));
-  user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content'));
 }
diff --git a/profiles/standard/standard.install b/profiles/standard/standard.install
index e570c18..11fcc79 100644
--- a/profiles/standard/standard.install
+++ b/profiles/standard/standard.install
@@ -395,11 +395,25 @@ function standard_install() {
     ),
   );
   field_create_instance($instance);
+  
+  // Create two standerd roles to assign to anonymous and registered users
+  // respectively.
+  $anonymous_role = new stdClass();
+  $anonymous_role->name = 'guest';
+  $anonymous_role->weight = 0;
+  user_role_save($anonymous_role);
+  variable_set('drupal_anonymous_rid', $anonymous_role->rid);
+  
+  $registration_role = new stdClass();
+  $registration_role->name = 'member';
+  $registration_role->weight = 1;
+  user_role_save($registration_role);
+  variable_set('drupal_registration_rid', $registration_role->rid);
 
   // Enable default permissions for system roles.
   $filtered_html_permission = filter_permission_name($filtered_html_format);
-  user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content', 'access comments', $filtered_html_permission));
-  user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content', 'access comments', 'post comments', 'skip comment approval', $filtered_html_permission));
+  user_role_grant_permissions($anonymous_role->rid, array('access content', 'access comments', $filtered_html_permission));
+  user_role_grant_permissions($registration_role->rid, array('access content', 'access comments', 'post comments', 'skip comment approval', $filtered_html_permission));
 
   // Create a default role for site administrators, with all available permissions assigned.
   $admin_role = new stdClass();
