<url-pattern>/robots.txt</url-pattern>\r
</servlet-mapping>\r
\r
+ <filter>\r
+ <filter-name>ProxyFilter</filter-name>\r
+ <filter-class>com.gitblit.servlet.ProxyFilter</filter-class>\r
+ </filter>\r
+ <filter-mapping>\r
+ <filter-name>ProxyFilter</filter-name>\r
+ <url-pattern>/*</url-pattern>\r
+ </filter-mapping>\r
+ \r
<!-- Git Access Restriction Filter\r
<url-pattern> MUST match: \r
* GitServlet\r
<url-pattern>/*</url-pattern>\r
</filter-mapping>\r
\r
-</web-app>\r
+</web-app>
\ No newline at end of file
public final void init(FilterConfig filterConfig) throws ServletException {\r
ServletContext context = filterConfig.getServletContext();\r
ObjectGraph objectGraph = (ObjectGraph) context.getAttribute(DaggerContext.INJECTOR_NAME);\r
- inject(objectGraph);\r
+ inject(objectGraph, filterConfig);\r
}\r
\r
- protected abstract void inject(ObjectGraph dagger);\r
+ protected abstract void inject(ObjectGraph dagger, FilterConfig filterConfig) throws ServletException;\r
\r
@Override\r
public void destroy() {\r
--- /dev/null
+/*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.extensions;
+
+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 ro.fortsoft.pf4j.ExtensionPoint;
+
+/**
+ * Extension point to intercept HTTP requests passing through the server.
+ *
+ * @author David Ostrovsky
+ * @since 1.6.0
+ *
+ */
+public abstract class HttpRequestFilter implements Filter, ExtensionPoint {
+
+ @Override
+ public void init(FilterConfig config) throws ServletException {
+ }
+
+ @Override
+ public void destroy() {
+ }
+
+ @Override
+ public abstract void doFilter(ServletRequest request, ServletResponse response,
+ FilterChain chain) throws IOException, ServletException;
+}
import java.text.MessageFormat;\r
\r
import javax.servlet.FilterChain;\r
+import javax.servlet.FilterConfig;\r
import javax.servlet.ServletException;\r
import javax.servlet.ServletRequest;\r
import javax.servlet.ServletResponse;\r
protected IRepositoryManager repositoryManager;\r
\r
@Override\r
- protected void inject(ObjectGraph dagger) {\r
- super.inject(dagger);\r
+ protected void inject(ObjectGraph dagger, FilterConfig filterConfig) {\r
+ super.inject(dagger, filterConfig);\r
this.runtimeManager = dagger.get(IRuntimeManager.class);\r
this.repositoryManager = dagger.get(IRepositoryManager.class);\r
}\r
import java.util.Map;\r
\r
import javax.servlet.FilterChain;\r
+import javax.servlet.FilterConfig;\r
import javax.servlet.ServletException;\r
import javax.servlet.ServletRequest;\r
import javax.servlet.ServletResponse;\r
protected IAuthenticationManager authenticationManager;\r
\r
@Override\r
- protected void inject(ObjectGraph dagger) {\r
+ protected void inject(ObjectGraph dagger, FilterConfig filterConfig) {\r
this.authenticationManager = dagger.get(IAuthenticationManager.class);\r
}\r
\r
import java.text.MessageFormat;
import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
private IAuthenticationManager authenticationManager;
@Override
- protected void inject(ObjectGraph dagger) {
+ protected void inject(ObjectGraph dagger, FilterConfig filterConfig) {
this.settings = dagger.get(IStoredSettings.class);
this.authenticationManager = dagger.get(IAuthenticationManager.class);
}
\r
import java.text.MessageFormat;\r
\r
+import javax.servlet.FilterConfig;\r
import javax.servlet.http.HttpServletRequest;\r
\r
import com.gitblit.Constants.AccessRestrictionType;\r
private IFederationManager federationManager;\r
\r
@Override\r
- protected void inject(ObjectGraph dagger) {\r
- super.inject(dagger);\r
+ protected void inject(ObjectGraph dagger, FilterConfig filterConfig) {\r
+ super.inject(dagger, filterConfig);\r
this.settings = dagger.get(IStoredSettings.class);\r
this.federationManager = dagger.get(IFederationManager.class);\r
}\r
--- /dev/null
+/*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.servlet;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import com.gitblit.dagger.DaggerFilter;
+import com.gitblit.extensions.HttpRequestFilter;
+import com.gitblit.manager.IPluginManager;
+
+import dagger.ObjectGraph;
+
+/**
+ * A request filter than allows regsitered extension request filters to access
+ * request data. The intended purpose is for server monitoring plugins.
+ *
+ * @author David Ostrovsky
+ * @since 1.6.0
+ */
+public class ProxyFilter extends DaggerFilter {
+ private List<HttpRequestFilter> filters;
+
+ @Override
+ protected void inject(ObjectGraph dagger, FilterConfig filterConfig) throws ServletException {
+ IPluginManager pluginManager = dagger.get(IPluginManager.class);
+ filters = pluginManager.getExtensions(HttpRequestFilter.class);
+ for (HttpRequestFilter f : filters) {
+ f.init(filterConfig);
+ }
+ }
+
+ @Override
+ public void doFilter(ServletRequest req, ServletResponse res, final FilterChain last)
+ throws IOException, ServletException {
+ final Iterator<HttpRequestFilter> itr = filters.iterator();
+ new FilterChain() {
+ @Override
+ public void doFilter(ServletRequest req, ServletResponse res) throws IOException,
+ ServletException {
+ if (itr.hasNext()) {
+ itr.next().doFilter(req, res, this);
+ } else {
+ last.doFilter(req, res);
+ }
+ }
+ }.doFilter(req, res);
+ }
+
+ @Override
+ public void destroy() {
+ for (HttpRequestFilter f : filters) {
+ f.destroy();
+ }
+ }
+}
import java.text.MessageFormat;\r
\r
import javax.servlet.FilterChain;\r
+import javax.servlet.FilterConfig;\r
import javax.servlet.ServletException;\r
import javax.servlet.ServletRequest;\r
import javax.servlet.ServletResponse;\r
private IRuntimeManager runtimeManager;\r
\r
@Override\r
- protected void inject(ObjectGraph dagger) {\r
- super.inject(dagger);\r
+ protected void inject(ObjectGraph dagger, FilterConfig filterConfig) {\r
+ super.inject(dagger, filterConfig);\r
this.settings = dagger.get(IStoredSettings.class);\r
this.runtimeManager = dagger.get(IRuntimeManager.class);\r
}\r
import java.text.MessageFormat;\r
\r
import javax.servlet.FilterChain;\r
+import javax.servlet.FilterConfig;\r
import javax.servlet.ServletException;\r
import javax.servlet.ServletRequest;\r
import javax.servlet.ServletResponse;\r
private IProjectManager projectManager;\r
\r
@Override\r
- protected void inject(ObjectGraph dagger) {\r
- super.inject(dagger);\r
+ protected void inject(ObjectGraph dagger, FilterConfig filterConfig) {\r
+ super.inject(dagger, filterConfig);\r
this.runtimeManager = dagger.get(IRuntimeManager.class);\r
this.repositoryManager = dagger.get(IRepositoryManager.class);\r
this.projectManager = dagger.get(IProjectManager.class);\r
}
```
+### Request Filter
+
+*SINCE 1.6.0*
+
+You can provide your own custom request filter by subclassing the *HttpRequestFilter* class.
+
+```java
+import com.gitblit.extensions.HttpRequestFilter;
+import ro.fortsoft.pf4j.Extension;
+
+@Extension
+public class MyRequestFilter extends HttpRequestFilter {
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response,
+ FilterChain chain) throws IOException, ServletException {
+ }
+}
+```
+