Implement full access requirement in all pages.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 7 May 2011 00:13:38 +0000 (02:13 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 7 May 2011 00:13:38 +0000 (02:13 +0200)
src/main/java/net/pterodactylus/sone/web/CreateSonePage.java
src/main/java/net/pterodactylus/sone/web/LoginPage.java
src/main/java/net/pterodactylus/sone/web/LogoutPage.java
src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java
src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java
src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java

index 2e2fc41..3f940a3 100644 (file)
@@ -129,6 +129,9 @@ public class CreateSonePage extends SoneTemplatePage {
         */
        @Override
        public boolean isEnabled(ToadletContext toadletContext) {
+               if (webInterface.getCore().getPreferences().isRequireFullAccess() && !toadletContext.isAllowedFullAccess()) {
+                       return false;
+               }
                return (getCurrentSone(toadletContext, false) == null) || (webInterface.getCore().getLocalSones().size() == 1);
        }
 
index 321193b..8e612ea 100644 (file)
@@ -103,6 +103,9 @@ public class LoginPage extends SoneTemplatePage {
         */
        @Override
        public boolean isEnabled(ToadletContext toadletContext) {
+               if (webInterface.getCore().getPreferences().isRequireFullAccess() && !toadletContext.isAllowedFullAccess()) {
+                       return false;
+               }
                return getCurrentSone(toadletContext, false) == null;
        }
 
index 4510bc1..7cd0587 100644 (file)
@@ -57,6 +57,9 @@ public class LogoutPage extends SoneTemplatePage {
         */
        @Override
        public boolean isEnabled(ToadletContext toadletContext) {
+               if (webInterface.getCore().getPreferences().isRequireFullAccess() && !toadletContext.isAllowedFullAccess()) {
+                       return false;
+               }
                return (getCurrentSone(toadletContext, false) != null) && (webInterface.getCore().getLocalSones().size() != 1);
        }
 
index 7392de4..42c0129 100644 (file)
@@ -296,7 +296,18 @@ public class SoneTemplatePage extends FreenetTemplatePage {
         * {@inheritDoc}
         */
        @Override
+       protected boolean isFullAccessOnly() {
+               return webInterface.getCore().getPreferences().isRequireFullAccess();
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
        public boolean isEnabled(ToadletContext toadletContext) {
+               if (webInterface.getCore().getPreferences().isRequireFullAccess() && !toadletContext.isAllowedFullAccess()) {
+                       return false;
+               }
                if (requiresLogin()) {
                        return getCurrentSone(toadletContext, false) != null;
                }
index 8d48bce..893b7ae 100644 (file)
@@ -188,6 +188,9 @@ public abstract class JsonPage implements Page {
         */
        @Override
        public Response handleRequest(Request request) {
+               if (webInterface.getCore().getPreferences().isRequireFullAccess() && !request.getToadletContext().isAllowedFullAccess()) {
+                       return new Response(401, "Not authorized", "application/json", JsonUtils.format(new JsonObject().put("success", false).put("error", "auth-required")));
+               }
                if (needsFormPassword()) {
                        String formPassword = request.getHttpRequest().getParam("formPassword");
                        if (!webInterface.getFormPassword().equals(formPassword)) {
index 6e7812f..5831a1b 100644 (file)
@@ -109,6 +109,9 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback {
                        return new RedirectResponse(redirectTarget);
                }
 
+               if (isFullAccessOnly() && !request.getToadletContext().isAllowedFullAccess()) {
+                       return new Response(401, "Not authorized", "text/html", "Not authorized");
+               }
                ToadletContext toadletContext = request.getToadletContext();
                if (request.getMethod() == Method.POST) {
                        /* require form password. */
@@ -227,6 +230,17 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback {
                return Collections.emptyList();
        }
 
+       /**
+        * Returns whether this page should only be allowed for requests from hosts
+        * with full access.
+        *
+        * @return {@code true} if this page should only be allowed for hosts with
+        *         full access, {@code false} to allow this page for any host
+        */
+       protected boolean isFullAccessOnly() {
+               return false;
+       }
+
        //
        // INTERFACE LinkEnabledCallback
        //
@@ -236,7 +250,7 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback {
         */
        @Override
        public boolean isEnabled(ToadletContext toadletContext) {
-               return true;
+               return !isFullAccessOnly();
        }
 
        /**