Repository: solid/community-server (ts)

Issue:
Create a flag for disabling registration
From https://github.com/solid/community-server/pull/815#discussion_r672869143

> Might be an idea for the future to have a configuration that allows having an IDP just to identify your own pod that does not allows registration for new pods. (Would be quite easy actually, just have to remove the registration handler from the list of handlers).

Idea: let's have an `SwitchableHandler` that either does nothing or throws an error if a certain flag is set (boolean parameter to the constructor). Then we could add that as a kill switch before the IDP registration handlers. Could operate independently or as a wrapper, similar to how `IfNeededConverter` is implemented.

Pull request description:
feat: Allow registration to be disabled
Closes #829 .

The interesting part about this config feature is that is also can be disabled by simply not importing the feature. I have also added a config file for disabling it though to be consistent with the other options.

Patch:
diff --git a/config/default.json b/config/default.json
index cfe4bd369..6a213cd47 100644
--- a/config/default.json
+++ b/config/default.json
@@ -11,6 +11,7 @@
     "files-scs:config/identity/handler/default.json",
     "files-scs:config/identity/ownership/token.json",
     "files-scs:config/identity/pod/static.json",
+    "files-scs:config/identity/registration/enabled.json",
     "files-scs:config/ldp/authentication/dpop-bearer.json",
     "files-scs:config/ldp/authorization/webacl.json",
     "files-scs:config/ldp/handler/default.json",
diff --git a/config/dynamic.json b/config/dynamic.json
index 21dbabb24..eb1429a15 100644
--- a/config/dynamic.json
+++ b/config/dynamic.json
@@ -11,6 +11,7 @@
     "files-scs:config/identity/handler/default.json",
     "files-scs:config/identity/ownership/token.json",
     "files-scs:config/identity/pod/dynamic.json",
+    "files-scs:config/identity/registration/enabled.json",
     "files-scs:config/ldp/authentication/dpop-bearer.json",
     "files-scs:config/ldp/authorization/webacl.json",
     "files-scs:config/ldp/handler/default.json",
diff --git a/config/example-https-file.json b/config/example-https-file.json
index f5e510def..bb913f216 100644
--- a/config/example-https-file.json
+++ b/config/example-https-file.json
@@ -11,6 +11,7 @@
     "files-scs:config/identity/handler/default.json",
     "files-scs:config/identity/ownership/token.json",
     "files-scs:config/identity/pod/static.json",
+    "files-scs:config/identity/registration/enabled.json",
     "files-scs:config/ldp/authentication/dpop-bearer.json",
     "files-scs:config/ldp/authorization/webacl.json",
     "files-scs:config/ldp/handler/default.json",
diff --git a/config/file.json b/config/file.json
index 262a8fd96..befd58868 100644
--- a/config/file.json
+++ b/config/file.json
@@ -11,6 +11,7 @@
     "files-scs:config/identity/handler/default.json",
     "files-scs:config/identity/ownership/token.json",
     "files-scs:config/identity/pod/static.json",
+    "files-scs:config/identity/registration/enabled.json",
     "files-scs:config/ldp/authentication/dpop-bearer.json",
     "files-scs:config/ldp/authorization/webacl.json",
     "files-scs:config/ldp/handler/default.json",
diff --git a/config/identity/README.md b/config/identity/README.md
index 12ff67e96..80fd6d187 100644
--- a/config/identity/README.md
+++ b/config/identity/README.md
@@ -23,3 +23,8 @@ What to use for pod creation.
 * *dynamic*: Every created pod has its own Components.js config for its ResourceStore,
   which can differ from the others.
 * *static*: All pod data is stored in separate containers in the same ResourceStore.
+
+## Registration
+If users should be able to register on the server.
+* *enabled*: Enables registration.
+* *disabled*: Disables registration.
diff --git a/config/identity/handler/interaction/handler.json b/config/identity/handler/interaction/handler.json
index 94e2b9553..02de864c8 100644
--- a/config/identity/handler/interaction/handler.json
+++ b/config/identity/handler/interaction/handler.json
@@ -4,7 +4,6 @@
     "files-scs:config/identity/handler/interaction/handlers/forgot-password.json",
     "files-scs:config/identity/handler/interaction/handlers/initial.json",
     "files-scs:config/identity/handler/interaction/handlers/login.json",
-    "files-scs:config/identity/handler/interaction/handlers/registration.json",
     "files-scs:config/identity/handler/interaction/handlers/reset-password.json",
     "files-scs:config/identity/handler/interaction/handlers/session.json"
   ],
@@ -15,7 +14,6 @@
       "@type": "WaterfallHandler",
       "handlers": [
         { "@id": "urn:solid-server:auth:password:InitialInteractionHandler" },
-        { "@id": "urn:solid-server:auth:password:RegistrationInteractionHandler" },
         { "@id": "urn:solid-server:auth:password:LoginInteractionHandler" },
         { "@id": "urn:solid-server:auth:password:SessionInteractionHandler" },
         { "@id": "urn:solid-server:auth:password:ForgotPasswordInteractionHandler" },
diff --git a/config/identity/registration/disabled.json b/config/identity/registration/disabled.json
new file mode 100644
index 000000000..e4627517a
--- /dev/null
+++ b/config/identity/registration/disabled.json
@@ -0,0 +1,8 @@
+{
+  "@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^1.0.0/components/context.jsonld",
+  "@graph": [
+    {
+      "comment": "Disable registration by not attaching a registration handler."
+    }
+  ]
+}
diff --git a/config/identity/registration/enabled.json b/config/identity/registration/enabled.json
new file mode 100644
index 000000000..8c5194b3c
--- /dev/null
+++ b/config/identity/registration/enabled.json
@@ -0,0 +1,15 @@
+{
+  "@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^1.0.0/components/context.jsonld",
+  "import": [
+    "files-scs:config/identity/registration/handler/registration.json"
+  ],
+  "@graph": [
+    {
+      "comment": "Enable registration by adding a registration handler to the list of interaction handlers.",
+      "@id": "urn:solid-server:auth:password:InteractionHttpHandler",
+      "WaterfallHandler:_handlers": [
+        { "@id": "urn:solid-server:auth:password:RegistrationInteractionHandler" }
+      ]
+    }
+  ]
+}
diff --git a/config/identity/handler/interaction/handlers/registration.json b/config/identity/registration/handler/registration.json
similarity index 100%
rename from config/identity/handler/interaction/handlers/registration.json
rename to config/identity/registration/handler/registration.json
diff --git a/config/memory-subdomains.json b/config/memory-subdomains.json
index 0b167817a..2a495e03d 100644
--- a/config/memory-subdomains.json
+++ b/config/memory-subdomains.json
@@ -11,6 +11,7 @@
     "files-scs:config/identity/handler/default.json",
     "files-scs:config/identity/ownership/token.json",
     "files-scs:config/identity/pod/static.json",
+    "files-scs:config/identity/registration/enabled.json",
     "files-scs:config/ldp/authentication/dpop-bearer.json",
     "files-scs:config/ldp/authorization/webacl.json",
     "files-scs:config/ldp/handler/default.json",
diff --git a/config/path-routing.json b/config/path-routing.json
index 231a5647f..67e3df917 100644
--- a/config/path-routing.json
+++ b/config/path-routing.json
@@ -11,6 +11,7 @@
     "files-scs:config/identity/handler/default.json",
     "files-scs:config/identity/ownership/token.json",
     "files-scs:config/identity/pod/static.json",
+    "files-scs:config/identity/registration/enabled.json",
     "files-scs:config/ldp/authentication/dpop-bearer.json",
     "files-scs:config/ldp/authorization/webacl.json",
     "files-scs:config/ldp/handler/default.json",


Test patch:
diff --git a/test/integration/config/server-dynamic-unsafe.json b/test/integration/config/server-dynamic-unsafe.json
index 2d5064226..0e5cdef13 100644
--- a/test/integration/config/server-dynamic-unsafe.json
+++ b/test/integration/config/server-dynamic-unsafe.json
@@ -11,6 +11,7 @@
     "files-scs:config/identity/handler/default.json",
     "files-scs:config/identity/ownership/unsafe-no-check.json",
     "files-scs:config/identity/pod/dynamic.json",
+    "files-scs:config/identity/registration/enabled.json",
     "files-scs:config/ldp/authentication/debug-auth-header.json",
     "files-scs:config/ldp/authorization/webacl.json",
     "files-scs:config/ldp/handler/default.json",
diff --git a/test/integration/config/server-memory.json b/test/integration/config/server-memory.json
index 4bc3bf1f6..122c004c6 100644
--- a/test/integration/config/server-memory.json
+++ b/test/integration/config/server-memory.json
@@ -10,6 +10,7 @@
     "files-scs:config/identity/handler/default.json",
     "files-scs:config/identity/ownership/token.json",
     "files-scs:config/identity/pod/static.json",
+    "files-scs:config/identity/registration/enabled.json",
     "files-scs:config/ldp/authentication/dpop-bearer.json",
     "files-scs:config/ldp/authorization/webacl.json",
     "files-scs:config/ldp/handler/default.json",
diff --git a/test/integration/config/server-subdomains-unsafe.json b/test/integration/config/server-subdomains-unsafe.json
index 0c972c83e..741180e25 100644
--- a/test/integration/config/server-subdomains-unsafe.json
+++ b/test/integration/config/server-subdomains-unsafe.json
@@ -11,6 +11,7 @@
     "files-scs:config/identity/handler/default.json",
     "files-scs:config/identity/ownership/unsafe-no-check.json",
     "files-scs:config/identity/pod/static.json",
+    "files-scs:config/identity/registration/enabled.json",
     "files-scs:config/ldp/authentication/debug-auth-header.json",
     "files-scs:config/ldp/authorization/webacl.json",
     "files-scs:config/ldp/handler/default.json",