package org.thethingsnetwork.zrh.monitor.ui.html;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.scout.rt.platform.BEANS;
import org.eclipse.scout.rt.server.commons.authentication.ConfigFileCredentialVerifier;
import org.eclipse.scout.rt.server.commons.authentication.DevelopmentAccessController;
import org.eclipse.scout.rt.server.commons.authentication.FormBasedAccessController;
import org.eclipse.scout.rt.server.commons.authentication.FormBasedAccessController.FormBasedAuthConfig;
import org.eclipse.scout.rt.server.commons.authentication.ServletFilterHelper;
import org.eclipse.scout.rt.server.commons.authentication.TrivialAccessController;
import org.eclipse.scout.rt.server.commons.authentication.TrivialAccessController.TrivialAuthConfig;

/**
 * <h3>{@link UiServletFilter}</h3>
 * This is the main servlet filter used for the HTML UI.
 *
 * @author mzi
 */
public class UiServletFilter implements Filter {

  private TrivialAccessController m_trivialAccessController;
  private FormBasedAccessController m_formBasedAccessController;
  private DevelopmentAccessController m_developmentAccessController;

  @Override
  public void init(FilterConfig filterConfig) throws ServletException {
    m_trivialAccessController = BEANS.get(TrivialAccessController.class)
        .init(new TrivialAuthConfig()
            .withExclusionFilter(filterConfig.getInitParameter("filter-exclude"))
            .withLoginPageInstalled(true));
    m_formBasedAccessController = BEANS.get(FormBasedAccessController.class)
        .init(new FormBasedAuthConfig()
            .withCredentialVerifier(BEANS.get(ConfigFileCredentialVerifier.class)));
    m_developmentAccessController = BEANS.get(DevelopmentAccessController.class).init();
  }

  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    final HttpServletRequest req = (HttpServletRequest) request;
    final HttpServletResponse resp = (HttpServletResponse) response;

    if (m_trivialAccessController.handle(req, resp, chain)) {
      return;
    }

    if (m_formBasedAccessController.handle(req, resp, chain)) {
      return;
    }

    if (m_developmentAccessController.handle(req, resp, chain)) {
      return;
    }

    BEANS.get(ServletFilterHelper.class).forwardToLoginForm(req, resp);
  }

  @Override
  public void destroy() {
    m_developmentAccessController.destroy();
    m_formBasedAccessController.destroy();
    m_trivialAccessController.destroy();
  }
}

@@ -423,16 +423,101 @@
 .BEANS;%0A
+import org.eclipse.scout.rt.server.commons.authentication.AnonymousAccessController;%0A
 import o
@@ -1320,78 +1320,23 @@
 ate 
-TrivialAccessController m_trivialAccessController;%0A  private FormBased
+final Anonymous
 Acce
@@ -1350,25 +1350,25 @@
 oller m_
-formBased
+anonymous
 AccessCo
@@ -1379,61 +1379,30 @@
 ller
-;%0A  private DevelopmentAccessController m_development
+ = BEANS.get(Anonymous
 Acce
@@ -1413,16 +1413,23 @@
 ntroller
+.class)
 ;%0A%0A  @Ov
@@ -1511,527 +1511,38 @@
 n %7B%0A
-  
+%09
   m_
-trivialAccessController = BEANS.get(TrivialAccessController.class)%0A        .init(new TrivialAuthConfig()%0A            .withExclusionFilter(filterConfig.getInitParameter(%22filter-exclude%22))%0A            .withLoginPageInstalled(true));%0A    m_formBasedAccessController = BEANS.get(FormBasedAccessController.class)%0A        .init(new FormBasedAuthConfig()%0A            .withCredentialVerifier(BEANS.get(ConfigFileCredentialVerifier.class)));%0A    m_developmentAccessController = BEANS.get(DevelopmentAccessController.class)
+anonymousAccessController
 .ini
@@ -1832,333 +1832,63 @@
 se;%0A
-%0A
     
-if (m_trivialAccessController.handle(req, resp, chain)) %7B%0A      return;%0A    %7D%0A%0A    if (m_formBasedAccessController.handle(req, resp, chain)) %7B%0A      return;%0A    %7D%0A%0A    if (m_developmentAccessController.handle(req, resp, chain)) %7B%0A      return;%0A    %7D%0A%0A    BEANS.get(ServletFilterHelper.class).forwardToLoginForm(req, resp
+m_anonymousAccessController.handle(req, resp, chain
 );%0A 
@@ -1933,109 +1933,22 @@
 ) %7B%0A
-  
+%09
   m_
-developmentAccessController.destroy();%0A    m_formBasedAccessController.destroy();%0A    m_trivial
+anonymous
 Acce

change to anonymous login