mbien commented on code in PR #189:
URL: https://github.com/apache/roller/pull/189#discussion_r4042017332


##########
app/src/main/java/org/apache/roller/weblogger/ui/core/filters/BootstrapSecurityFilter.java:
##########
@@ -0,0 +1,29 @@
+package org.apache.roller.weblogger.ui.core.filters;
+
+import java.io.IOException;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import org.apache.roller.weblogger.business.WebloggerFactory;
+import org.apache.roller.weblogger.ui.core.security.BootstrapSecurity;
+
+/** Prevents anonymous access to installer and first-user actions. */
+public class BootstrapSecurityFilter implements Filter {
+    public void doFilter(ServletRequest req, ServletResponse res, FilterChain 
chain) throws IOException, ServletException {
+        HttpServletRequest r = (HttpServletRequest) req;
+        HttpServletResponse p = (HttpServletResponse) res;
+        String uri = r.getRequestURI();
+        boolean tokenPage = uri != null && 
(uri.endsWith("/bootstrap-token.rol")
+                || uri.endsWith("/bootstrap-token!redeem.rol"));
+        boolean installer = uri != null && (tokenPage || 
uri.contains("/roller-ui/install/")
+                || uri.endsWith("/roller-ui/register.rol")
+                || uri.endsWith("/roller-ui/register!save.rol")
+                || uri.endsWith("/roller-ui/setup.rol"));
+        if (installer && !BootstrapSecurity.isCompleted()) {

Review Comment:
   nitpick: i would consider putting 
   
   ```
   if (BootstrapSecurity.isCompleted()) {
           chain.doFilter(req, res);
           return;
   }
   ```
   as fast path to the beginning of the method. (`&& 
!BootstrapSecurity.isCompleted()` can be removed afterwards). This would also 
make it clear that the filter becomes a no-op after bootstrap is done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to