This is a quick return of the servlet3-style code which was reverted mid-December 2013. It is not completely tested, but a casual review was done and it's looks good. The next steps should be to restore `@Inject` annotations, simplify *DaggerModule* boilerplate, and run this on a JEE container with CDI - like JBoss AS 7.
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+
+ <!-- This file is necessary for CDI to work on JEE6 containers -->
+
+</beans>
\ No newline at end of file
-<?xml version="1.0" encoding="UTF-8"?>\r
-<web-app version="2.4"\r
- xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">\r
-\r
- <!-- The base folder is used to specify the root location of your Gitblit data.\r
- \r
- ${baseFolder}/gitblit.properties\r
- ${baseFolder}/users.conf\r
- ${baseFolder}/projects.conf\r
- ${baseFolder}/robots.txt\r
- ${baseFolder}/git\r
- ${baseFolder}/groovy\r
- ${baseFolder}/groovy/grape\r
- ${baseFolder}/proposals\r
-\r
- By default, this location is WEB-INF/data. It is recommended to set this\r
- path to a location outside your webapps folder that is writable by your\r
- servlet container. Gitblit will copy the WEB-INF/data files to that\r
- location for you when it restarts. This approach makes upgrading simpler.\r
- All you have to do is set this parameter for the new release and then\r
- review the defaults for any new settings. Settings are always versioned\r
- with a SINCE x.y.z attribute and also noted in the release changelog.\r
- -->\r
- <env-entry>\r
- <description>The base folder is used to specify the root location of your Gitblit data.</description>\r
- <env-entry-name>baseFolder</env-entry-name>\r
- <env-entry-type>java.lang.String</env-entry-type>\r
- <env-entry-value>${contextFolder}/WEB-INF/data</env-entry-value>\r
- </env-entry>\r
- \r
- <!-- Gitblit Displayname -->\r
- <display-name>Gitblit - @gb.version@</display-name>\r
-\r
- \r
-<!-- Gitblit Context Listener --><!-- STRIP \r
- <listener>\r
- <listener-class>com.gitblit.servlet.GitblitContext</listener-class>\r
- </listener>STRIP --> \r
- \r
- \r
- <!-- Git Servlet\r
- <url-pattern> MUST match: \r
- * GitFilter\r
- * com.gitblit.Constants.GIT_PATH\r
- * Wicket Filter ignorePaths parameter -->\r
- <servlet>\r
- <servlet-name>GitServlet</servlet-name>\r
- <servlet-class>com.gitblit.servlet.GitServlet</servlet-class>\r
- </servlet>\r
- <servlet-mapping>\r
- <servlet-name>GitServlet</servlet-name> \r
- <url-pattern>/git/*</url-pattern>\r
- </servlet-mapping>\r
- <servlet-mapping>\r
- <servlet-name>GitServlet</servlet-name> \r
- <url-pattern>/r/*</url-pattern>\r
- </servlet-mapping>\r
-\r
- \r
- <!-- SparkleShare Invite Servlet\r
- <url-pattern> MUST match: \r
- * com.gitblit.Constants.SPARKLESHARE_INVITE_PATH\r
- * Wicket Filter ignorePaths parameter -->\r
- <servlet>\r
- <servlet-name>SparkleShareInviteServlet</servlet-name>\r
- <servlet-class>com.gitblit.servlet.SparkleShareInviteServlet</servlet-class>\r
- </servlet>\r
- <servlet-mapping>\r
- <servlet-name>SparkleShareInviteServlet</servlet-name> \r
- <url-pattern>/sparkleshare/*</url-pattern>\r
- </servlet-mapping>\r
-\r
- \r
- <!-- Syndication Servlet\r
- <url-pattern> MUST match: \r
- * SyndicationFilter\r
- * com.gitblit.Constants.SYNDICATION_PATH\r
- * Wicket Filter ignorePaths parameter -->\r
- <servlet>\r
- <servlet-name>SyndicationServlet</servlet-name>\r
- <servlet-class>com.gitblit.servlet.SyndicationServlet</servlet-class> \r
- </servlet>\r
- <servlet-mapping>\r
- <servlet-name>SyndicationServlet</servlet-name>\r
- <url-pattern>/feed/*</url-pattern>\r
- </servlet-mapping>\r
- \r
- \r
- <!-- Zip Servlet\r
- <url-pattern> MUST match: \r
- * ZipServlet\r
- * com.gitblit.Constants.ZIP_PATH\r
- * Wicket Filter ignorePaths parameter -->\r
- <servlet>\r
- <servlet-name>ZipServlet</servlet-name>\r
- <servlet-class>com.gitblit.servlet.DownloadZipServlet</servlet-class> \r
- </servlet>\r
- <servlet-mapping>\r
- <servlet-name>ZipServlet</servlet-name>\r
- <url-pattern>/zip/*</url-pattern>\r
- </servlet-mapping>\r
- \r
- \r
- <!-- Federation Servlet\r
- <url-pattern> MUST match: \r
- * com.gitblit.Constants.FEDERATION_PATH \r
- * Wicket Filter ignorePaths parameter -->\r
- <servlet>\r
- <servlet-name>FederationServlet</servlet-name>\r
- <servlet-class>com.gitblit.servlet.FederationServlet</servlet-class> \r
- </servlet>\r
- <servlet-mapping>\r
- <servlet-name>FederationServlet</servlet-name>\r
- <url-pattern>/federation/*</url-pattern>\r
- </servlet-mapping> \r
- \r
- \r
- <!-- Rpc Servlet\r
- <url-pattern> MUST match: \r
- * com.gitblit.Constants.RPC_PATH \r
- * Wicket Filter ignorePaths parameter -->\r
- <servlet>\r
- <servlet-name>RpcServlet</servlet-name>\r
- <servlet-class>com.gitblit.servlet.RpcServlet</servlet-class> \r
- </servlet>\r
- <servlet-mapping>\r
- <servlet-name>RpcServlet</servlet-name>\r
- <url-pattern>/rpc/*</url-pattern>\r
- </servlet-mapping> \r
-\r
-\r
- <!-- Raw Servlet\r
- <url-pattern> MUST match: \r
- * RawFilter\r
- * com.gitblit.Constants.RAW_PATH\r
- * Wicket Filter ignorePaths parameter -->\r
- <servlet>\r
- <servlet-name>RawServlet</servlet-name>\r
- <servlet-class>com.gitblit.servlet.RawServlet</servlet-class>\r
- </servlet>\r
- <servlet-mapping>\r
- <servlet-name>RawServlet</servlet-name> \r
- <url-pattern>/raw/*</url-pattern>\r
- </servlet-mapping> \r
-\r
-\r
- <!-- Pages Servlet\r
- <url-pattern> MUST match: \r
- * PagesFilter\r
- * com.gitblit.Constants.PAGES_PATH\r
- * Wicket Filter ignorePaths parameter -->\r
- <servlet>\r
- <servlet-name>PagesServlet</servlet-name>\r
- <servlet-class>com.gitblit.servlet.PagesServlet</servlet-class>\r
- </servlet>\r
- <servlet-mapping>\r
- <servlet-name>PagesServlet</servlet-name> \r
- <url-pattern>/pages/*</url-pattern>\r
- </servlet-mapping> \r
-\r
- \r
- <!-- Logo Servlet\r
- <url-pattern> MUST match: \r
- * Wicket Filter ignorePaths parameter -->\r
- <servlet>\r
- <servlet-name>LogoServlet</servlet-name>\r
- <servlet-class>com.gitblit.servlet.LogoServlet</servlet-class>\r
- </servlet>\r
- <servlet-mapping>\r
- <servlet-name>LogoServlet</servlet-name> \r
- <url-pattern>/logo.png</url-pattern>\r
- </servlet-mapping>\r
-\r
-\r
- <!-- PT Servlet\r
- <url-pattern> MUST match: \r
- * Wicket Filter ignorePaths parameter -->\r
- <servlet>\r
- <servlet-name>PtServlet</servlet-name>\r
- <servlet-class>com.gitblit.servlet.PtServlet</servlet-class>\r
- </servlet>\r
- <servlet-mapping>\r
- <servlet-name>PtServlet</servlet-name> \r
- <url-pattern>/pt</url-pattern>\r
- </servlet-mapping>\r
-\r
-\r
- <!-- Branch Graph Servlet\r
- <url-pattern> MUST match: \r
- * Wicket Filter ignorePaths parameter -->\r
- <servlet>\r
- <servlet-name>BranchGraphServlet</servlet-name>\r
- <servlet-class>com.gitblit.servlet.BranchGraphServlet</servlet-class>\r
- </servlet>\r
- <servlet-mapping>\r
- <servlet-name>BranchGraphServlet</servlet-name> \r
- <url-pattern>/graph/*</url-pattern>\r
- </servlet-mapping>\r
-\r
- <!-- Robots.txt Servlet\r
- <url-pattern> MUST match: \r
- * Wicket Filter ignorePaths parameter -->\r
- <servlet>\r
- <servlet-name>RobotsTxtServlet</servlet-name>\r
- <servlet-class>com.gitblit.servlet.RobotsTxtServlet</servlet-class>\r
- </servlet>\r
- <servlet-mapping>\r
- <servlet-name>RobotsTxtServlet</servlet-name> \r
- <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
- * com.gitblit.Constants.GIT_PATH\r
- * Wicket Filter ignorePaths parameter -->\r
- <filter>\r
- <filter-name>GitFilter</filter-name>\r
- <filter-class>com.gitblit.servlet.GitFilter</filter-class>\r
- </filter>\r
- <filter-mapping>\r
- <filter-name>GitFilter</filter-name>\r
- <url-pattern>/git/*</url-pattern>\r
- </filter-mapping>\r
- <filter-mapping>\r
- <filter-name>GitFilter</filter-name>\r
- <url-pattern>/r/*</url-pattern>\r
- </filter-mapping>\r
- \r
- \r
- <!-- Syndication Restriction Filter\r
- <url-pattern> MUST match: \r
- * SyndicationServlet\r
- * com.gitblit.Constants.SYNDICATION_PATH\r
- * Wicket Filter ignorePaths parameter -->\r
- <filter>\r
- <filter-name>SyndicationFilter</filter-name>\r
- <filter-class>com.gitblit.servlet.SyndicationFilter</filter-class>\r
- </filter>\r
- <filter-mapping>\r
- <filter-name>SyndicationFilter</filter-name>\r
- <url-pattern>/feed/*</url-pattern>\r
- </filter-mapping>\r
- \r
- \r
- <!-- Download Zip Restriction Filter\r
- <url-pattern> MUST match: \r
- * DownloadZipServlet\r
- * com.gitblit.Constants.ZIP_PATH\r
- * Wicket Filter ignorePaths parameter -->\r
- <filter>\r
- <filter-name>ZipFilter</filter-name>\r
- <filter-class>com.gitblit.servlet.DownloadZipFilter</filter-class>\r
- </filter>\r
- <filter-mapping>\r
- <filter-name>ZipFilter</filter-name>\r
- <url-pattern>/zip/*</url-pattern>\r
- </filter-mapping>\r
-\r
- \r
- <!-- Rpc Restriction Filter\r
- <url-pattern> MUST match: \r
- * RpcServlet\r
- * com.gitblit.Constants.RPC_PATH\r
- * Wicket Filter ignorePaths parameter -->\r
- <filter>\r
- <filter-name>RpcFilter</filter-name>\r
- <filter-class>com.gitblit.servlet.RpcFilter</filter-class>\r
- </filter>\r
- <filter-mapping>\r
- <filter-name>RpcFilter</filter-name>\r
- <url-pattern>/rpc/*</url-pattern>\r
- </filter-mapping>\r
-\r
-\r
- <!-- Branch Restriction Filter\r
- <url-pattern> MUST match: \r
- * RawServlet\r
- * com.gitblit.Constants.BRANCH_PATH\r
- * Wicket Filter ignorePaths parameter -->\r
- <filter>\r
- <filter-name>RawFilter</filter-name>\r
- <filter-class>com.gitblit.servlet.RawFilter</filter-class>\r
- </filter>\r
- <filter-mapping>\r
- <filter-name>RawFilter</filter-name>\r
- <url-pattern>/raw/*</url-pattern>\r
- </filter-mapping>\r
- \r
-\r
- <!-- Pages Restriction Filter\r
- <url-pattern> MUST match: \r
- * PagesServlet\r
- * com.gitblit.Constants.PAGES_PATH\r
- * Wicket Filter ignorePaths parameter -->\r
- <filter>\r
- <filter-name>PagesFilter</filter-name>\r
- <filter-class>com.gitblit.servlet.PagesFilter</filter-class>\r
- </filter>\r
- <filter-mapping>\r
- <filter-name>PagesFilter</filter-name>\r
- <url-pattern>/pages/*</url-pattern>\r
- </filter-mapping>\r
- \r
- <filter>\r
- <filter-name>EnforceAuthenticationFilter</filter-name>\r
- <filter-class>com.gitblit.servlet.EnforceAuthenticationFilter</filter-class>\r
- </filter>\r
- <filter-mapping>\r
- <filter-name>EnforceAuthenticationFilter</filter-name>\r
- <url-pattern>/*</url-pattern>\r
- </filter-mapping>\r
-\r
-\r
- <!-- Wicket Filter -->\r
- <filter>\r
- <filter-name>wicketFilter</filter-name>\r
- <filter-class>\r
- com.gitblit.wicket.GitblitWicketFilter\r
- </filter-class> \r
- <init-param>\r
- <param-name>ignorePaths</param-name>\r
- <!-- Paths should match \r
- * SyndicationFilter <url-pattern>\r
- * SyndicationServlet <url-pattern>\r
- * com.gitblit.Constants.SYNDICATION_PATH\r
- * GitFilter <url-pattern>\r
- * GitServlet <url-pattern>\r
- * com.gitblit.Constants.GIT_PATH\r
- * SparkleshareInviteServlet <url-pattern>\r
- * com.gitblit.Constants.SPARKLESHARE_INVITE_PATH\r
- * Zipfilter <url-pattern>\r
- * ZipServlet <url-pattern>\r
- * com.gitblit.Constants.ZIP_PATH\r
- * FederationServlet <url-pattern>\r
- * RpcFilter <url-pattern>\r
- * RpcServlet <url-pattern>\r
- * RawFilter <url-pattern>\r
- * RawServlet <url-pattern>\r
- * PagesFilter <url-pattern>\r
- * PagesServlet <url-pattern>\r
- * com.gitblit.Constants.PAGES_PATH -->\r
- <param-value>r/,git/,pt,feed/,zip/,federation/,rpc/,raw/,pages/,robots.txt,logo.png,graph/,sparkleshare/</param-value>\r
- </init-param>\r
- </filter>\r
- <filter-mapping>\r
- <filter-name>wicketFilter</filter-name>\r
- <url-pattern>/*</url-pattern>\r
- </filter-mapping>\r
- \r
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="3.0"
+ xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_3_0.xsd">
+
+ <!-- The base folder is used to specify the root location of your Gitblit data.
+
+ ${baseFolder}/gitblit.properties
+ ${baseFolder}/users.conf
+ ${baseFolder}/projects.conf
+ ${baseFolder}/robots.txt
+ ${baseFolder}/git
+ ${baseFolder}/groovy
+ ${baseFolder}/groovy/grape
+ ${baseFolder}/proposals
+
+ By default, this location is WEB-INF/data. It is recommended to set this
+ path to a location outside your webapps folder that is writable by your
+ servlet container. Gitblit will copy the WEB-INF/data files to that
+ location for you when it restarts. This approach makes upgrading simpler.
+ All you have to do is set this parameter for the new release and then
+ review the defaults for any new settings. Settings are always versioned
+ with a SINCE x.y.z attribute and also noted in the release changelog.
+ -->
+ <env-entry>
+ <description>The base folder is used to specify the root location of your Gitblit data.</description>
+ <env-entry-name>baseFolder</env-entry-name>
+ <env-entry-type>java.lang.String</env-entry-type>
+ <env-entry-value>${contextFolder}/WEB-INF/data</env-entry-value>
+ </env-entry>
+
+ <!-- Gitblit Displayname -->
+ <display-name>Gitblit - @gb.version@</display-name>
+
</web-app>
\ No newline at end of file
\r
public static final String RAW_PATH = "/raw/";\r
\r
+ public static final String PT_PATH = "/pt";\r
+\r
public static final String BRANCH_GRAPH_PATH = "/graph/";\r
\r
public static final String BORDER = "*****************************************************************";\r
import com.gitblit.manager.RepositoryManager;
import com.gitblit.manager.RuntimeManager;
import com.gitblit.manager.UserManager;
+import com.gitblit.servlet.BranchGraphServlet;
+import com.gitblit.servlet.DownloadZipFilter;
+import com.gitblit.servlet.DownloadZipServlet;
+import com.gitblit.servlet.EnforceAuthenticationFilter;
+import com.gitblit.servlet.FederationServlet;
+import com.gitblit.servlet.GitFilter;
+import com.gitblit.servlet.GitServlet;
+import com.gitblit.servlet.LogoServlet;
+import com.gitblit.servlet.PagesFilter;
+import com.gitblit.servlet.PagesServlet;
+import com.gitblit.servlet.ProxyFilter;
+import com.gitblit.servlet.PtServlet;
+import com.gitblit.servlet.RawFilter;
+import com.gitblit.servlet.RawServlet;
+import com.gitblit.servlet.RobotsTxtServlet;
+import com.gitblit.servlet.RpcFilter;
+import com.gitblit.servlet.RpcServlet;
+import com.gitblit.servlet.SparkleShareInviteServlet;
+import com.gitblit.servlet.SyndicationFilter;
+import com.gitblit.servlet.SyndicationServlet;
import com.gitblit.transport.ssh.FileKeyManager;
import com.gitblit.transport.ssh.IPublicKeyManager;
import com.gitblit.transport.ssh.MemoryKeyManager;
import com.gitblit.transport.ssh.NullKeyManager;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.GitBlitWebApp;
+import com.gitblit.wicket.GitblitWicketFilter;
import dagger.Module;
import dagger.Provides;
IGitblit.class,
// the Gitblit Wicket app
- GitBlitWebApp.class
+ GitBlitWebApp.class,
+
+ // filters & servlets
+ GitServlet.class,
+ GitFilter.class,
+ RawServlet.class,
+ RawFilter.class,
+ PagesServlet.class,
+ PagesFilter.class,
+ RpcServlet.class,
+ RpcFilter.class,
+ DownloadZipServlet.class,
+ DownloadZipFilter.class,
+ SyndicationServlet.class,
+ SyndicationFilter.class,
+ FederationServlet.class,
+ SparkleShareInviteServlet.class,
+ BranchGraphServlet.class,
+ RobotsTxtServlet.class,
+ LogoServlet.class,
+ PtServlet.class,
+ ProxyFilter.class,
+ EnforceAuthenticationFilter.class,
+ GitblitWicketFilter.class
}
)
public class DaggerModule {
federationManager,
gitblit);
}
+//
+// @Provides @Singleton GitblitWicketFilter provideGitblitWicketFilter(GitBlitWebApp webapp) {
+// return new GitblitWicketFilter(webapp);
+// }
+//
+// @Provides GitServlet provideGitServlet(IGitblit gitblit) {
+// return new GitServlet(gitblit);
+// }
+//
+// @Provides GitFilter provideGitFilter(
+// IRuntimeManager runtimeManager,
+// IUserManager userManager,
+// IAuthenticationManager authenticationManager,
+// IRepositoryManager repositoryManager,
+// IFederationManager federationManager) {
+//
+// return new GitFilter(
+// runtimeManager,
+// userManager,
+// authenticationManager,
+// repositoryManager,
+// federationManager);
+// }
+//
+// @Provides @Singleton PagesServlet providePagesServlet(
+// IRuntimeManager runtimeManager,
+// IRepositoryManager repositoryManager) {
+//
+// return new PagesServlet(runtimeManager, repositoryManager);
+// }
+//
+// @Provides @Singleton PagesFilter providePagesFilter(
+// IRuntimeManager runtimeManager,
+// IAuthenticationManager authenticationManager,
+// IRepositoryManager repositoryManager) {
+//
+// return new PagesFilter(
+// runtimeManager,
+// authenticationManager,
+// repositoryManager);
+// }
+//
+// @Provides @Singleton RpcServlet provideRpcServlet(IGitblit gitblit) {
+// return new RpcServlet(gitblit);
+// }
+//
+// @Provides @Singleton RpcFilter provideRpcFilter(
+// IRuntimeManager runtimeManager,
+// IAuthenticationManager authenticationManager) {
+//
+// return new RpcFilter(runtimeManager, authenticationManager);
+// }
+//
+// @Provides @Singleton DownloadZipServlet provideDownloadZipServlet(
+// IRuntimeManager runtimeManager,
+// IRepositoryManager repositoryManager) {
+//
+// return new DownloadZipServlet(runtimeManager, repositoryManager);
+// }
+//
+// @Provides @Singleton DownloadZipFilter provideDownloadZipFilter(
+// IRuntimeManager runtimeManager,
+// IAuthenticationManager authenticationManager,
+// IRepositoryManager repositoryManager) {
+//
+// return new DownloadZipFilter(
+// runtimeManager,
+// authenticationManager,
+// repositoryManager);
+// }
+//
+// @Provides @Singleton SyndicationServlet provideSyndicationServlet(
+// IRuntimeManager runtimeManager,
+// IRepositoryManager repositoryManager,
+// IProjectManager projectManager) {
+//
+// return new SyndicationServlet(
+// runtimeManager,
+// repositoryManager,
+// projectManager);
+// }
+//
+// @Provides @Singleton SyndicationFilter provideSyndicationFilter(
+// IRuntimeManager runtimeManager,
+// IAuthenticationManager authenticationManager,
+// IRepositoryManager repositoryManager,
+// IProjectManager projectManager) {
+//
+// return new SyndicationFilter(
+// runtimeManager,
+// authenticationManager,
+// repositoryManager,
+// projectManager);
+// }
+//
+// @Provides @Singleton FederationServlet provideFederationServlet(
+// IRuntimeManager runtimeManager,
+// IUserManager userManager,
+// IRepositoryManager repositoryManager,
+// IFederationManager federationManager) {
+//
+// return new FederationServlet(
+// runtimeManager,
+// userManager,
+// repositoryManager,
+// federationManager);
+// }
+//
+// @Provides @Singleton SparkleShareInviteServlet provideSparkleshareInviteServlet(
+// IRuntimeManager runtimeManager,
+// IUserManager userManager,
+// IAuthenticationManager authenticationManager,
+// IRepositoryManager repositoryManager) {
+//
+// return new SparkleShareInviteServlet(
+// runtimeManager,
+// userManager,
+// authenticationManager,
+// repositoryManager);
+// }
+//
+// @Provides @Singleton BranchGraphServlet provideBranchGraphServlet(
+// IRuntimeManager runtimeManager,
+// IRepositoryManager repositoryManager) {
+//
+// return new BranchGraphServlet(runtimeManager, repositoryManager);
+// }
+//
+// @Provides @Singleton RobotsTxtServlet provideRobotsTxtServlet(IRuntimeManager runtimeManager) {
+// return new RobotsTxtServlet(runtimeManager);
+// }
+//
+// @Provides @Singleton LogoServlet provideLogoServlet(IRuntimeManager runtimeManager) {
+// return new LogoServlet(runtimeManager);
+// }
+//
+// @Provides @Singleton EnforceAuthenticationFilter provideEnforceAuthenticationFilter(
+// IRuntimeManager runtimeManager,
+// IAuthenticationManager authenticationManager) {
+//
+// return new EnforceAuthenticationFilter(runtimeManager, authenticationManager);
+// }
+
+
+ @Provides @Singleton GitblitWicketFilter provideGitblitWicketFilter(GitBlitWebApp webapp) {
+ return new GitblitWicketFilter();
+ }
+
+ @Provides GitServlet provideGitServlet(IGitblit gitblit) {
+ return new GitServlet();
+ }
+
+ @Provides GitFilter provideGitFilter(
+ IRuntimeManager runtimeManager,
+ IUserManager userManager,
+ IAuthenticationManager authenticationManager,
+ IRepositoryManager repositoryManager,
+ IFederationManager federationManager) {
+
+ return new GitFilter();
+ }
+
+ @Provides @Singleton RawServlet provideRawServlet(
+ IRuntimeManager runtimeManager,
+ IRepositoryManager repositoryManager) {
+
+ return new RawServlet();
+ }
+
+ @Provides @Singleton RawFilter provideRawFilter(
+ IRuntimeManager runtimeManager,
+ IAuthenticationManager authenticationManager,
+ IRepositoryManager repositoryManager) {
+
+ return new RawFilter();
+ }
+
+ @Provides @Singleton PagesServlet providePagesServlet(
+ IRuntimeManager runtimeManager,
+ IRepositoryManager repositoryManager) {
+
+ return new PagesServlet();
+ }
+
+ @Provides @Singleton PagesFilter providePagesFilter(
+ IRuntimeManager runtimeManager,
+ IAuthenticationManager authenticationManager,
+ IRepositoryManager repositoryManager) {
+
+ return new PagesFilter();
+ }
+
+ @Provides @Singleton RpcServlet provideRpcServlet(IGitblit gitblit) {
+ return new RpcServlet();
+ }
+
+ @Provides @Singleton RpcFilter provideRpcFilter(
+ IRuntimeManager runtimeManager,
+ IAuthenticationManager authenticationManager) {
+
+ return new RpcFilter();
+ }
+
+ @Provides @Singleton DownloadZipServlet provideDownloadZipServlet(
+ IRuntimeManager runtimeManager,
+ IRepositoryManager repositoryManager) {
+
+ return new DownloadZipServlet();
+ }
+
+ @Provides @Singleton DownloadZipFilter provideDownloadZipFilter(
+ IRuntimeManager runtimeManager,
+ IAuthenticationManager authenticationManager,
+ IRepositoryManager repositoryManager) {
+
+ return new DownloadZipFilter();
+ }
+
+ @Provides @Singleton SyndicationServlet provideSyndicationServlet(
+ IRuntimeManager runtimeManager,
+ IRepositoryManager repositoryManager,
+ IProjectManager projectManager) {
+
+ return new SyndicationServlet();
+ }
+
+ @Provides @Singleton SyndicationFilter provideSyndicationFilter(
+ IRuntimeManager runtimeManager,
+ IAuthenticationManager authenticationManager,
+ IRepositoryManager repositoryManager,
+ IProjectManager projectManager) {
+
+ return new SyndicationFilter();
+ }
+
+ @Provides @Singleton FederationServlet provideFederationServlet(
+ IRuntimeManager runtimeManager,
+ IUserManager userManager,
+ IRepositoryManager repositoryManager,
+ IFederationManager federationManager) {
+
+ return new FederationServlet();
+ }
+
+ @Provides @Singleton SparkleShareInviteServlet provideSparkleshareInviteServlet(
+ IRuntimeManager runtimeManager,
+ IUserManager userManager,
+ IAuthenticationManager authenticationManager,
+ IRepositoryManager repositoryManager) {
+
+ return new SparkleShareInviteServlet();
+ }
+
+ @Provides @Singleton BranchGraphServlet provideBranchGraphServlet(
+ IRuntimeManager runtimeManager,
+ IRepositoryManager repositoryManager) {
+
+ return new BranchGraphServlet();
+ }
+
+ @Provides @Singleton RobotsTxtServlet provideRobotsTxtServlet(IRuntimeManager runtimeManager) {
+ return new RobotsTxtServlet();
+ }
+
+ @Provides @Singleton LogoServlet provideLogoServlet(IRuntimeManager runtimeManager) {
+ return new LogoServlet();
+ }
+
+ @Provides @Singleton PtServlet providePtServlet(IRuntimeManager runtimeManager) {
+ return new PtServlet();
+ }
+
+ @Provides @Singleton ProxyFilter provideProxyFilter(
+ IRuntimeManager runtimeManager,
+ IAuthenticationManager authenticationManager) {
+
+ return new ProxyFilter();
+ }
+
+ @Provides @Singleton EnforceAuthenticationFilter provideEnforceAuthenticationFilter(
+ IRuntimeManager runtimeManager,
+ IAuthenticationManager authenticationManager) {
+
+ return new EnforceAuthenticationFilter();
+ }
}
\ No newline at end of file
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.gitblit.servlet.InjectionContextListener;
+
import dagger.ObjectGraph;
/**
* @author James Moger
*
*/
-public abstract class DaggerContext implements ServletContextListener {
+public abstract class DaggerContext extends InjectionContextListener {
public static final String INJECTOR_NAME = ObjectGraph.class.getName();
return (ObjectGraph) o;
}
+ /**
+ * Instantiates an object.
+ *
+ * @param clazz
+ * @return the object
+ */
+ @Override
+ protected <X> X instantiate(ServletContext context, Class<X> clazz) {
+ try {
+ ObjectGraph injector = getInjector(context);
+ return injector.get(clazz);
+ } catch (Throwable t) {
+ logger.error(null, t);
+ }
+ return null;
+ }
+
@Override
public final void contextDestroyed(ServletContextEvent contextEvent) {
ServletContext context = contextEvent.getServletContext();
import java.io.OutputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
+import javax.servlet.annotation.WebListener;
import com.gitblit.Constants;
import com.gitblit.DaggerModule;
import com.gitblit.transport.ssh.IPublicKeyManager;
import com.gitblit.utils.ContainerUtils;
import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.GitblitWicketFilter;
import dagger.ObjectGraph;
/**
* This class is the main entry point for the entire webapp. It is a singleton
* created manually by Gitblit GO or dynamically by the WAR/Express servlet
- * container. This class instantiates and starts all managers. Servlets and
- * filters are instantiated defined in web.xml and instantiated by the servlet
- * container, but those servlets and filters use Dagger to manually inject their
- * dependencies.
+ * container. This class instantiates and starts all managers.
+ *
+ * Servlets and filters are injected which allows Gitblit to be completely
+ * code-driven.
*
* @author James Moger
*
*/
+@WebListener
public class GitblitContext extends DaggerContext {
private static GitblitContext gitblit;
return new Object [] { new DaggerModule() };
}
- /**
- * Configure Gitblit from the web.xml, if no configuration has already been
- * specified.
- *
- * @see ServletContextListener.contextInitialize(ServletContextEvent)
- */
- @Override
- public final void contextInitialized(ServletContextEvent contextEvent) {
- ServletContext context = contextEvent.getServletContext();
- configureContext(context);
- }
-
/**
* Prepare runtime settings and start all manager instances.
*/
- protected void configureContext(ServletContext context) {
+ @Override
+ protected void beforeServletInjection(ServletContext context) {
ObjectGraph injector = getInjector(context);
// create the runtime settings object
logger.info("----[{}]----", clazz.getName());
}
+ /**
+ * Instantiate and inject all filters and servlets into the container using
+ * the servlet 3 specification.
+ */
+ @Override
+ protected void injectServlets(ServletContext context) {
+ // access restricted servlets
+ serve(context, Constants.R_PATH, GitServlet.class, GitFilter.class);
+ serve(context, Constants.GIT_PATH, GitServlet.class, GitFilter.class);
+ serve(context, Constants.RAW_PATH, RawServlet.class, RawFilter.class);
+ serve(context, Constants.PAGES, PagesServlet.class, PagesFilter.class);
+ serve(context, Constants.RPC_PATH, RpcServlet.class, RpcFilter.class);
+ serve(context, Constants.ZIP_PATH, DownloadZipServlet.class, DownloadZipFilter.class);
+ serve(context, Constants.SYNDICATION_PATH, SyndicationServlet.class, SyndicationFilter.class);
+
+ // servlets
+ serve(context, Constants.FEDERATION_PATH, FederationServlet.class);
+ serve(context, Constants.SPARKLESHARE_INVITE_PATH, SparkleShareInviteServlet.class);
+ serve(context, Constants.BRANCH_GRAPH_PATH, BranchGraphServlet.class);
+ serve(context, Constants.PT_PATH, PtServlet.class);
+ file(context, "/robots.txt", RobotsTxtServlet.class);
+ file(context, "/logo.png", LogoServlet.class);
+
+ // global filters
+ filter(context, "/*", ProxyFilter.class, null);
+ filter(context, "/*", EnforceAuthenticationFilter.class, null);
+
+ // Wicket
+ String toIgnore = StringUtils.flattenStrings(getRegisteredPaths(), ",");
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(GitblitWicketFilter.FILTER_MAPPING_PARAM, "/*");
+ params.put(GitblitWicketFilter.IGNORE_PATHS_PARAM, toIgnore);
+ filter(context, "/*", GitblitWicketFilter.class, params);
+ }
+
/**
* Gitblit is being shutdown either because the servlet container is
* shutting down or because the servlet container is re-deploying Gitblit.
--- /dev/null
+/*\r
+ * Copyright 2014 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.servlet;\r
+\r
+import java.util.ArrayList;\r
+import java.util.EnumSet;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.servlet.DispatcherType;\r
+import javax.servlet.Filter;\r
+import javax.servlet.FilterRegistration;\r
+import javax.servlet.Servlet;\r
+import javax.servlet.ServletContext;\r
+import javax.servlet.ServletContextEvent;\r
+import javax.servlet.ServletContextListener;\r
+import javax.servlet.ServletRegistration;\r
+\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+/**\r
+ * Injection context listener instantiates and injects servlets, filters, and\r
+ * anything else you might want into a servlet context. This class provides\r
+ * convenience methods for servlet & filter registration and also tracks\r
+ * registered paths.\r
+ *\r
+ * @author James Moger\r
+ *\r
+ */\r
+public abstract class InjectionContextListener implements ServletContextListener {\r
+\r
+ protected final Logger logger = LoggerFactory.getLogger(getClass());\r
+\r
+ private final List<String> registeredPaths = new ArrayList<String>();\r
+\r
+ protected final List<String> getRegisteredPaths() {\r
+ return registeredPaths;\r
+ }\r
+\r
+ /**\r
+ * Hook for subclasses to manipulate context initialization before\r
+ * standard initialization procedure.\r
+ *\r
+ * @param context\r
+ */\r
+ protected void beforeServletInjection(ServletContext context) {\r
+ // NOOP\r
+ }\r
+\r
+ /**\r
+ * Hook for subclasses to instantiate and inject servlets and filters\r
+ * into the servlet context.\r
+ *\r
+ * @param context\r
+ */\r
+ protected abstract void injectServlets(ServletContext context);\r
+\r
+ /**\r
+ * Hook for subclasses to manipulate context initialization after\r
+ * servlet registration.\r
+ *\r
+ * @param context\r
+ */\r
+ protected void afterServletInjection(ServletContext context) {\r
+ // NOOP\r
+ }\r
+\r
+ /**\r
+ * Configure Gitblit from the web.xml, if no configuration has already been\r
+ * specified.\r
+ *\r
+ * @see ServletContextListener.contextInitialize(ServletContextEvent)\r
+ */\r
+ @Override\r
+ public final void contextInitialized(ServletContextEvent contextEvent) {\r
+ ServletContext context = contextEvent.getServletContext();\r
+ beforeServletInjection(context);\r
+ injectServlets(context);\r
+ afterServletInjection(context);\r
+ }\r
+\r
+\r
+ /**\r
+ * Registers a file path.\r
+ *\r
+ * @param context\r
+ * @param file\r
+ * @param servletClass\r
+ */\r
+ protected void file(ServletContext context, String file, Class<? extends Servlet> servletClass) {\r
+ file(context, file, servletClass, null);\r
+ }\r
+\r
+ /**\r
+ * Registers a file path with init parameters.\r
+ *\r
+ * @param context\r
+ * @param file\r
+ * @param servletClass\r
+ * @param initParams\r
+ */\r
+ protected void file(ServletContext context, String file, Class<? extends Servlet> servletClass, Map<String, String> initParams) {\r
+ Servlet servlet = instantiate(context, servletClass);\r
+ ServletRegistration.Dynamic d = context.addServlet(sanitize(servletClass.getSimpleName() + file), servlet);\r
+ d.addMapping(file);\r
+ if (initParams != null) {\r
+ d.setInitParameters(initParams);\r
+ }\r
+ registeredPaths.add(file);\r
+ }\r
+\r
+ /**\r
+ * Serves a path (trailing wildcard will be appended).\r
+ *\r
+ * @param context\r
+ * @param route\r
+ * @param servletClass\r
+ */\r
+ protected void serve(ServletContext context, String route, Class<? extends Servlet> servletClass) {\r
+ serve(context, route, servletClass, (Class<Filter>) null);\r
+ }\r
+\r
+ /**\r
+ * Serves a path (trailing wildcard will be appended) with init parameters.\r
+ *\r
+ * @param context\r
+ * @param route\r
+ * @param servletClass\r
+ * @param initParams\r
+ */\r
+ protected void serve(ServletContext context, String route, Class<? extends Servlet> servletClass, Map<String, String> initParams) {\r
+ Servlet servlet = instantiate(context, servletClass);\r
+ ServletRegistration.Dynamic d = context.addServlet(sanitize(servletClass.getSimpleName() + route), servlet);\r
+ d.addMapping(route + "*");\r
+ if (initParams != null) {\r
+ d.setInitParameters(initParams);\r
+ }\r
+ registeredPaths.add(route);\r
+ }\r
+\r
+ /**\r
+ * Serves a path (trailing wildcard will be appended) and also maps a filter\r
+ * to that path.\r
+ *\r
+ * @param context\r
+ * @param route\r
+ * @param servletClass\r
+ * @param filterClass\r
+ */\r
+ protected void serve(ServletContext context, String route, Class<? extends Servlet> servletClass, Class<? extends Filter> filterClass) {\r
+ Servlet servlet = instantiate(context, servletClass);\r
+ ServletRegistration.Dynamic d = context.addServlet(sanitize(servletClass.getSimpleName() + route), servlet);\r
+ d.addMapping(route + "*");\r
+ if (filterClass != null) {\r
+ filter(context, route + "*", filterClass);\r
+ }\r
+ registeredPaths.add(route);\r
+ }\r
+\r
+ /**\r
+ * Registers a path filter.\r
+ *\r
+ * @param context\r
+ * @param route\r
+ * @param filterClass\r
+ */\r
+ protected void filter(ServletContext context, String route, Class<? extends Filter> filterClass) {\r
+ filter(context, route, filterClass, null);\r
+ }\r
+\r
+ /**\r
+ * Registers a path filter with init parameters.\r
+ *\r
+ * @param context\r
+ * @param route\r
+ * @param filterClass\r
+ * @param initParams\r
+ */\r
+ protected void filter(ServletContext context, String route, Class<? extends Filter> filterClass, Map<String, String> initParams) {\r
+ Filter filter = instantiate(context, filterClass);\r
+ FilterRegistration.Dynamic d = context.addFilter(sanitize(filterClass.getSimpleName() + route), filter);\r
+ d.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, route);\r
+ if (initParams != null) {\r
+ d.setInitParameters(initParams);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Limit the generated servlet/filter names to alpha-numeric values with a\r
+ * handful of acceptable other characters.\r
+ *\r
+ * @param name\r
+ * @return a sanitized name\r
+ */\r
+ protected String sanitize(String name) {\r
+ StringBuilder sb = new StringBuilder();\r
+ for (char c : name.toCharArray()) {\r
+ if (Character.isLetterOrDigit(c)) {\r
+ sb.append(c);\r
+ } else if ('-' == c) {\r
+ sb.append(c);\r
+ } else if ('*' == c) {\r
+ sb.append("all");\r
+ } else if ('.' == c) {\r
+ sb.append('.');\r
+ } else {\r
+ sb.append('_');\r
+ }\r
+ }\r
+ return sb.toString();\r
+ }\r
+\r
+ /**\r
+ * Instantiates an object.\r
+ *\r
+ * @param clazz\r
+ * @return the object\r
+ */\r
+ protected <X> X instantiate(ServletContext context, Class<X> clazz) {\r
+ try {\r
+ return clazz.newInstance();\r
+ } catch (Throwable t) {\r
+ logger.error(null, t);\r
+ }\r
+ return null;\r
+ }\r
+}\r