@@ -0,0 +1,3154 @@
+/*%0A * CODENVY CONFIDENTIAL%0A * __________________%0A *%0A *  %5B2012%5D - %5B2016%5D Codenvy, S.A.%0A *  All Rights Reserved.%0A *%0A * NOTICE:  All information contained herein is, and remains%0A * the property of Codenvy S.A. and its suppliers,%0A * if any.  The intellectual and technical concepts contained%0A * herein are proprietary to Codenvy S.A.%0A * and its suppliers and may be covered by U.S. and Foreign Patents,%0A * patents in process, and are protected by trade secret or copyright law.%0A * Dissemination of this information or reproduction of this material%0A * is strictly forbidden unless prior written permission is obtained%0A * from Codenvy S.A..%0A */%0Apackage com.codenvy.auth.sso.client;%0A%0Aimport com.google.inject.Inject;%0Aimport com.google.inject.name.Named;%0A%0Aimport javax.inject.Singleton;%0Aimport javax.servlet.Filter;%0Aimport javax.servlet.FilterChain;%0Aimport javax.servlet.FilterConfig;%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.ServletRequest;%0Aimport javax.servlet.ServletResponse;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletRequestWrapper;%0Aimport javax.ws.rs.core.HttpHeaders;%0Aimport java.io.IOException;%0Aimport java.util.Collections;%0Aimport java.util.Enumeration;%0Aimport java.util.List;%0A%0A/**%0A * Set user token to authorization header to each machine request.%0A *%0A * @author Anton Korneta%0A */%0A@Singleton%0Apublic class MachineRequestTokenInjectFilter implements Filter %7B%0A%0A    @Inject%0A    @Named(%22user.token%22)%0A    private String userToken;%0A%0A    @Override%0A    public void init(FilterConfig filterConfig) throws ServletException %7B%0A    %7D%0A%0A    @Override%0A    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)%0A            throws IOException, ServletException %7B%0A        final AddAuthorizationHeaderRequestWrapper modifiedRequest = new AddAuthorizationHeaderRequestWrapper(((HttpServletRequest) servletRequest));%0A        filterChain.doFilter(modifiedRequest, servletResponse);%0A    %7D%0A%0A    @Override%0A    public void destroy() %7B%0A    %7D%0A%0A    private class AddAuthorizationHeaderRequestWrapper extends HttpServletRequestWrapper %7B%0A        public AddAuthorizationHeaderRequestWrapper(HttpServletRequest request) %7B%0A            super(request);%0A        %7D%0A%0A        @Override%0A        public String getHeader(String name) %7B%0A            if (HttpHeaders.AUTHORIZATION.equals(name)) %7B%0A                return userToken;%0A            %7D%0A            return super.getHeader(name);%0A        %7D%0A%0A        @Override%0A        public Enumeration%3CString%3E getHeaderNames() %7B%0A            final List%3CString%3E names = Collections.list(super.getHeaderNames());%0A            if (!names.contains(HttpHeaders.AUTHORIZATION)) %7B%0A                names.add(HttpHeaders.AUTHORIZATION);%0A            %7D%0A            return Collections.enumeration(names);%0A        %7D%0A%0A        @Override%0A        public Enumeration%3CString%3E getHeaders(String name) %7B%0A            final List%3CString%3E values = Collections.list(super.getHeaders(name));%0A            if (HttpHeaders.AUTHORIZATION.equals(name)) %7B%0A                values.add(userToken);%0A            %7D%0A            return Collections.enumeration(values);%0A        %7D%0A    %7D%0A%7D%0A

Add machine request filter