This project has retired. For details please refer to its
Attic page.
ProxyFilter xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.server.filter;
2021import java.io.IOException;
22import java.util.regex.Pattern;
2324import javax.servlet.Filter;
25import javax.servlet.FilterChain;
26import javax.servlet.FilterConfig;
27import javax.servlet.ServletException;
28import javax.servlet.ServletRequest;
29import javax.servlet.ServletResponse;
30import javax.servlet.http.HttpServletRequest;
3132/**33 * A filter that corrects server name, server port and scheme if OpenCMIS is34 * running behind a proxy or load balancer.35 */36publicclassProxyFilter implements Filter {
3738publicstaticfinal String PARAM_TRUSTED_PROXIES = "trustedProxies";
3940private Pattern trustedProxies;
4142publicvoid init(FilterConfig filterConfig) throws ServletException {
43 trustedProxies = null;
44 String trustedProxiesString = filterConfig.getInitParameter(PARAM_TRUSTED_PROXIES);
45if (trustedProxiesString != null) {
46try {
47 trustedProxies = Pattern.compile(trustedProxiesString);
48 } catch (Exception e) {
49thrownew ServletException("Could not compile trustedProxies parameter: " + e, e);
50 }
51 }
52 }
5354publicvoid doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
55 ServletException {
5657// check for trusted proxy58if (trustedProxies != null && (request instanceof HttpServletRequest)
59 && trustedProxies.matcher(request.getRemoteAddr()).matches()) {
60 request = newProxyHttpServletRequestWrapper((HttpServletRequest) request);
61 }
6263// call next64 chain.doFilter(request, response);
65 }
6667publicvoid destroy() {
68 }
69 }