/*
 *  [2012] - [2016] 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.im;

import com.codenvy.auth.sso.client.LoginFilter;
import com.codenvy.auth.sso.client.deploy.SsoClientServletModule;
import com.google.inject.name.Names;
import com.google.inject.servlet.ServletModule;

import org.eclipse.che.inject.DynaModule;
import org.everrest.guice.servlet.GuiceEverrestServlet;

/** @author Anatoliy Bazko */
@DynaModule
public class UpdateServerServletModule extends ServletModule {

    @Override
    protected void configureServlets() {
        bindConstant().annotatedWith(Names.named("auth.sso.client_allow_anonymous")).to(false);
        bindConstant().annotatedWith(Names.named("auth.sso.login_page_url")).to("/site/login");
        bindConstant().annotatedWith(Names.named("auth.sso.cookies_disabled_error_page_url")).to("/site/error/error-cookies-disabled");
        bindConstant().annotatedWith(Names.named("auth.sso.client_skip_filter_regexp")).to(".*((/repository/(updates|properties|public/download|log-event)/)"
                                                                                           + "|(/report/parameters)"
                                                                                           + "|(/util/client-ip)).*");

        bind(com.codenvy.auth.sso.client.WebAppClientUrlExtractor.class);
        bind(com.codenvy.auth.sso.client.token.ChainedTokenExtractor.class);
        bind(com.codenvy.auth.sso.client.filter.RequestFilter.class).to(com.codenvy.auth.sso.client.filter.RegexpRequestFilter.class);
        bind(com.codenvy.auth.sso.client.TokenHandler.class).to(com.codenvy.auth.sso.client.RecoverableTokenHandler.class);

        filterRegex("/(?!_sso/).*$",
                    "/repository/download").through(LoginFilter.class);
        install(new SsoClientServletModule());
        serve("/*").with(GuiceEverrestServlet.class);
    }
}

@@ -643,25 +643,191 @@
 .client.
-LoginFilt
+ClientUrlExtractor;%0Aimport com.codenvy.auth.sso.client.LoginFilter;%0Aimport com.codenvy.auth.sso.client.RecoverableTokenHandler;%0Aimport com.codenvy.auth.sso.client.RequestWrapp
 er;%0Aimpo
@@ -884,24 +884,61 @@
 vletModule;%0A
+import com.google.inject.name.Named;%0A
 import com.g
@@ -1014,105 +1014,430 @@
 le;%0A
-%0Aimport org.eclipse.che.inject.DynaModule;%0Aimport org.everrest.guice.servlet.GuiceEverrestServlet
+import org.eclipse.che.commons.env.EnvironmentContext;%0Aimport org.eclipse.che.commons.subject.Subject;%0Aimport org.eclipse.che.inject.DynaModule;%0Aimport org.everrest.guice.servlet.GuiceEverrestServlet;%0A%0Aimport javax.inject.Inject;%0Aimport javax.servlet.FilterChain;%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0Aimport java.io.IOException
 ;%0A%0A/
@@ -2673,47 +2673,21 @@
 .to(
-com.codenvy.auth.sso.client.Recoverable
+AnonymousUser
 Toke
@@ -2743,52 +2743,8 @@
 .*$%22
-,%0A                    %22/repository/download%22
 ).th
@@ -2865,21 +2865,1115 @@
 vlet.class);
+%0A    %7D%0A%0A    public static class AnonymousUserTokenHandler extends RecoverableTokenHandler %7B%0A%0A        @Inject%0A        public AnonymousUserTokenHandler(RequestWrapper requestWrapper,%0A                                         ClientUrlExtractor clientUrlExtractor,%0A                                         @Named(%22auth.sso.client_allow_anonymous%22) boolean allowAnonymous) %7B%0A            super(requestWrapper, clientUrlExtractor, allowAnonymous);%0A        %7D%0A%0A        @Override public void handleMissingToken(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException %7B%0A            if (!%22GET%22.equals(request.getMethod())) %7B%0A                //go with anonymous%0A                EnvironmentContext environmentContext = EnvironmentContext.getCurrent();%0A                environmentContext.setSubject(Subject.ANONYMOUS);%0A                chain.doFilter(requestWrapper.wrapRequest(request.getSession(), request, Subject.ANONYMOUS), response);%0A            %7D else %7B%0A                super.handleMissingToken(request, response, chain);%0A            %7D%0A        %7D
 %0A    %7D%0A%7D%0A

fix error of logging event by using Update Server