1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-29 21:09:56 +00:00

server: Authorize only authenticated users when using a credentials file

This commit is contained in:
quentin 2021-03-10 23:16:41 +01:00
parent 1f2e0ed189
commit 21a3bbf9d6

View File

@ -52,14 +52,21 @@ function Server(options) {
// Initialize browser-caching // Initialize browser-caching
this.enableBrowserCache = this.get("use-browser-cache") === "yes"; this.enableBrowserCache = this.get("use-browser-cache") === "yes";
// Initialise authorization // Initialise authorization
var authorizedUserName = (this.get("username") && this.get("password")) ? this.get("username") : "(anon)"; var authorizedUserName;
if(this.get("username") && this.get("password")) {
authorizedUserName = this.get("username");
} else if(this.get("credentials")) {
authorizedUserName = "(authenticated)";
} else {
authorizedUserName = "(anon)";
}
this.authorizationPrincipals = { this.authorizationPrincipals = {
readers: (this.get("readers") || authorizedUserName).split(",").map($tw.utils.trim), readers: (this.get("readers") || authorizedUserName).split(",").map($tw.utils.trim),
writers: (this.get("writers") || authorizedUserName).split(",").map($tw.utils.trim) writers: (this.get("writers") || authorizedUserName).split(",").map($tw.utils.trim)
} }
// Load and initialise authenticators // Load and initialise authenticators
$tw.modules.forEachModuleOfType("authenticator", function(title,authenticatorDefinition) { $tw.modules.forEachModuleOfType("authenticator", function(title,authenticatorDefinition) {
// console.log("Loading server route " + title); // console.log("Loading authenticator " + title);
self.addAuthenticator(authenticatorDefinition.AuthenticatorClass); self.addAuthenticator(authenticatorDefinition.AuthenticatorClass);
}); });
// Load route handlers // Load route handlers