From f551d1c75630c77c1968820300c0c4076408b1c3 Mon Sep 17 00:00:00 2001
From: Wim Leers <wim.leers@acquia.com>
Date: Thu, 1 Dec 2016 18:20:13 +0100
Subject: [PATCH 1/4] s1

---
 core/modules/rest/src/RestResourceConfigInterface.php                 | 4 ++--
 .../tests/src/Functional/EntityResource/EntityResourceTestBase.php    | 2 +-
 core/modules/rest/tests/src/Functional/ResourceTestBase.php           | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/core/modules/rest/src/RestResourceConfigInterface.php b/core/modules/rest/src/RestResourceConfigInterface.php
index 601bb0e..a2660f0 100644
--- a/core/modules/rest/src/RestResourceConfigInterface.php
+++ b/core/modules/rest/src/RestResourceConfigInterface.php
@@ -42,8 +42,8 @@ public function getMethods();
    * @param string $method
    *   The request method e.g GET or POST.
    *
-   * @return string[]
-   *   A list of supported authentication provider IDs.
+   * @return string[]|null
+   *   A list of supported authentication provider IDs, or NULL if
    */
   public function getAuthenticationProviders($method);
 
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
index 973f5b9..7c8bd48 100644
--- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
+++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
@@ -143,7 +143,7 @@
   protected function provisionEntityResource() {
     // It's possible to not have any authentication providers enabled, when
     // testing public (anonymous) usage of a REST resource.
-    $auth = isset(static::$auth) ? [static::$auth] : [];
+    $auth = static::$auth !== FALSE ? [static::$auth] : NULL;
     $this->provisionResource('entity.' . static::$entityTypeId, [static::$format], $auth);
   }
 
diff --git a/core/modules/rest/tests/src/Functional/ResourceTestBase.php b/core/modules/rest/tests/src/Functional/ResourceTestBase.php
index f1f0458..974ec30 100644
--- a/core/modules/rest/tests/src/Functional/ResourceTestBase.php
+++ b/core/modules/rest/tests/src/Functional/ResourceTestBase.php
@@ -139,10 +139,10 @@ public function setUp() {
    *   The resource type (REST resource plugin ID).
    * @param string[] $formats
    *   The allowed formats for this resource.
-   * @param string[] $authentication
+   * @param string[]|null $authentication
    *   The allowed authentication providers for this resource.
    */
-  protected function provisionResource($resource_type, $formats = [], $authentication = []) {
+  protected function provisionResource($resource_type, array $formats = [], $authentication) {
     $this->resourceConfigStorage->create([
       'id' => $resource_type,
       'granularity' => RestResourceConfigInterface::RESOURCE_GRANULARITY,
-- 
2.10.1


From 5a3929dac33fc5019fc54ce0c6691c9e13966d3d Mon Sep 17 00:00:00 2001
From: Wim Leers <wim.leers@acquia.com>
Date: Thu, 1 Dec 2016 18:20:22 +0100
Subject: [PATCH 2/4] s2

---
 core/modules/rest/src/Entity/ConfigDependencies.php | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/core/modules/rest/src/Entity/ConfigDependencies.php b/core/modules/rest/src/Entity/ConfigDependencies.php
index 4b03057..d9ef20a 100644
--- a/core/modules/rest/src/Entity/ConfigDependencies.php
+++ b/core/modules/rest/src/Entity/ConfigDependencies.php
@@ -90,7 +90,14 @@ public function calculateDependencies(RestResourceConfigInterface $rest_config)
     $dependencies = [];
     foreach ($methods as $request_method) {
       // Add dependencies based on the supported authentication providers.
-      foreach ($rest_config->getAuthenticationProviders($request_method) as $auth) {
+      $auth_providers = $rest_config->getAuthenticationProviders($request_method);
+      // If NULL, that means "no authentication providers at all", which implies
+      // only anonymous access is allowed (and hence only the access checking
+      // within the ResourceInterface plugin is applied).
+      if ($auth_providers === NULL) {
+        continue;
+      }
+      foreach ($auth_providers as $auth) {
         if (isset($this->authProviders[$auth])) {
           $module_name = $this->authProviders[$auth];
           $dependencies['module'][] = $module_name;
-- 
2.10.1


From fa3a94883f7db7880b87e698b31d79723996a189 Mon Sep 17 00:00:00 2001
From: Wim Leers <wim.leers@acquia.com>
Date: Thu, 1 Dec 2016 18:20:32 +0100
Subject: [PATCH 3/4] s3

---
 core/modules/rest/config/schema/rest.schema.yml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/core/modules/rest/config/schema/rest.schema.yml b/core/modules/rest/config/schema/rest.schema.yml
index 2c255ab..0aceea6 100644
--- a/core/modules/rest/config/schema/rest.schema.yml
+++ b/core/modules/rest/config/schema/rest.schema.yml
@@ -45,6 +45,7 @@ rest_resource.resource:
         label: 'Format'
     authentication:
       type: sequence
+      nullable: true
       label: 'Supported authentication providers'
       sequence:
         type: string
@@ -61,6 +62,7 @@ rest_request:
         label: 'Format'
     supported_auth:
       type: sequence
+      nullable: true
       label: 'Supported authentication'
       sequence:
         type: string
-- 
2.10.1


From 422a7a552e1f4e681abe17d820e08ef4b9b417a8 Mon Sep 17 00:00:00 2001
From: Wim Leers <wim.leers@acquia.com>
Date: Thu, 1 Dec 2016 18:24:11 +0100
Subject: [PATCH 4/4] s4

---
 core/modules/rest/src/Routing/ResourceRoutes.php | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/core/modules/rest/src/Routing/ResourceRoutes.php b/core/modules/rest/src/Routing/ResourceRoutes.php
index 8aedfba..d31a3e4 100644
--- a/core/modules/rest/src/Routing/ResourceRoutes.php
+++ b/core/modules/rest/src/Routing/ResourceRoutes.php
@@ -94,7 +94,8 @@ protected function getRoutesForResourceConfig(RestResourceConfigInterface $rest_
         $route->setRequirement('_csrf_request_header_token', 'TRUE');
 
         // Check that authentication providers are defined.
-        if (empty($rest_resource_config->getAuthenticationProviders($method))) {
+        $auth_providers = $rest_resource_config->getAuthenticationProviders($method);
+        if (empty($auth_providers) && $auth_providers !== NULL) {
           $this->logger->error('At least one authentication provider must be defined for resource @id', array(':id' => $rest_resource_config->id()));
           continue;
         }
@@ -114,7 +115,9 @@ protected function getRoutesForResourceConfig(RestResourceConfigInterface $rest_
 
         // The configuration seems legit at this point, so we set the
         // authentication provider and add the route.
-        $route->setOption('_auth', $rest_resource_config->getAuthenticationProviders($method));
+        if ($auth_providers !== NULL) {
+          $route->setOption('_auth', $auth_providers);
+        }
         $route->setDefault('_rest_resource_config', $rest_resource_config->id());
         $collection->add("rest.$name", $route);
       }
-- 
2.10.1

