/*
 * CODENVY CONFIDENTIAL
 * __________________
 *
 *  [2012] - [2014] Codenvy, S.A.
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Codenvy S.A. and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Codenvy S.A.
 * and its suppliers and may be covered by U.S. and Foreign Patents,
 * patents in process, and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Codenvy S.A..
 */
package com.codenvy.analytics.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.Principal;

import static com.codenvy.analytics.Utils.isAnonymousUser;

/**
 * The purpose is in redirection anonymous users to an account creation page.
 *
 * @author Anatoliy Bazko
 */
public class AnalyticsFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

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

        Principal userPrincipal = httpRequest.getUserPrincipal();
        if (userPrincipal == null || isAnonymousUser(userPrincipal.getName())) {
            String url = httpRequest.getRequestURL().toString();
            String baseUrl = url.substring(0, url.length() - httpRequest.getRequestURI().length());

            httpResponse.sendRedirect(baseUrl + "/site/create-account");
        } else {
            chain.doFilter(request, response);
        }
    }

    @Override
    public void destroy() {
    }
}

@@ -671,16 +671,53 @@
 ilter;%0A%0A
+import com.google.inject.Singleton;%0A%0A
 import j
@@ -1061,16 +1061,27 @@
 zko%0A */%0A
+@Singleton%0A
 public c

Allow to configure admin logins, for example: analytics.admin_login_regexp=.+@codenvy[.]com