diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 7b6eda4..d5f228b 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -1739,19 +1739,10 @@ function theme_comment_post_forbidden($variables) {
   $node = $variables['node'];
   global $user;
 
-  // 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);
-
   if (!$user->uid) {
-    if (!isset($authenticated_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]);
-    }
-
-    if ($authenticated_post_comments) {
+    // We only output a link if we are certain that users will get permission
+    // to post comments by logging in.
+    if (user_role_has_permission(DRUPAL_AUTHENTICATED_RID, '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/forum/forum.module b/core/modules/forum/forum.module
index 459cbeb..2917079 100644
--- a/core/modules/forum/forum.module
+++ b/core/modules/forum/forum.module
@@ -198,15 +198,18 @@ function forum_menu_local_tasks_alter(&$data, $router_item, $root_path) {
         }
         // Anonymous user does not have access to create new topics.
         else {
-          $links['login'] = array(
-            '#theme' => 'menu_local_action',
-            '#link' => array(
-              'title' => t('<a href="@login">Log in</a> to post new content in the forum.', array(
-                '@login' => url('user/login', array('query' => drupal_get_destination())),
-              )),
-              'localized_options' => array('html' => TRUE),
-            ),
-          );
+          // If authenticated users can post new topic, provide a login link.
+          if (user_role_has_permission(DRUPAL_AUTHENTICATED_RID, 'create forum content')) {
+            $links['login'] = array(
+              '#theme' => 'menu_local_action',
+              '#link' => array(
+                'title' => t('<a href="@login">Log in</a> to post new content in the forum.', array(
+                  '@login' => url('user/login', array('query' => drupal_get_destination())),
+                )),
+                'localized_options' => array('html' => TRUE),
+              ),
+            );
+          }
         }
       }
       $data['actions']['output'] = array_merge($data['actions']['output'], $links);
diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumAnonymousTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumAnonymousTest.php
new file mode 100644
index 0000000..d6e468d
--- /dev/null
+++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumAnonymousTest.php
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\forum\Tests\ForumAnonymousTest.
+ */
+
+namespace Drupal\forum\Tests;
+
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests forum behavior for anonymous users.
+ */
+class ForumAnonymousTest extends WebTestBase {
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Forum anonymous',
+      'description' => 'Tests anonymous user messages.',
+      'group' => 'Forum',
+    );
+  }
+
+  public function setUp() {
+    parent::setUp('taxonomy', 'comment', 'forum');
+
+    // Create a test user.
+    $web_user = $this->drupalCreateUser(array(
+      'create forum content',
+      'edit own forum content',
+      'edit any forum content',
+      'administer nodes',
+    ));
+    $this->drupalLogin($web_user);
+  }
+
+  /**
+   * Tests that anonymous users receive correct messages.
+   *
+   * Verfies the presence of message "Log in to post new content in the forum"
+   * when the user is anonymous and the authenticated does not have the "Create
+   * new content" permission.
+   */
+  public function testAnonymousForumMessage() {
+    $langcode = LANGUAGE_NOT_SPECIFIED;
+
+    // The forum ID to use.
+    $tid = 1;
+
+    // Create a test node.
+    $title = $this->randomName(20);
+    $edit = array(
+      'title' => $title,
+      "body[$langcode][0][value]" => $this->randomName(25),
+      "taxonomy_forums[$langcode]" => array(1),
+    );
+
+    // Create the forum topic, preselecting the forum ID via a URL parameter.
+    $this->drupalPost('node/add/forum/' . $tid, $edit, t('Save'));
+    $this->drupalLogout();
+
+    // Access the forum list as an anonymous user and test for presence of
+    // message.
+    $this->drupalGet('forum');
+    $this->assertNoRaw(t('<a href="@login">Log in</a> to post new content in the forum.', array('@login' => url('user/login', array('query' => array('destination' => 'forum'))))), 'Log in or register message does not appear.');
+  }
+}
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index 6911853..c40846a 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -402,7 +402,7 @@ function user_password($length = 10) {
 }
 
 /**
- * Determine the permissions for one or more roles.
+ * Determines the permissions for one or more roles.
  *
  * @param $roles
  *   An array whose keys are the role IDs of interest, such as $user->roles.
@@ -448,6 +448,29 @@ function user_role_permissions($roles = array()) {
 }
 
 /**
+ * Determines the permissions for one or more roles.
+ *
+ * @param string $rid
+ *   Role ID of interest
+ *
+ * @param string $permission
+ *   Permission name, such as "administer nodes"
+ *
+ * @return boolean
+ *   TRUE if the given role has the requested permission.
+ */
+function user_role_has_permission($rid, $permission) {
+  // Get permissions of role given by ID.
+  // @todo: the user_role_permission method asks for rid => name but the name is
+  //   never used, should be improve?!
+  // @todo: should it be possible to handle multiple IDs?
+  $perms = user_role_permissions(array($rid => $rid));
+
+  // Returns TRUE if the role has the requested permission.
+  return isset($perms[$rid][$permission]);
+}
+
+/**
  * Determine whether the user has a given privilege.
  *
  * @param $string
