diff --git a/modules/user/user.module b/modules/user/user.module
index 500875779269a0aa918951665a06b0ad6344d55f..adfb493c1a286bd6ac5ff53c1b90ce39d5846cdd 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -1789,6 +1789,14 @@ function user_menu_site_status_alter(&$menu_site_status, $path) {
  * Implements hook_menu_link_alter().
  */
 function user_menu_link_alter(&$link) {
+  // The path 'user' must be accessible for anonymous users, but only visible
+  // for authenticated users. Authenticated users should see "My account", but
+  // anonymous users should not see it at all. Therefore, invoke
+  // user_translated_menu_link_alter() to conditionally hide the link.
+  if ($link['link_path'] == 'user' && $link['module'] == 'system') {
+    $link['options']['alter'] = TRUE;
+  }
+
   // Force the Logout link to appear on the top-level of 'user-menu' menu by
   // default (i.e., unless it has been customized).
   if ($link['link_path'] == 'user/logout' && $link['module'] == 'system' && empty($link['customized'])) {
@@ -1796,6 +1804,16 @@ function user_menu_link_alter(&$link) {
   }
 }
 
+/**
+ * Implements hook_translated_menu_link_alter().
+ */
+function user_translated_menu_link_alter(&$link) {
+  // Hide the "User account" link for anonymous users.
+  if ($link['link_path'] == 'user' && $link['module'] == 'system' && user_is_anonymous()) {
+    $link['hidden'] = 1;
+  }
+}
+
 /**
  * Implements hook_admin_paths().
  */
@@ -1808,6 +1826,17 @@ function user_admin_paths() {
   return $paths;
 }
 
+/**
+ * Returns $arg or the user ID of the current user if $arg is '%' or empty.
+ *
+ * Deprecated. Use %user_uid_optional instead.
+ *
+ * @todo D8: Remove.
+ */
+function user_uid_only_optional_to_arg($arg) {
+  return user_uid_optional_to_arg($arg);
+}
+
 /**
  * Load either a specified or the current user account.
  *
diff --git a/modules/user/user.test b/modules/user/user.test
index 2cfb45671d5658891450c95f043e5359309173f2..2d54f7078e9d9aca43af92ac66a3b1db7889f05e 100644
--- a/modules/user/user.test
+++ b/modules/user/user.test
@@ -1227,6 +1227,56 @@ class UserAutocompleteTestCase extends DrupalWebTestCase {
   }
 }
 
+
+/**
+ * Test user-links in secondary menu.
+ */
+class UserAccountLinksUnitTests extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'User account links',
+      'description' => 'Test user-account links.',
+      'group' => 'User'
+    );
+  }
+
+  /**
+   * Test the user login block.
+   */
+  function testSecondaryMenu() {
+    // Create a regular user.
+    $user = $this->drupalCreateUser(array());
+
+    // Log in and get the homepage.
+    $this->drupalLogin($user);
+    $this->drupalGet('<front>');
+
+    // For a logged-in user, expect the secondary menu to have links for "My
+    // account" and "Log out".
+    $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
+      ':menu_id' => 'secondary-menu-links',
+      ':href' => 'user',
+      ':text' => 'My account',
+    ));
+    $this->assertEqual(count($link), 1, 'My account link is in secondary menu.');
+
+    $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array(
+      ':menu_id' => 'secondary-menu-links',
+      ':href' => 'user/logout',
+      ':text' => 'Log out',
+    ));
+    $this->assertEqual(count($link), 1, 'Log out link is in secondary menu.');
+
+    // Log out and get the homepage.
+    $this->drupalLogout();
+    $this->drupalGet('<front>');
+
+    // For a logged-out user, expect no secondary links.
+    $element = $this->xpath('//ul[@id=:menu_id]', array(':menu_id' => 'secondary-menu-links'));
+    $this->assertEqual(count($element), 0, 'No secondary-menu for logged-out users.');
+  }
+}
+
 /**
  * Test user blocks.
  */