@@ -5,10 +5,11 @@ | |||
<classpathentry kind="src" path="src/test/java" output="bin/test-classes" /> | |||
<classpathentry kind="src" path="src/test/bugtraq" output="bin/test-classes" /> | |||
<classpathentry kind="src" path="src/main/resources" /> | |||
<classpathentry kind="lib" path="ext/dagger-1.1.0.jar" sourcepath="ext/src/dagger-1.1.0.jar" /> | |||
<classpathentry kind="lib" path="ext/guice-4.0-beta4.jar" sourcepath="ext/src/guice-4.0-beta4.jar" /> | |||
<classpathentry kind="lib" path="ext/javax.inject-1.jar" sourcepath="ext/src/javax.inject-1.jar" /> | |||
<classpathentry kind="lib" path="ext/dagger-compiler-1.1.0.jar" sourcepath="ext/src/dagger-compiler-1.1.0.jar" /> | |||
<classpathentry kind="lib" path="ext/javawriter-2.1.1.jar" sourcepath="ext/src/javawriter-2.1.1.jar" /> | |||
<classpathentry kind="lib" path="ext/aopalliance-1.0.jar" sourcepath="ext/src/aopalliance-1.0.jar" /> | |||
<classpathentry kind="lib" path="ext/guava-17.0.jar" sourcepath="ext/src/guava-17.0.jar" /> | |||
<classpathentry kind="lib" path="ext/guice-servlet-4.0-gb1.jar" sourcepath="ext/src/guice-servlet-4.0-gb1.jar" /> | |||
<classpathentry kind="lib" path="ext/annotations-12.0.jar" sourcepath="ext/src/annotations-12.0.jar" /> | |||
<classpathentry kind="lib" path="ext/log4j-1.2.17.jar" sourcepath="ext/src/log4j-1.2.17.jar" /> | |||
<classpathentry kind="lib" path="ext/slf4j-api-1.7.7.jar" sourcepath="ext/src/slf4j-api-1.7.7.jar" /> | |||
@@ -70,7 +71,6 @@ | |||
<classpathentry kind="lib" path="ext/waffle-jna-1.5.jar" sourcepath="ext/src/waffle-jna-1.5.jar" /> | |||
<classpathentry kind="lib" path="ext/platform-3.5.0.jar" sourcepath="ext/src/platform-3.5.0.jar" /> | |||
<classpathentry kind="lib" path="ext/jna-3.5.0.jar" sourcepath="ext/src/jna-3.5.0.jar" /> | |||
<classpathentry kind="lib" path="ext/guava-13.0.1.jar" sourcepath="ext/src/guava-13.0.1.jar" /> | |||
<classpathentry kind="lib" path="ext/libpam4j-1.7.jar" sourcepath="ext/src/libpam4j-1.7.jar" /> | |||
<classpathentry kind="lib" path="ext/args4j-2.0.26.jar" sourcepath="ext/src/args4j-2.0.26.jar" /> | |||
<classpathentry kind="lib" path="ext/jedis-2.3.1.jar" sourcepath="ext/src/jedis-2.3.1.jar" /> |
@@ -358,3 +358,12 @@ pf4j | |||
Apache License 2.0 | |||
https://github.com/decebals/pf4j | |||
--------------------------------------------------------------------------- | |||
google-guice | |||
--------------------------------------------------------------------------- | |||
google-guice, release under the | |||
Apache License 2.0 | |||
https://code.google.com/p/google-guice | |||
@@ -96,9 +96,10 @@ registeredRepositories: | |||
- { id: eclipse, url: 'http://repo.eclipse.org/content/groups/releases' } | |||
- { id: eclipse-snapshots, url: 'http://repo.eclipse.org/content/groups/snapshots' } | |||
- { id: atlassian-contrib, url: 'https://maven.atlassian.com/content/repositories/atlassian-3rdparty' } | |||
- { id: gitblit, url: 'http://gitblit.github.io/gitblit-maven' } | |||
# Source all dependencies from the following repositories in the specified order | |||
repositories: central, eclipse-snapshots, eclipse, atlassian-contrib | |||
repositories: central, eclipse-snapshots, eclipse, atlassian-contrib, gitblit | |||
# Convenience properties for dependencies | |||
properties: { | |||
@@ -112,6 +113,9 @@ properties: { | |||
wikitext.version : 1.4 | |||
sshd.version: 0.11.1-atlassian-1 | |||
mina.version: 2.0.7 | |||
guice.version : 4.0-beta4 | |||
# Gitblit maintains a fork of guice-servlet | |||
guice-servlet.version : 4.0-gb1 | |||
} | |||
# Dependencies | |||
@@ -126,15 +130,14 @@ properties: { | |||
# | |||
dependencies: | |||
# Dagger dependency injection library (annotation processor) | |||
- compile 'com.squareup.dagger:dagger:1.1.0' :war apt | |||
- compile 'com.squareup.dagger:dagger-compiler:1.1.0' :war optional apt | |||
# Standard dependencies | |||
- compile 'com.google.inject:guice:${guice.version}' :war :fedclient | |||
- compile 'com.google.inject.extensions:guice-servlet:${guice-servlet.version}' :war | |||
- compile 'com.google.guava:guava:17.0' :war :fedclient | |||
- compile 'com.intellij:annotations:12.0' :war | |||
- compile 'log4j:log4j:1.2.17' :war :fedclient :authority | |||
- compile 'org.slf4j:slf4j-api:1.7.7' :war :fedclient :authority | |||
- compile 'org.slf4j:slf4j-log4j12:1.7.7' :war :fedclient :authority | |||
- compile 'com.sun.mail:javax.mail:1.5.1' :war :authority | |||
- compile 'log4j:log4j:1.2.17' :war :fedclient | |||
- compile 'org.slf4j:slf4j-api:1.7.7' :war :fedclient | |||
- compile 'org.slf4j:slf4j-log4j12:1.7.7' :war :fedclient | |||
- compile 'com.sun.mail:javax.mail:1.5.1' :war | |||
- compile 'javax.servlet:javax.servlet-api:3.1.0' :fedclient | |||
- compile 'org.eclipse.jetty.aggregate:jetty-all:${jetty.version}' @jar | |||
- compile 'org.apache.wicket:wicket:${wicket.version}' :war !org.mockito | |||
@@ -152,11 +155,11 @@ dependencies: | |||
- compile 'org.fusesource.wikitext:tracwiki-core:${wikitext.version}' :war | |||
- compile 'org.fusesource.wikitext:mediawiki-core:${wikitext.version}' :war | |||
- compile 'org.fusesource.wikitext:confluence-core:${wikitext.version}' :war | |||
- compile 'org.eclipse.jgit:org.eclipse.jgit:${jgit.version}' :war :fedclient :manager :authority !junit | |||
- compile 'org.eclipse.jgit:org.eclipse.jgit.http.server:${jgit.version}' :war :manager :authority !junit | |||
- compile 'org.bouncycastle:bcprov-jdk15on:${bouncycastle.version}' :war :authority | |||
- compile 'org.bouncycastle:bcmail-jdk15on:${bouncycastle.version}' :war :authority | |||
- compile 'org.bouncycastle:bcpkix-jdk15on:${bouncycastle.version}' :war :authority | |||
- compile 'org.eclipse.jgit:org.eclipse.jgit:${jgit.version}' :war :fedclient :manager !junit | |||
- compile 'org.eclipse.jgit:org.eclipse.jgit.http.server:${jgit.version}' :war :manager !junit | |||
- compile 'org.bouncycastle:bcprov-jdk15on:${bouncycastle.version}' :war | |||
- compile 'org.bouncycastle:bcmail-jdk15on:${bouncycastle.version}' :war | |||
- compile 'org.bouncycastle:bcpkix-jdk15on:${bouncycastle.version}' :war | |||
- compile 'org.apache.sshd:sshd-core:${sshd.version}' :war !org.easymock | |||
- compile 'org.apache.mina:mina-core:${mina.version}' :war !org.easymock | |||
- compile 'rome:rome:0.9' :war :manager :api | |||
@@ -171,7 +174,7 @@ dependencies: | |||
- compile 'org.freemarker:freemarker:2.3.20' :war | |||
- compile 'com.github.dblock.waffle:waffle-jna:1.5' :war | |||
- compile 'org.kohsuke:libpam4j:1.7' :war | |||
- compile 'args4j:args4j:2.0.26' :war :fedclient :authority | |||
- compile 'args4j:args4j:2.0.26' :war :fedclient | |||
- compile 'commons-codec:commons-codec:1.7' :war | |||
- compile 'redis.clients:jedis:2.3.1' :war | |||
- compile 'ro.fortsoft.pf4j:pf4j:0.8.0' :war |
@@ -295,7 +295,7 @@ | |||
classes, exclude any classes in classpath jars --> | |||
<mx:genjar tag="" includeresources="false" excludeClasspathJars="true" | |||
destfile="${project.targetDirectory}/fedclient.jar" | |||
excludes="**/.class,**/*.java, **/Thumbs.db, **/*.mkd, com/gitblit/wicket/**"> | |||
excludes="**/.class, **/*.java, **/Thumbs.db, **/*.mkd, **/*.md, **/*.css, com/gitblit/wicket/**"> | |||
<mainclass name="com.gitblit.FederationClient" /> | |||
<class name="com.gitblit.Keys" /> | |||
<launcher paths="ext" /> | |||
@@ -335,7 +335,8 @@ | |||
<!-- generate jar by traversing the class hierarchy of the specified | |||
classes, exclude any classes in classpath jars --> | |||
<mx:genjar tag="" includeResources="false" excludeClasspathJars="true" | |||
destfile="${project.targetDirectory}/manager.jar"> | |||
destfile="${project.targetDirectory}/manager.jar" | |||
excludes="**/.class, **/*.java, **/Thumbs.db, **/*.mkd, **/*.md, **/*.css, com/gitblit/wicket/**"> | |||
<resource file="${project.src.dir}/com/gitblit/client/splash.png" /> | |||
<resource file="${project.resources.dir}/gitblt-favicon.png" /> | |||
<resource file="${project.resources.dir}/gitweb-favicon.png" /> | |||
@@ -411,9 +412,10 @@ | |||
<!-- Build API Library jar --> | |||
<mx:genjar tag="" includeResources="false" excludeClasspathJars="true" | |||
destfile="${project.targetDirectory}/gbapi-${project.version}.jar"> | |||
destfile="${project.targetDirectory}/gbapi-${project.version}.jar" | |||
excludes="**/.class, **/*.java, **/Thumbs.db, **/*.mkd, **/*.md, **/*.css, com/gitblit/wicket/**"> | |||
<mainclass name="com.gitblit.client.GitblitClient" /> | |||
<class name="com.gitblit.Keys" /> | |||
<class name="com.gitblit.client.GitblitClient" /> | |||
<class name="com.gitblit.models.FederationModel" /> | |||
<class name="com.gitblit.models.FederationProposal" /> | |||
<class name="com.gitblit.models.FederationSet" /> |
@@ -14,13 +14,13 @@ | |||
</content> | |||
<orderEntry type="sourceFolder" forTests="false" /> | |||
<orderEntry type="module-library"> | |||
<library name="dagger-1.1.0.jar"> | |||
<library name="guice-4.0-beta4.jar"> | |||
<CLASSES> | |||
<root url="jar://$MODULE_DIR$/ext/dagger-1.1.0.jar!/" /> | |||
<root url="jar://$MODULE_DIR$/ext/guice-4.0-beta4.jar!/" /> | |||
</CLASSES> | |||
<JAVADOC /> | |||
<SOURCES> | |||
<root url="jar://$MODULE_DIR$/ext/src/dagger-1.1.0.jar!/" /> | |||
<root url="jar://$MODULE_DIR$/ext/src/guice-4.0-beta4.jar!/" /> | |||
</SOURCES> | |||
</library> | |||
</orderEntry> | |||
@@ -36,24 +36,35 @@ | |||
</library> | |||
</orderEntry> | |||
<orderEntry type="module-library"> | |||
<library name="dagger-compiler-1.1.0.jar"> | |||
<library name="aopalliance-1.0.jar"> | |||
<CLASSES> | |||
<root url="jar://$MODULE_DIR$/ext/dagger-compiler-1.1.0.jar!/" /> | |||
<root url="jar://$MODULE_DIR$/ext/aopalliance-1.0.jar!/" /> | |||
</CLASSES> | |||
<JAVADOC /> | |||
<SOURCES> | |||
<root url="jar://$MODULE_DIR$/ext/src/dagger-compiler-1.1.0.jar!/" /> | |||
<root url="jar://$MODULE_DIR$/ext/src/aopalliance-1.0.jar!/" /> | |||
</SOURCES> | |||
</library> | |||
</orderEntry> | |||
<orderEntry type="module-library"> | |||
<library name="javawriter-2.1.1.jar"> | |||
<library name="guava-17.0.jar"> | |||
<CLASSES> | |||
<root url="jar://$MODULE_DIR$/ext/javawriter-2.1.1.jar!/" /> | |||
<root url="jar://$MODULE_DIR$/ext/guava-17.0.jar!/" /> | |||
</CLASSES> | |||
<JAVADOC /> | |||
<SOURCES> | |||
<root url="jar://$MODULE_DIR$/ext/src/javawriter-2.1.1.jar!/" /> | |||
<root url="jar://$MODULE_DIR$/ext/src/guava-17.0.jar!/" /> | |||
</SOURCES> | |||
</library> | |||
</orderEntry> | |||
<orderEntry type="module-library"> | |||
<library name="guice-servlet-4.0-gb1.jar"> | |||
<CLASSES> | |||
<root url="jar://$MODULE_DIR$/ext/guice-servlet-4.0-gb1.jar!/" /> | |||
</CLASSES> | |||
<JAVADOC /> | |||
<SOURCES> | |||
<root url="jar://$MODULE_DIR$/ext/src/guice-servlet-4.0-gb1.jar!/" /> | |||
</SOURCES> | |||
</library> | |||
</orderEntry> | |||
@@ -724,17 +735,6 @@ | |||
</SOURCES> | |||
</library> | |||
</orderEntry> | |||
<orderEntry type="module-library"> | |||
<library name="guava-13.0.1.jar"> | |||
<CLASSES> | |||
<root url="jar://$MODULE_DIR$/ext/guava-13.0.1.jar!/" /> | |||
</CLASSES> | |||
<JAVADOC /> | |||
<SOURCES> | |||
<root url="jar://$MODULE_DIR$/ext/src/guava-13.0.1.jar!/" /> | |||
</SOURCES> | |||
</library> | |||
</orderEntry> | |||
<orderEntry type="module-library"> | |||
<library name="libpam4j-1.7.jar"> | |||
<CLASSES> |
@@ -24,6 +24,7 @@ r25: { | |||
- Jetty 9.2.1 (pr-202) | |||
- Lucene 4.8.1 (pr-201) | |||
- JGit 3.4.0 (pr-200) | |||
- Guice 4.0-beta4 (ticket-80) | |||
- SLF4j 1.7.7 (ticket-122) | |||
- gson 2.2.2 (ticket-123) | |||
- Freemarker 2.3.20 (ticket-124) |
@@ -1,361 +1,49 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<web-app version="2.4" | |||
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_2_4.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> | |||
<!-- Gitblit Context Listener --><!-- STRIP | |||
<listener> | |||
<listener-class>com.gitblit.servlet.GitblitContext</listener-class> | |||
</listener>STRIP --> | |||
<!-- Git Servlet | |||
<url-pattern> MUST match: | |||
* GitFilter | |||
* com.gitblit.Constants.GIT_PATH | |||
* Wicket Filter ignorePaths parameter --> | |||
<servlet> | |||
<servlet-name>GitServlet</servlet-name> | |||
<servlet-class>com.gitblit.servlet.GitServlet</servlet-class> | |||
</servlet> | |||
<servlet-mapping> | |||
<servlet-name>GitServlet</servlet-name> | |||
<url-pattern>/git/*</url-pattern> | |||
</servlet-mapping> | |||
<servlet-mapping> | |||
<servlet-name>GitServlet</servlet-name> | |||
<url-pattern>/r/*</url-pattern> | |||
</servlet-mapping> | |||
<!-- SparkleShare Invite Servlet | |||
<url-pattern> MUST match: | |||
* com.gitblit.Constants.SPARKLESHARE_INVITE_PATH | |||
* Wicket Filter ignorePaths parameter --> | |||
<servlet> | |||
<servlet-name>SparkleShareInviteServlet</servlet-name> | |||
<servlet-class>com.gitblit.servlet.SparkleShareInviteServlet</servlet-class> | |||
</servlet> | |||
<servlet-mapping> | |||
<servlet-name>SparkleShareInviteServlet</servlet-name> | |||
<url-pattern>/sparkleshare/*</url-pattern> | |||
</servlet-mapping> | |||
<!-- Syndication Servlet | |||
<url-pattern> MUST match: | |||
* SyndicationFilter | |||
* com.gitblit.Constants.SYNDICATION_PATH | |||
* Wicket Filter ignorePaths parameter --> | |||
<servlet> | |||
<servlet-name>SyndicationServlet</servlet-name> | |||
<servlet-class>com.gitblit.servlet.SyndicationServlet</servlet-class> | |||
</servlet> | |||
<servlet-mapping> | |||
<servlet-name>SyndicationServlet</servlet-name> | |||
<url-pattern>/feed/*</url-pattern> | |||
</servlet-mapping> | |||
<!-- Zip Servlet | |||
<url-pattern> MUST match: | |||
* ZipServlet | |||
* com.gitblit.Constants.ZIP_PATH | |||
* Wicket Filter ignorePaths parameter --> | |||
<servlet> | |||
<servlet-name>ZipServlet</servlet-name> | |||
<servlet-class>com.gitblit.servlet.DownloadZipServlet</servlet-class> | |||
</servlet> | |||
<servlet-mapping> | |||
<servlet-name>ZipServlet</servlet-name> | |||
<url-pattern>/zip/*</url-pattern> | |||
</servlet-mapping> | |||
<!-- Federation Servlet | |||
<url-pattern> MUST match: | |||
* com.gitblit.Constants.FEDERATION_PATH | |||
* Wicket Filter ignorePaths parameter --> | |||
<servlet> | |||
<servlet-name>FederationServlet</servlet-name> | |||
<servlet-class>com.gitblit.servlet.FederationServlet</servlet-class> | |||
</servlet> | |||
<servlet-mapping> | |||
<servlet-name>FederationServlet</servlet-name> | |||
<url-pattern>/federation/*</url-pattern> | |||
</servlet-mapping> | |||
<!-- Rpc Servlet | |||
<url-pattern> MUST match: | |||
* com.gitblit.Constants.RPC_PATH | |||
* Wicket Filter ignorePaths parameter --> | |||
<servlet> | |||
<servlet-name>RpcServlet</servlet-name> | |||
<servlet-class>com.gitblit.servlet.RpcServlet</servlet-class> | |||
</servlet> | |||
<servlet-mapping> | |||
<servlet-name>RpcServlet</servlet-name> | |||
<url-pattern>/rpc/*</url-pattern> | |||
</servlet-mapping> | |||
<!-- Raw Servlet | |||
<url-pattern> MUST match: | |||
* RawFilter | |||
* com.gitblit.Constants.RAW_PATH | |||
* Wicket Filter ignorePaths parameter --> | |||
<servlet> | |||
<servlet-name>RawServlet</servlet-name> | |||
<servlet-class>com.gitblit.servlet.RawServlet</servlet-class> | |||
</servlet> | |||
<servlet-mapping> | |||
<servlet-name>RawServlet</servlet-name> | |||
<url-pattern>/raw/*</url-pattern> | |||
</servlet-mapping> | |||
<!-- Pages Servlet | |||
<url-pattern> MUST match: | |||
* PagesFilter | |||
* com.gitblit.Constants.PAGES_PATH | |||
* Wicket Filter ignorePaths parameter --> | |||
<servlet> | |||
<servlet-name>PagesServlet</servlet-name> | |||
<servlet-class>com.gitblit.servlet.PagesServlet</servlet-class> | |||
</servlet> | |||
<servlet-mapping> | |||
<servlet-name>PagesServlet</servlet-name> | |||
<url-pattern>/pages/*</url-pattern> | |||
</servlet-mapping> | |||
<!-- Logo Servlet | |||
<url-pattern> MUST match: | |||
* Wicket Filter ignorePaths parameter --> | |||
<servlet> | |||
<servlet-name>LogoServlet</servlet-name> | |||
<servlet-class>com.gitblit.servlet.LogoServlet</servlet-class> | |||
</servlet> | |||
<servlet-mapping> | |||
<servlet-name>LogoServlet</servlet-name> | |||
<url-pattern>/logo.png</url-pattern> | |||
</servlet-mapping> | |||
<!-- PT Servlet | |||
<url-pattern> MUST match: | |||
* Wicket Filter ignorePaths parameter --> | |||
<servlet> | |||
<servlet-name>PtServlet</servlet-name> | |||
<servlet-class>com.gitblit.servlet.PtServlet</servlet-class> | |||
</servlet> | |||
<servlet-mapping> | |||
<servlet-name>PtServlet</servlet-name> | |||
<url-pattern>/pt</url-pattern> | |||
</servlet-mapping> | |||
<!-- Branch Graph Servlet | |||
<url-pattern> MUST match: | |||
* Wicket Filter ignorePaths parameter --> | |||
<servlet> | |||
<servlet-name>BranchGraphServlet</servlet-name> | |||
<servlet-class>com.gitblit.servlet.BranchGraphServlet</servlet-class> | |||
</servlet> | |||
<servlet-mapping> | |||
<servlet-name>BranchGraphServlet</servlet-name> | |||
<url-pattern>/graph/*</url-pattern> | |||
</servlet-mapping> | |||
<!-- Robots.txt Servlet | |||
<url-pattern> MUST match: | |||
* Wicket Filter ignorePaths parameter --> | |||
<servlet> | |||
<servlet-name>RobotsTxtServlet</servlet-name> | |||
<servlet-class>com.gitblit.servlet.RobotsTxtServlet</servlet-class> | |||
</servlet> | |||
<servlet-mapping> | |||
<servlet-name>RobotsTxtServlet</servlet-name> | |||
<url-pattern>/robots.txt</url-pattern> | |||
</servlet-mapping> | |||
<filter> | |||
<filter-name>ProxyFilter</filter-name> | |||
<filter-class>com.gitblit.servlet.ProxyFilter</filter-class> | |||
</filter> | |||
<filter-mapping> | |||
<filter-name>ProxyFilter</filter-name> | |||
<url-pattern>/*</url-pattern> | |||
</filter-mapping> | |||
<!-- Git Access Restriction Filter | |||
<url-pattern> MUST match: | |||
* GitServlet | |||
* com.gitblit.Constants.GIT_PATH | |||
* Wicket Filter ignorePaths parameter --> | |||
<filter> | |||
<filter-name>GitFilter</filter-name> | |||
<filter-class>com.gitblit.servlet.GitFilter</filter-class> | |||
</filter> | |||
<filter-mapping> | |||
<filter-name>GitFilter</filter-name> | |||
<url-pattern>/git/*</url-pattern> | |||
</filter-mapping> | |||
<filter-mapping> | |||
<filter-name>GitFilter</filter-name> | |||
<url-pattern>/r/*</url-pattern> | |||
</filter-mapping> | |||
<!-- Syndication Restriction Filter | |||
<url-pattern> MUST match: | |||
* SyndicationServlet | |||
* com.gitblit.Constants.SYNDICATION_PATH | |||
* Wicket Filter ignorePaths parameter --> | |||
<filter> | |||
<filter-name>SyndicationFilter</filter-name> | |||
<filter-class>com.gitblit.servlet.SyndicationFilter</filter-class> | |||
</filter> | |||
<filter-mapping> | |||
<filter-name>SyndicationFilter</filter-name> | |||
<url-pattern>/feed/*</url-pattern> | |||
</filter-mapping> | |||
<!-- Download Zip Restriction Filter | |||
<url-pattern> MUST match: | |||
* DownloadZipServlet | |||
* com.gitblit.Constants.ZIP_PATH | |||
* Wicket Filter ignorePaths parameter --> | |||
<filter> | |||
<filter-name>ZipFilter</filter-name> | |||
<filter-class>com.gitblit.servlet.DownloadZipFilter</filter-class> | |||
</filter> | |||
<filter-mapping> | |||
<filter-name>ZipFilter</filter-name> | |||
<url-pattern>/zip/*</url-pattern> | |||
</filter-mapping> | |||
<!-- Rpc Restriction Filter | |||
<url-pattern> MUST match: | |||
* RpcServlet | |||
* com.gitblit.Constants.RPC_PATH | |||
* Wicket Filter ignorePaths parameter --> | |||
<filter> | |||
<filter-name>RpcFilter</filter-name> | |||
<filter-class>com.gitblit.servlet.RpcFilter</filter-class> | |||
</filter> | |||
<filter-mapping> | |||
<filter-name>RpcFilter</filter-name> | |||
<url-pattern>/rpc/*</url-pattern> | |||
</filter-mapping> | |||
<!-- Branch Restriction Filter | |||
<url-pattern> MUST match: | |||
* RawServlet | |||
* com.gitblit.Constants.BRANCH_PATH | |||
* Wicket Filter ignorePaths parameter --> | |||
<filter> | |||
<filter-name>RawFilter</filter-name> | |||
<filter-class>com.gitblit.servlet.RawFilter</filter-class> | |||
</filter> | |||
<filter-mapping> | |||
<filter-name>RawFilter</filter-name> | |||
<url-pattern>/raw/*</url-pattern> | |||
</filter-mapping> | |||
<!-- Pages Restriction Filter | |||
<url-pattern> MUST match: | |||
* PagesServlet | |||
* com.gitblit.Constants.PAGES_PATH | |||
* Wicket Filter ignorePaths parameter --> | |||
<filter> | |||
<filter-name>PagesFilter</filter-name> | |||
<filter-class>com.gitblit.servlet.PagesFilter</filter-class> | |||
</filter> | |||
<filter-mapping> | |||
<filter-name>PagesFilter</filter-name> | |||
<url-pattern>/pages/*</url-pattern> | |||
</filter-mapping> | |||
<filter> | |||
<filter-name>EnforceAuthenticationFilter</filter-name> | |||
<filter-class>com.gitblit.servlet.EnforceAuthenticationFilter</filter-class> | |||
</filter> | |||
<filter-mapping> | |||
<filter-name>EnforceAuthenticationFilter</filter-name> | |||
<url-pattern>/*</url-pattern> | |||
</filter-mapping> | |||
<!-- Wicket Filter --> | |||
<filter> | |||
<filter-name>wicketFilter</filter-name> | |||
<filter-class> | |||
com.gitblit.wicket.GitblitWicketFilter | |||
</filter-class> | |||
<init-param> | |||
<param-name>ignorePaths</param-name> | |||
<!-- Paths should match | |||
* SyndicationFilter <url-pattern> | |||
* SyndicationServlet <url-pattern> | |||
* com.gitblit.Constants.SYNDICATION_PATH | |||
* GitFilter <url-pattern> | |||
* GitServlet <url-pattern> | |||
* com.gitblit.Constants.GIT_PATH | |||
* SparkleshareInviteServlet <url-pattern> | |||
* com.gitblit.Constants.SPARKLESHARE_INVITE_PATH | |||
* Zipfilter <url-pattern> | |||
* ZipServlet <url-pattern> | |||
* com.gitblit.Constants.ZIP_PATH | |||
* FederationServlet <url-pattern> | |||
* RpcFilter <url-pattern> | |||
* RpcServlet <url-pattern> | |||
* RawFilter <url-pattern> | |||
* RawServlet <url-pattern> | |||
* PagesFilter <url-pattern> | |||
* PagesServlet <url-pattern> | |||
* com.gitblit.Constants.PAGES_PATH --> | |||
<param-value>r/,git/,pt,feed/,zip/,federation/,rpc/,raw/,pages/,robots.txt,logo.png,graph/,sparkleshare/</param-value> | |||
</init-param> | |||
</filter> | |||
<filter-mapping> | |||
<filter-name>wicketFilter</filter-name> | |||
<url-pattern>/*</url-pattern> | |||
</filter-mapping> | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<web-app version="2.4" | |||
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_2_4.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> | |||
<listener> | |||
<listener-class>com.gitblit.servlet.GitblitContext</listener-class> | |||
</listener> | |||
<filter> | |||
<filter-name>guiceFilter</filter-name> | |||
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class> | |||
</filter> | |||
<filter-mapping> | |||
<filter-name>guiceFilter</filter-name> | |||
<url-pattern>/*</url-pattern> | |||
</filter-mapping> | |||
</web-app> |
@@ -70,6 +70,8 @@ public class Constants { | |||
public static final String RAW_PATH = "/raw/"; | |||
public static final String PT_PATH = "/pt"; | |||
public static final String BRANCH_GRAPH_PATH = "/graph/"; | |||
public static final String BORDER = "*****************************************************************"; |
@@ -1,215 +0,0 @@ | |||
/* | |||
* Copyright 2013 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; | |||
import javax.inject.Singleton; | |||
import com.gitblit.manager.AuthenticationManager; | |||
import com.gitblit.manager.FederationManager; | |||
import com.gitblit.manager.IAuthenticationManager; | |||
import com.gitblit.manager.IFederationManager; | |||
import com.gitblit.manager.IGitblit; | |||
import com.gitblit.manager.INotificationManager; | |||
import com.gitblit.manager.IPluginManager; | |||
import com.gitblit.manager.IProjectManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.manager.IUserManager; | |||
import com.gitblit.manager.NotificationManager; | |||
import com.gitblit.manager.PluginManager; | |||
import com.gitblit.manager.ProjectManager; | |||
import com.gitblit.manager.RepositoryManager; | |||
import com.gitblit.manager.RuntimeManager; | |||
import com.gitblit.manager.UserManager; | |||
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 dagger.Module; | |||
import dagger.Provides; | |||
/** | |||
* DaggerModule references all injectable objects. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
@Module( | |||
library = true, | |||
injects = { | |||
IStoredSettings.class, | |||
// core managers | |||
IRuntimeManager.class, | |||
IPluginManager.class, | |||
INotificationManager.class, | |||
IUserManager.class, | |||
IAuthenticationManager.class, | |||
IPublicKeyManager.class, | |||
IRepositoryManager.class, | |||
IProjectManager.class, | |||
IFederationManager.class, | |||
// the monolithic manager | |||
IGitblit.class, | |||
// the Gitblit Wicket app | |||
GitBlitWebApp.class | |||
} | |||
) | |||
public class DaggerModule { | |||
@Provides @Singleton IStoredSettings provideSettings() { | |||
return new FileSettings(); | |||
} | |||
@Provides @Singleton IRuntimeManager provideRuntimeManager(IStoredSettings settings) { | |||
return new RuntimeManager(settings); | |||
} | |||
@Provides @Singleton IPluginManager providePluginManager(IRuntimeManager runtimeManager) { | |||
return new PluginManager(runtimeManager); | |||
} | |||
@Provides @Singleton INotificationManager provideNotificationManager(IStoredSettings settings) { | |||
return new NotificationManager(settings); | |||
} | |||
@Provides @Singleton IUserManager provideUserManager( | |||
IRuntimeManager runtimeManager, | |||
IPluginManager pluginManager) { | |||
return new UserManager(runtimeManager, pluginManager); | |||
} | |||
@Provides @Singleton IAuthenticationManager provideAuthenticationManager( | |||
IRuntimeManager runtimeManager, | |||
IUserManager userManager) { | |||
return new AuthenticationManager( | |||
runtimeManager, | |||
userManager); | |||
} | |||
@Provides @Singleton IPublicKeyManager providePublicKeyManager( | |||
IStoredSettings settings, | |||
IRuntimeManager runtimeManager) { | |||
String clazz = settings.getString(Keys.git.sshKeysManager, FileKeyManager.class.getName()); | |||
if (StringUtils.isEmpty(clazz)) { | |||
clazz = FileKeyManager.class.getName(); | |||
} | |||
if (FileKeyManager.class.getName().equals(clazz)) { | |||
return new FileKeyManager(runtimeManager); | |||
} else if (NullKeyManager.class.getName().equals(clazz)) { | |||
return new NullKeyManager(); | |||
} else if (MemoryKeyManager.class.getName().equals(clazz)) { | |||
return new MemoryKeyManager(); | |||
} else { | |||
try { | |||
Class<?> mgrClass = Class.forName(clazz); | |||
return (IPublicKeyManager) mgrClass.newInstance(); | |||
} catch (Exception e) { | |||
} | |||
return null; | |||
} | |||
} | |||
@Provides @Singleton IRepositoryManager provideRepositoryManager( | |||
IRuntimeManager runtimeManager, | |||
IPluginManager pluginManager, | |||
IUserManager userManager) { | |||
return new RepositoryManager( | |||
runtimeManager, | |||
pluginManager, | |||
userManager); | |||
} | |||
@Provides @Singleton IProjectManager provideProjectManager( | |||
IRuntimeManager runtimeManager, | |||
IUserManager userManager, | |||
IRepositoryManager repositoryManager) { | |||
return new ProjectManager( | |||
runtimeManager, | |||
userManager, | |||
repositoryManager); | |||
} | |||
@Provides @Singleton IFederationManager provideFederationManager( | |||
IRuntimeManager runtimeManager, | |||
INotificationManager notificationManager, | |||
IRepositoryManager repositoryManager) { | |||
return new FederationManager( | |||
runtimeManager, | |||
notificationManager, | |||
repositoryManager); | |||
} | |||
@Provides @Singleton IGitblit provideGitblit( | |||
IRuntimeManager runtimeManager, | |||
IPluginManager pluginManager, | |||
INotificationManager notificationManager, | |||
IUserManager userManager, | |||
IAuthenticationManager authenticationManager, | |||
IPublicKeyManager publicKeyManager, | |||
IRepositoryManager repositoryManager, | |||
IProjectManager projectManager, | |||
IFederationManager federationManager) { | |||
return new GitBlit( | |||
runtimeManager, | |||
pluginManager, | |||
notificationManager, | |||
userManager, | |||
authenticationManager, | |||
publicKeyManager, | |||
repositoryManager, | |||
projectManager, | |||
federationManager); | |||
} | |||
@Provides @Singleton GitBlitWebApp provideWebApplication( | |||
IRuntimeManager runtimeManager, | |||
IPluginManager pluginManager, | |||
INotificationManager notificationManager, | |||
IUserManager userManager, | |||
IAuthenticationManager authenticationManager, | |||
IPublicKeyManager publicKeyManager, | |||
IRepositoryManager repositoryManager, | |||
IProjectManager projectManager, | |||
IFederationManager federationManager, | |||
IGitblit gitblit) { | |||
return new GitBlitWebApp( | |||
runtimeManager, | |||
pluginManager, | |||
notificationManager, | |||
userManager, | |||
authenticationManager, | |||
publicKeyManager, | |||
repositoryManager, | |||
projectManager, | |||
federationManager, | |||
gitblit); | |||
} | |||
} |
@@ -1,189 +1,189 @@ | |||
/* | |||
* Copyright 2011 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; | |||
import java.io.File; | |||
import java.util.ArrayList; | |||
import java.util.Collection; | |||
import java.util.List; | |||
import org.kohsuke.args4j.CmdLineException; | |||
import org.kohsuke.args4j.CmdLineParser; | |||
import org.kohsuke.args4j.Option; | |||
import com.gitblit.manager.FederationManager; | |||
import com.gitblit.manager.GitblitManager; | |||
import com.gitblit.manager.IGitblit; | |||
import com.gitblit.manager.INotificationManager; | |||
import com.gitblit.manager.RepositoryManager; | |||
import com.gitblit.manager.RuntimeManager; | |||
import com.gitblit.manager.UserManager; | |||
import com.gitblit.models.FederationModel; | |||
import com.gitblit.models.Mailing; | |||
import com.gitblit.service.FederationPullService; | |||
import com.gitblit.utils.FederationUtils; | |||
import com.gitblit.utils.StringUtils; | |||
/** | |||
* Command-line client to pull federated Gitblit repositories. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
public class FederationClient { | |||
public static void main(String[] args) { | |||
Params params = new Params(); | |||
CmdLineParser parser = new CmdLineParser(params); | |||
try { | |||
parser.parseArgument(args); | |||
} catch (CmdLineException t) { | |||
usage(parser, t); | |||
} | |||
System.out.println("Gitblit Federation Client v" + Constants.getVersion() + " (" + Constants.getBuildDate() + ")"); | |||
// command-line specified base folder | |||
File baseFolder = new File(System.getProperty("user.dir")); | |||
if (!StringUtils.isEmpty(params.baseFolder)) { | |||
baseFolder = new File(params.baseFolder); | |||
} | |||
File regFile = com.gitblit.utils.FileUtils.resolveParameter(Constants.baseFolder$, baseFolder, params.registrationsFile); | |||
FileSettings settings = new FileSettings(regFile.getAbsolutePath()); | |||
List<FederationModel> registrations = new ArrayList<FederationModel>(); | |||
if (StringUtils.isEmpty(params.url)) { | |||
registrations.addAll(FederationUtils.getFederationRegistrations(settings)); | |||
} else { | |||
if (StringUtils.isEmpty(params.token)) { | |||
System.out.println("Must specify --token parameter!"); | |||
System.exit(0); | |||
} | |||
FederationModel model = new FederationModel("Gitblit"); | |||
model.url = params.url; | |||
model.token = params.token; | |||
model.mirror = params.mirror; | |||
model.bare = params.bare; | |||
model.folder = ""; | |||
registrations.add(model); | |||
} | |||
if (registrations.size() == 0) { | |||
System.out.println("No Federation Registrations! Nothing to do."); | |||
System.exit(0); | |||
} | |||
// command-line specified repositories folder | |||
if (!StringUtils.isEmpty(params.repositoriesFolder)) { | |||
settings.overrideSetting(Keys.git.repositoriesFolder, new File( | |||
params.repositoriesFolder).getAbsolutePath()); | |||
} | |||
// configure the Gitblit singleton for minimal, non-server operation | |||
RuntimeManager runtime = new RuntimeManager(settings, baseFolder).start(); | |||
NoopNotificationManager notifications = new NoopNotificationManager().start(); | |||
UserManager users = new UserManager(runtime, null).start(); | |||
RepositoryManager repositories = new RepositoryManager(runtime, null, users).start(); | |||
FederationManager federation = new FederationManager(runtime, notifications, repositories).start(); | |||
IGitblit gitblit = new GitblitManager(runtime, null, notifications, users, null, null, repositories, null, federation); | |||
FederationPullService puller = new FederationPullService(gitblit, federation.getFederationRegistrations()) { | |||
@Override | |||
public void reschedule(FederationModel registration) { | |||
// NOOP | |||
} | |||
}; | |||
puller.run(); | |||
System.out.println("Finished."); | |||
System.exit(0); | |||
} | |||
private static void usage(CmdLineParser parser, CmdLineException t) { | |||
System.out.println(Constants.getGitBlitVersion()); | |||
System.out.println(); | |||
if (t != null) { | |||
System.out.println(t.getMessage()); | |||
System.out.println(); | |||
} | |||
if (parser != null) { | |||
parser.printUsage(System.out); | |||
} | |||
System.exit(0); | |||
} | |||
/** | |||
* Parameters class for FederationClient. | |||
*/ | |||
private static class Params { | |||
@Option(name = "--registrations", usage = "Gitblit Federation Registrations File", metaVar = "FILE") | |||
public String registrationsFile = "${baseFolder}/federation.properties"; | |||
@Option(name = "--url", usage = "URL of Gitblit instance to mirror from", metaVar = "URL") | |||
public String url; | |||
@Option(name = "--mirror", usage = "Mirror repositories") | |||
public boolean mirror; | |||
@Option(name = "--bare", usage = "Create bare repositories") | |||
public boolean bare; | |||
@Option(name = "--token", usage = "Federation Token", metaVar = "TOKEN") | |||
public String token; | |||
@Option(name = "--baseFolder", usage = "Base folder for received data", metaVar = "PATH") | |||
public String baseFolder; | |||
@Option(name = "--repositoriesFolder", usage = "Destination folder for cloned repositories", metaVar = "PATH") | |||
public String repositoriesFolder; | |||
} | |||
private static class NoopNotificationManager implements INotificationManager { | |||
@Override | |||
public NoopNotificationManager start() { | |||
return this; | |||
} | |||
@Override | |||
public NoopNotificationManager stop() { | |||
return this; | |||
} | |||
@Override | |||
public boolean isSendingMail() { | |||
return false; | |||
} | |||
@Override | |||
public void sendMailToAdministrators(String subject, String message) { | |||
} | |||
@Override | |||
public void sendMail(String subject, String message, Collection<String> toAddresses) { | |||
} | |||
@Override | |||
public void sendHtmlMail(String subject, String message, Collection<String> toAddresses) { | |||
} | |||
@Override | |||
public void send(Mailing mailing) { | |||
} | |||
} | |||
} | |||
/* | |||
* Copyright 2011 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; | |||
import java.io.File; | |||
import java.util.ArrayList; | |||
import java.util.Collection; | |||
import java.util.List; | |||
import org.kohsuke.args4j.CmdLineException; | |||
import org.kohsuke.args4j.CmdLineParser; | |||
import org.kohsuke.args4j.Option; | |||
import com.gitblit.manager.FederationManager; | |||
import com.gitblit.manager.GitblitManager; | |||
import com.gitblit.manager.IGitblit; | |||
import com.gitblit.manager.INotificationManager; | |||
import com.gitblit.manager.RepositoryManager; | |||
import com.gitblit.manager.RuntimeManager; | |||
import com.gitblit.manager.UserManager; | |||
import com.gitblit.models.FederationModel; | |||
import com.gitblit.models.Mailing; | |||
import com.gitblit.service.FederationPullService; | |||
import com.gitblit.utils.FederationUtils; | |||
import com.gitblit.utils.StringUtils; | |||
/** | |||
* Command-line client to pull federated Gitblit repositories. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
public class FederationClient { | |||
public static void main(String[] args) { | |||
Params params = new Params(); | |||
CmdLineParser parser = new CmdLineParser(params); | |||
try { | |||
parser.parseArgument(args); | |||
} catch (CmdLineException t) { | |||
usage(parser, t); | |||
} | |||
System.out.println("Gitblit Federation Client v" + Constants.getVersion() + " (" + Constants.getBuildDate() + ")"); | |||
// command-line specified base folder | |||
File baseFolder = new File(System.getProperty("user.dir")); | |||
if (!StringUtils.isEmpty(params.baseFolder)) { | |||
baseFolder = new File(params.baseFolder); | |||
} | |||
File regFile = com.gitblit.utils.FileUtils.resolveParameter(Constants.baseFolder$, baseFolder, params.registrationsFile); | |||
FileSettings settings = new FileSettings(regFile.getAbsolutePath()); | |||
List<FederationModel> registrations = new ArrayList<FederationModel>(); | |||
if (StringUtils.isEmpty(params.url)) { | |||
registrations.addAll(FederationUtils.getFederationRegistrations(settings)); | |||
} else { | |||
if (StringUtils.isEmpty(params.token)) { | |||
System.out.println("Must specify --token parameter!"); | |||
System.exit(0); | |||
} | |||
FederationModel model = new FederationModel("Gitblit"); | |||
model.url = params.url; | |||
model.token = params.token; | |||
model.mirror = params.mirror; | |||
model.bare = params.bare; | |||
model.folder = ""; | |||
registrations.add(model); | |||
} | |||
if (registrations.size() == 0) { | |||
System.out.println("No Federation Registrations! Nothing to do."); | |||
System.exit(0); | |||
} | |||
// command-line specified repositories folder | |||
if (!StringUtils.isEmpty(params.repositoriesFolder)) { | |||
settings.overrideSetting(Keys.git.repositoriesFolder, new File( | |||
params.repositoriesFolder).getAbsolutePath()); | |||
} | |||
// configure the Gitblit singleton for minimal, non-server operation | |||
RuntimeManager runtime = new RuntimeManager(settings, baseFolder).start(); | |||
NoopNotificationManager notifications = new NoopNotificationManager().start(); | |||
UserManager users = new UserManager(runtime, null).start(); | |||
RepositoryManager repositories = new RepositoryManager(runtime, null, users).start(); | |||
FederationManager federation = new FederationManager(runtime, notifications, repositories).start(); | |||
IGitblit gitblit = new GitblitManager(null, null, runtime, null, notifications, users, null, repositories, null, federation); | |||
FederationPullService puller = new FederationPullService(gitblit, federation.getFederationRegistrations()) { | |||
@Override | |||
public void reschedule(FederationModel registration) { | |||
// NOOP | |||
} | |||
}; | |||
puller.run(); | |||
System.out.println("Finished."); | |||
System.exit(0); | |||
} | |||
private static void usage(CmdLineParser parser, CmdLineException t) { | |||
System.out.println(Constants.getGitBlitVersion()); | |||
System.out.println(); | |||
if (t != null) { | |||
System.out.println(t.getMessage()); | |||
System.out.println(); | |||
} | |||
if (parser != null) { | |||
parser.printUsage(System.out); | |||
} | |||
System.exit(0); | |||
} | |||
/** | |||
* Parameters class for FederationClient. | |||
*/ | |||
private static class Params { | |||
@Option(name = "--registrations", usage = "Gitblit Federation Registrations File", metaVar = "FILE") | |||
public String registrationsFile = "${baseFolder}/federation.properties"; | |||
@Option(name = "--url", usage = "URL of Gitblit instance to mirror from", metaVar = "URL") | |||
public String url; | |||
@Option(name = "--mirror", usage = "Mirror repositories") | |||
public boolean mirror; | |||
@Option(name = "--bare", usage = "Create bare repositories") | |||
public boolean bare; | |||
@Option(name = "--token", usage = "Federation Token", metaVar = "TOKEN") | |||
public String token; | |||
@Option(name = "--baseFolder", usage = "Base folder for received data", metaVar = "PATH") | |||
public String baseFolder; | |||
@Option(name = "--repositoriesFolder", usage = "Destination folder for cloned repositories", metaVar = "PATH") | |||
public String repositoriesFolder; | |||
} | |||
private static class NoopNotificationManager implements INotificationManager { | |||
@Override | |||
public NoopNotificationManager start() { | |||
return this; | |||
} | |||
@Override | |||
public NoopNotificationManager stop() { | |||
return this; | |||
} | |||
@Override | |||
public boolean isSendingMail() { | |||
return false; | |||
} | |||
@Override | |||
public void sendMailToAdministrators(String subject, String message) { | |||
} | |||
@Override | |||
public void sendMail(String subject, String message, Collection<String> toAddresses) { | |||
} | |||
@Override | |||
public void sendHtmlMail(String subject, String message, Collection<String> toAddresses) { | |||
} | |||
@Override | |||
public void send(Mailing mailing) { | |||
} | |||
} | |||
} |
@@ -15,471 +15,55 @@ | |||
*/ | |||
package com.gitblit; | |||
import java.text.MessageFormat; | |||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.Comparator; | |||
import java.util.HashSet; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Set; | |||
import javax.inject.Singleton; | |||
import javax.servlet.http.HttpServletRequest; | |||
import com.gitblit.Constants.AccessPermission; | |||
import com.gitblit.Constants.Transport; | |||
import com.gitblit.manager.GitblitManager; | |||
import com.gitblit.manager.IAuthenticationManager; | |||
import com.gitblit.manager.IFederationManager; | |||
import com.gitblit.manager.IGitblit; | |||
import com.gitblit.manager.INotificationManager; | |||
import com.gitblit.manager.IPluginManager; | |||
import com.gitblit.manager.IProjectManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.manager.IUserManager; | |||
import com.gitblit.manager.ServicesManager; | |||
import com.gitblit.models.RepositoryModel; | |||
import com.gitblit.models.RepositoryUrl; | |||
import com.gitblit.models.UserModel; | |||
import com.gitblit.tickets.BranchTicketService; | |||
import com.gitblit.tickets.FileTicketService; | |||
import com.gitblit.tickets.ITicketService; | |||
import com.gitblit.tickets.NullTicketService; | |||
import com.gitblit.tickets.RedisTicketService; | |||
import com.gitblit.transport.ssh.IPublicKeyManager; | |||
import com.gitblit.utils.StringUtils; | |||
import dagger.Module; | |||
import dagger.ObjectGraph; | |||
import dagger.Provides; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Provider; | |||
import com.google.inject.Singleton; | |||
/** | |||
* GitBlit is the aggregate manager for the Gitblit webapp. It provides all | |||
* management functions and also manages some long-running services. | |||
* GitBlit is the aggregate manager for the Gitblit webapp. The parent class provides all | |||
* functionality. This class exists to not break existing Groovy push hooks. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
@Deprecated | |||
public class GitBlit extends GitblitManager { | |||
private final ObjectGraph injector; | |||
private final ServicesManager servicesManager; | |||
private ITicketService ticketService; | |||
@Inject | |||
public GitBlit( | |||
Provider<IPublicKeyManager> publicKeyManagerProvider, | |||
Provider<ITicketService> ticketServiceProvider, | |||
IRuntimeManager runtimeManager, | |||
IPluginManager pluginManager, | |||
INotificationManager notificationManager, | |||
IUserManager userManager, | |||
IAuthenticationManager authenticationManager, | |||
IPublicKeyManager publicKeyManager, | |||
IRepositoryManager repositoryManager, | |||
IProjectManager projectManager, | |||
IFederationManager federationManager) { | |||
super(runtimeManager, | |||
super( | |||
publicKeyManagerProvider, | |||
ticketServiceProvider, | |||
runtimeManager, | |||
pluginManager, | |||
notificationManager, | |||
userManager, | |||
authenticationManager, | |||
publicKeyManager, | |||
repositoryManager, | |||
projectManager, | |||
federationManager); | |||
this.injector = ObjectGraph.create(getModules()); | |||
this.servicesManager = new ServicesManager(this); | |||
} | |||
@Override | |||
public GitBlit start() { | |||
super.start(); | |||
logger.info("Starting services manager..."); | |||
servicesManager.start(); | |||
configureTicketService(); | |||
return this; | |||
} | |||
@Override | |||
public GitBlit stop() { | |||
super.stop(); | |||
servicesManager.stop(); | |||
ticketService.stop(); | |||
return this; | |||
} | |||
@Override | |||
public boolean isServingRepositories() { | |||
return servicesManager.isServingRepositories(); | |||
} | |||
@Override | |||
public boolean isServingHTTP() { | |||
return servicesManager.isServingHTTP(); | |||
} | |||
@Override | |||
public boolean isServingGIT() { | |||
return servicesManager.isServingGIT(); | |||
} | |||
@Override | |||
public boolean isServingSSH() { | |||
return servicesManager.isServingSSH(); | |||
} | |||
protected Object [] getModules() { | |||
return new Object [] { new GitBlitModule()}; | |||
} | |||
protected boolean acceptPush(Transport byTransport) { | |||
if (byTransport == null) { | |||
logger.info("Unknown transport, push rejected!"); | |||
return false; | |||
} | |||
Set<Transport> transports = new HashSet<Transport>(); | |||
for (String value : getSettings().getStrings(Keys.git.acceptedPushTransports)) { | |||
Transport transport = Transport.fromString(value); | |||
if (transport == null) { | |||
logger.info(String.format("Ignoring unknown registered transport %s", value)); | |||
continue; | |||
} | |||
transports.add(transport); | |||
} | |||
if (transports.isEmpty()) { | |||
// no transports are explicitly specified, all are acceptable | |||
return true; | |||
} | |||
// verify that the transport is permitted | |||
return transports.contains(byTransport); | |||
} | |||
/** | |||
* Returns a list of repository URLs and the user access permission. | |||
* | |||
* @param request | |||
* @param user | |||
* @param repository | |||
* @return a list of repository urls | |||
*/ | |||
@Override | |||
public List<RepositoryUrl> getRepositoryUrls(HttpServletRequest request, UserModel user, RepositoryModel repository) { | |||
if (user == null) { | |||
user = UserModel.ANONYMOUS; | |||
} | |||
String username = StringUtils.encodeUsername(UserModel.ANONYMOUS.equals(user) ? "" : user.username); | |||
List<RepositoryUrl> list = new ArrayList<RepositoryUrl>(); | |||
// http/https url | |||
if (settings.getBoolean(Keys.git.enableGitServlet, true)) { | |||
AccessPermission permission = user.getRepositoryPermission(repository).permission; | |||
if (permission.exceeds(AccessPermission.NONE)) { | |||
Transport transport = Transport.fromString(request.getScheme()); | |||
if (permission.atLeast(AccessPermission.PUSH) && !acceptPush(transport)) { | |||
// downgrade the repo permission for this transport | |||
// because it is not an acceptable PUSH transport | |||
permission = AccessPermission.CLONE; | |||
} | |||
list.add(new RepositoryUrl(getRepositoryUrl(request, username, repository), permission)); | |||
} | |||
} | |||
// ssh daemon url | |||
String sshDaemonUrl = servicesManager.getSshDaemonUrl(request, user, repository); | |||
if (!StringUtils.isEmpty(sshDaemonUrl)) { | |||
AccessPermission permission = user.getRepositoryPermission(repository).permission; | |||
if (permission.exceeds(AccessPermission.NONE)) { | |||
if (permission.atLeast(AccessPermission.PUSH) && !acceptPush(Transport.SSH)) { | |||
// downgrade the repo permission for this transport | |||
// because it is not an acceptable PUSH transport | |||
permission = AccessPermission.CLONE; | |||
} | |||
list.add(new RepositoryUrl(sshDaemonUrl, permission)); | |||
} | |||
} | |||
// git daemon url | |||
String gitDaemonUrl = servicesManager.getGitDaemonUrl(request, user, repository); | |||
if (!StringUtils.isEmpty(gitDaemonUrl)) { | |||
AccessPermission permission = servicesManager.getGitDaemonAccessPermission(user, repository); | |||
if (permission.exceeds(AccessPermission.NONE)) { | |||
if (permission.atLeast(AccessPermission.PUSH) && !acceptPush(Transport.GIT)) { | |||
// downgrade the repo permission for this transport | |||
// because it is not an acceptable PUSH transport | |||
permission = AccessPermission.CLONE; | |||
} | |||
list.add(new RepositoryUrl(gitDaemonUrl, permission)); | |||
} | |||
} | |||
// add all other urls | |||
// {0} = repository | |||
// {1} = username | |||
for (String url : settings.getStrings(Keys.web.otherUrls)) { | |||
if (url.contains("{1}")) { | |||
// external url requires username, only add url IF we have one | |||
if (!StringUtils.isEmpty(username)) { | |||
list.add(new RepositoryUrl(MessageFormat.format(url, repository.name, username), null)); | |||
} | |||
} else { | |||
// external url does not require username | |||
list.add(new RepositoryUrl(MessageFormat.format(url, repository.name), null)); | |||
} | |||
} | |||
// sort transports by highest permission and then by transport security | |||
Collections.sort(list, new Comparator<RepositoryUrl>() { | |||
@Override | |||
public int compare(RepositoryUrl o1, RepositoryUrl o2) { | |||
if (!o1.isExternal() && o2.isExternal()) { | |||
// prefer Gitblit over external | |||
return -1; | |||
} else if (o1.isExternal() && !o2.isExternal()) { | |||
// prefer Gitblit over external | |||
return 1; | |||
} else if (o1.isExternal() && o2.isExternal()) { | |||
// sort by Transport ordinal | |||
return o1.transport.compareTo(o2.transport); | |||
} else if (o1.permission.exceeds(o2.permission)) { | |||
// prefer highest permission | |||
return -1; | |||
} else if (o2.permission.exceeds(o1.permission)) { | |||
// prefer highest permission | |||
return 1; | |||
} | |||
// prefer more secure transports | |||
return o1.transport.compareTo(o2.transport); | |||
} | |||
}); | |||
// consider the user's transport preference | |||
RepositoryUrl preferredUrl = null; | |||
Transport preferredTransport = user.getPreferences().getTransport(); | |||
if (preferredTransport != null) { | |||
Iterator<RepositoryUrl> itr = list.iterator(); | |||
while (itr.hasNext()) { | |||
RepositoryUrl url = itr.next(); | |||
if (url.transport.equals(preferredTransport)) { | |||
itr.remove(); | |||
preferredUrl = url; | |||
break; | |||
} | |||
} | |||
} | |||
if (preferredUrl != null) { | |||
list.add(0, preferredUrl); | |||
} | |||
return list; | |||
} | |||
/** | |||
* Detect renames and reindex as appropriate. | |||
*/ | |||
@Override | |||
public void updateRepositoryModel(String repositoryName, RepositoryModel repository, | |||
boolean isCreate) throws GitBlitException { | |||
RepositoryModel oldModel = null; | |||
boolean isRename = !isCreate && !repositoryName.equalsIgnoreCase(repository.name); | |||
if (isRename) { | |||
oldModel = repositoryManager.getRepositoryModel(repositoryName); | |||
} | |||
super.updateRepositoryModel(repositoryName, repository, isCreate); | |||
if (isRename && ticketService != null) { | |||
ticketService.rename(oldModel, repository); | |||
} | |||
} | |||
/** | |||
* Delete the user and all associated public ssh keys. | |||
*/ | |||
@Override | |||
public boolean deleteUser(String username) { | |||
UserModel user = userManager.getUserModel(username); | |||
return deleteUserModel(user); | |||
} | |||
@Override | |||
public boolean deleteUserModel(UserModel model) { | |||
boolean success = userManager.deleteUserModel(model); | |||
if (success) { | |||
getPublicKeyManager().removeAllKeys(model.username); | |||
} | |||
return success; | |||
} | |||
/** | |||
* Delete the repository and all associated tickets. | |||
*/ | |||
@Override | |||
public boolean deleteRepository(String repositoryName) { | |||
RepositoryModel repository = repositoryManager.getRepositoryModel(repositoryName); | |||
return deleteRepositoryModel(repository); | |||
} | |||
@Override | |||
public boolean deleteRepositoryModel(RepositoryModel model) { | |||
boolean success = repositoryManager.deleteRepositoryModel(model); | |||
if (success && ticketService != null) { | |||
ticketService.deleteAll(model); | |||
} | |||
return success; | |||
} | |||
/** | |||
* Returns the configured ticket service. | |||
* | |||
* @return a ticket service | |||
*/ | |||
@Override | |||
public ITicketService getTicketService() { | |||
return ticketService; | |||
} | |||
protected void configureTicketService() { | |||
String clazz = settings.getString(Keys.tickets.service, NullTicketService.class.getName()); | |||
if (StringUtils.isEmpty(clazz)) { | |||
clazz = NullTicketService.class.getName(); | |||
} | |||
try { | |||
Class<? extends ITicketService> serviceClass = (Class<? extends ITicketService>) Class.forName(clazz); | |||
ticketService = injector.get(serviceClass).start(); | |||
if (ticketService instanceof NullTicketService) { | |||
logger.warn("No ticket service configured."); | |||
} else if (ticketService.isReady()) { | |||
logger.info("{} is ready.", ticketService); | |||
} else { | |||
logger.warn("{} is disabled.", ticketService); | |||
} | |||
} catch (Exception e) { | |||
logger.error("failed to create ticket service " + clazz, e); | |||
ticketService = injector.get(NullTicketService.class).start(); | |||
} | |||
} | |||
/** | |||
* A nested Dagger graph is used for constructor dependency injection of | |||
* complex classes. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
@Module( | |||
library = true, | |||
injects = { | |||
IStoredSettings.class, | |||
// core managers | |||
IRuntimeManager.class, | |||
IPluginManager.class, | |||
INotificationManager.class, | |||
IUserManager.class, | |||
IAuthenticationManager.class, | |||
IRepositoryManager.class, | |||
IProjectManager.class, | |||
IFederationManager.class, | |||
// the monolithic manager | |||
IGitblit.class, | |||
// ticket services | |||
NullTicketService.class, | |||
FileTicketService.class, | |||
BranchTicketService.class, | |||
RedisTicketService.class | |||
} | |||
) | |||
class GitBlitModule { | |||
@Provides @Singleton IStoredSettings provideSettings() { | |||
return settings; | |||
} | |||
@Provides @Singleton IRuntimeManager provideRuntimeManager() { | |||
return runtimeManager; | |||
} | |||
@Provides @Singleton IPluginManager providePluginManager() { | |||
return pluginManager; | |||
} | |||
@Provides @Singleton INotificationManager provideNotificationManager() { | |||
return notificationManager; | |||
} | |||
@Provides @Singleton IUserManager provideUserManager() { | |||
return userManager; | |||
} | |||
@Provides @Singleton IAuthenticationManager provideAuthenticationManager() { | |||
return authenticationManager; | |||
} | |||
@Provides @Singleton IRepositoryManager provideRepositoryManager() { | |||
return repositoryManager; | |||
} | |||
@Provides @Singleton IProjectManager provideProjectManager() { | |||
return projectManager; | |||
} | |||
@Provides @Singleton IFederationManager provideFederationManager() { | |||
return federationManager; | |||
} | |||
@Provides @Singleton IGitblit provideGitblit() { | |||
return GitBlit.this; | |||
} | |||
@Provides @Singleton NullTicketService provideNullTicketService() { | |||
return new NullTicketService( | |||
runtimeManager, | |||
pluginManager, | |||
notificationManager, | |||
userManager, | |||
repositoryManager); | |||
} | |||
@Provides @Singleton FileTicketService provideFileTicketService() { | |||
return new FileTicketService( | |||
runtimeManager, | |||
pluginManager, | |||
notificationManager, | |||
userManager, | |||
repositoryManager); | |||
} | |||
@Provides @Singleton BranchTicketService provideBranchTicketService() { | |||
return new BranchTicketService( | |||
runtimeManager, | |||
pluginManager, | |||
notificationManager, | |||
userManager, | |||
repositoryManager); | |||
} | |||
@Provides @Singleton RedisTicketService provideRedisTicketService() { | |||
return new RedisTicketService( | |||
runtimeManager, | |||
pluginManager, | |||
notificationManager, | |||
userManager, | |||
repositoryManager); | |||
} | |||
} | |||
} |
@@ -1,67 +0,0 @@ | |||
/* | |||
* Copyright 2013 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.dagger; | |||
import javax.servlet.ServletContext; | |||
import javax.servlet.ServletContextEvent; | |||
import javax.servlet.ServletContextListener; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import dagger.ObjectGraph; | |||
/** | |||
* Dagger servlet context listener is a context listener that uses Dagger to | |||
* instantiate and inject servlets, filters, and anything else you might want. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
public abstract class DaggerContext implements ServletContextListener { | |||
public static final String INJECTOR_NAME = ObjectGraph.class.getName(); | |||
protected final Logger logger = LoggerFactory.getLogger(getClass()); | |||
protected abstract Object [] getModules(); | |||
protected abstract void destroyContext(ServletContext context); | |||
protected ObjectGraph getInjector(ServletContext context) { | |||
Object o = context.getAttribute(INJECTOR_NAME); | |||
if (o == null) { | |||
logger.debug("instantiating Dagger modules"); | |||
Object [] modules = getModules(); | |||
logger.debug("getting Dagger injector"); | |||
try { | |||
o = ObjectGraph.create(modules); | |||
logger.debug("setting Dagger injector into {} attribute", INJECTOR_NAME); | |||
context.setAttribute(INJECTOR_NAME, o); | |||
} catch (Throwable t) { | |||
logger.error("an error occurred creating the Dagger injector", t); | |||
} | |||
} | |||
return (ObjectGraph) o; | |||
} | |||
@Override | |||
public final void contextDestroyed(ServletContextEvent contextEvent) { | |||
ServletContext context = contextEvent.getServletContext(); | |||
context.removeAttribute(INJECTOR_NAME); | |||
destroyContext(context); | |||
} | |||
} |
@@ -1,47 +0,0 @@ | |||
/* | |||
* Copyright 2013 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.dagger; | |||
import javax.servlet.Filter; | |||
import javax.servlet.FilterConfig; | |||
import javax.servlet.ServletContext; | |||
import javax.servlet.ServletException; | |||
import dagger.ObjectGraph; | |||
/** | |||
* Uses Dagger to manually inject dependencies into a servlet filter. | |||
* This class is useful for servlet containers that offer CDI and are | |||
* confused by Dagger. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
public abstract class DaggerFilter implements Filter { | |||
@Override | |||
public final void init(FilterConfig filterConfig) throws ServletException { | |||
ServletContext context = filterConfig.getServletContext(); | |||
ObjectGraph objectGraph = (ObjectGraph) context.getAttribute(DaggerContext.INJECTOR_NAME); | |||
inject(objectGraph, filterConfig); | |||
} | |||
protected abstract void inject(ObjectGraph dagger, FilterConfig filterConfig) throws ServletException; | |||
@Override | |||
public void destroy() { | |||
} | |||
} |
@@ -1,44 +0,0 @@ | |||
/* | |||
* Copyright 2013 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.dagger; | |||
import javax.servlet.ServletContext; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.http.HttpServlet; | |||
import dagger.ObjectGraph; | |||
/** | |||
* Uses Dagger to manually inject dependencies into a servlet. | |||
* This class is useful for servlet containers that offer CDI and are | |||
* confused by Dagger. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
public abstract class DaggerServlet extends HttpServlet { | |||
private static final long serialVersionUID = 1L; | |||
@Override | |||
public final void init() throws ServletException { | |||
ServletContext context = getServletContext(); | |||
ObjectGraph objectGraph = (ObjectGraph) context.getAttribute(DaggerContext.INJECTOR_NAME); | |||
inject(objectGraph); | |||
} | |||
protected abstract void inject(ObjectGraph dagger); | |||
} |
@@ -1,45 +0,0 @@ | |||
/* | |||
* Copyright 2013 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.dagger; | |||
import javax.servlet.FilterConfig; | |||
import javax.servlet.ServletContext; | |||
import javax.servlet.ServletException; | |||
import org.apache.wicket.protocol.http.WicketFilter; | |||
import dagger.ObjectGraph; | |||
/** | |||
* Uses Dagger to manually inject dependencies into a Wicket filter. | |||
* This class is useful for servlet containers that offer CDI and are | |||
* confused by Dagger. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
public abstract class DaggerWicketFilter extends WicketFilter { | |||
@Override | |||
public final void init(FilterConfig filterConfig) throws ServletException { | |||
ServletContext context = filterConfig.getServletContext(); | |||
ObjectGraph objectGraph = (ObjectGraph) context.getAttribute(DaggerContext.INJECTOR_NAME); | |||
inject(objectGraph); | |||
super.init(filterConfig); | |||
} | |||
protected abstract void inject(ObjectGraph dagger); | |||
} |
@@ -0,0 +1,79 @@ | |||
/* | |||
* 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.guice; | |||
import com.gitblit.FileSettings; | |||
import com.gitblit.GitBlit; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.manager.AuthenticationManager; | |||
import com.gitblit.manager.FederationManager; | |||
import com.gitblit.manager.IAuthenticationManager; | |||
import com.gitblit.manager.IFederationManager; | |||
import com.gitblit.manager.IGitblit; | |||
import com.gitblit.manager.INotificationManager; | |||
import com.gitblit.manager.IPluginManager; | |||
import com.gitblit.manager.IProjectManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.manager.IServicesManager; | |||
import com.gitblit.manager.IUserManager; | |||
import com.gitblit.manager.NotificationManager; | |||
import com.gitblit.manager.PluginManager; | |||
import com.gitblit.manager.ProjectManager; | |||
import com.gitblit.manager.RepositoryManager; | |||
import com.gitblit.manager.RuntimeManager; | |||
import com.gitblit.manager.ServicesManager; | |||
import com.gitblit.manager.UserManager; | |||
import com.gitblit.tickets.ITicketService; | |||
import com.gitblit.transport.ssh.IPublicKeyManager; | |||
import com.gitblit.utils.WorkQueue; | |||
import com.google.inject.AbstractModule; | |||
/** | |||
* CoreModule references all the core business objects. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
public class CoreModule extends AbstractModule { | |||
@Override | |||
protected void configure() { | |||
bind(IStoredSettings.class).toInstance(new FileSettings()); | |||
// bind complex providers | |||
bind(IPublicKeyManager.class).toProvider(IPublicKeyManagerProvider.class); | |||
bind(ITicketService.class).toProvider(ITicketServiceProvider.class); | |||
bind(WorkQueue.class).toProvider(WorkQueueProvider.class); | |||
// core managers | |||
bind(IRuntimeManager.class).to(RuntimeManager.class); | |||
bind(IPluginManager.class).to(PluginManager.class); | |||
bind(INotificationManager.class).to(NotificationManager.class); | |||
bind(IUserManager.class).to(UserManager.class); | |||
bind(IAuthenticationManager.class).to(AuthenticationManager.class); | |||
bind(IRepositoryManager.class).to(RepositoryManager.class); | |||
bind(IProjectManager.class).to(ProjectManager.class); | |||
bind(IFederationManager.class).to(FederationManager.class); | |||
// the monolithic manager | |||
bind(IGitblit.class).to(GitBlit.class); | |||
// manager for long-running daemons and services | |||
bind(IServicesManager.class).to(ServicesManager.class); | |||
} | |||
} |
@@ -0,0 +1,72 @@ | |||
/* | |||
* 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.guice; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.transport.ssh.FileKeyManager; | |||
import com.gitblit.transport.ssh.IPublicKeyManager; | |||
import com.gitblit.transport.ssh.NullKeyManager; | |||
import com.gitblit.utils.StringUtils; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Provider; | |||
import com.google.inject.Singleton; | |||
/** | |||
* Provides a lazily-instantiated IPublicKeyManager configured from IStoredSettings. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class IPublicKeyManagerProvider implements Provider<IPublicKeyManager> { | |||
private final Logger logger = LoggerFactory.getLogger(getClass()); | |||
private final IRuntimeManager runtimeManager; | |||
private volatile IPublicKeyManager manager; | |||
@Inject | |||
public IPublicKeyManagerProvider(IRuntimeManager runtimeManager) { | |||
this.runtimeManager = runtimeManager; | |||
} | |||
@Override | |||
public synchronized IPublicKeyManager get() { | |||
if (manager != null) { | |||
return manager; | |||
} | |||
IStoredSettings settings = runtimeManager.getSettings(); | |||
String clazz = settings.getString(Keys.git.sshKeysManager, FileKeyManager.class.getName()); | |||
if (StringUtils.isEmpty(clazz)) { | |||
clazz = FileKeyManager.class.getName(); | |||
} | |||
try { | |||
Class<? extends IPublicKeyManager> mgrClass = (Class<? extends IPublicKeyManager>) Class.forName(clazz); | |||
manager = runtimeManager.getInjector().getInstance(mgrClass); | |||
} catch (Exception e) { | |||
logger.error("failed to create public key manager", e); | |||
manager = new NullKeyManager(); | |||
} | |||
return manager; | |||
} | |||
} |
@@ -0,0 +1,73 @@ | |||
/* | |||
* 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.guice; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.tickets.ITicketService; | |||
import com.gitblit.tickets.NullTicketService; | |||
import com.gitblit.utils.StringUtils; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Provider; | |||
import com.google.inject.Singleton; | |||
/** | |||
* Provides a lazily-instantiated ITicketService configured from IStoredSettings. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class ITicketServiceProvider implements Provider<ITicketService> { | |||
private final Logger logger = LoggerFactory.getLogger(getClass()); | |||
private final IRuntimeManager runtimeManager; | |||
private volatile ITicketService service; | |||
@Inject | |||
public ITicketServiceProvider(IRuntimeManager runtimeManager) { | |||
this.runtimeManager = runtimeManager; | |||
} | |||
@Override | |||
public synchronized ITicketService get() { | |||
if (service != null) { | |||
return service; | |||
} | |||
IStoredSettings settings = runtimeManager.getSettings(); | |||
String clazz = settings.getString(Keys.tickets.service, NullTicketService.class.getName()); | |||
if (StringUtils.isEmpty(clazz)) { | |||
clazz = NullTicketService.class.getName(); | |||
} | |||
try { | |||
Class<? extends ITicketService> serviceClass = (Class<? extends ITicketService>) Class.forName(clazz); | |||
service = runtimeManager.getInjector().getInstance(serviceClass); | |||
} catch (Exception e) { | |||
logger.error("failed to create ticket service", e); | |||
service = runtimeManager.getInjector().getInstance(NullTicketService.class); | |||
} | |||
return service; | |||
} | |||
} |
@@ -0,0 +1,105 @@ | |||
/* | |||
* 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.guice; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import com.gitblit.Constants; | |||
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.wicket.GitblitWicketFilter; | |||
import com.google.common.base.Joiner; | |||
import com.google.inject.servlet.ServletModule; | |||
/** | |||
* Defines all the web servlets & filters. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
public class WebModule extends ServletModule { | |||
final static String ALL = "/*"; | |||
@Override | |||
protected void configureServlets() { | |||
// servlets | |||
serve(fuzzy(Constants.R_PATH), fuzzy(Constants.GIT_PATH)).with(GitServlet.class); | |||
serve(fuzzy(Constants.RAW_PATH)).with(RawServlet.class); | |||
serve(fuzzy(Constants.PAGES)).with(PagesServlet.class); | |||
serve(fuzzy(Constants.RPC_PATH)).with(RpcServlet.class); | |||
serve(fuzzy(Constants.ZIP_PATH)).with(DownloadZipServlet.class); | |||
serve(fuzzy(Constants.SYNDICATION_PATH)).with(SyndicationServlet.class); | |||
serve(fuzzy(Constants.FEDERATION_PATH)).with(FederationServlet.class); | |||
serve(fuzzy(Constants.SPARKLESHARE_INVITE_PATH)).with(SparkleShareInviteServlet.class); | |||
serve(fuzzy(Constants.BRANCH_GRAPH_PATH)).with(BranchGraphServlet.class); | |||
serve(Constants.PT_PATH).with(PtServlet.class); | |||
serve("/robots.txt").with(RobotsTxtServlet.class); | |||
serve("/logo.png").with(LogoServlet.class); | |||
// global filters | |||
filter(ALL).through(ProxyFilter.class); | |||
filter(ALL).through(EnforceAuthenticationFilter.class); | |||
// security filters | |||
filter(fuzzy(Constants.R_PATH), fuzzy(Constants.GIT_PATH)).through(GitFilter.class); | |||
filter(fuzzy(Constants.RAW_PATH)).through(RawFilter.class); | |||
filter(fuzzy(Constants.PAGES)).through(PagesFilter.class); | |||
filter(fuzzy(Constants.RPC_PATH)).through(RpcFilter.class); | |||
filter(fuzzy(Constants.ZIP_PATH)).through(DownloadZipFilter.class); | |||
filter(fuzzy(Constants.SYNDICATION_PATH)).through(SyndicationFilter.class); | |||
// Wicket | |||
String toIgnore = Joiner.on(",").join(Constants.R_PATH, Constants.GIT_PATH, Constants.RAW_PATH, | |||
Constants.PAGES, Constants.RPC_PATH, Constants.ZIP_PATH, Constants.SYNDICATION_PATH, | |||
Constants.FEDERATION_PATH, Constants.SPARKLESHARE_INVITE_PATH, Constants.BRANCH_GRAPH_PATH, | |||
Constants.PT_PATH, "/robots.txt", "/logo.png"); | |||
Map<String, String> params = new HashMap<String, String>(); | |||
params.put(GitblitWicketFilter.FILTER_MAPPING_PARAM, ALL); | |||
params.put(GitblitWicketFilter.IGNORE_PATHS_PARAM, toIgnore); | |||
filter(ALL).through(GitblitWicketFilter.class, params); | |||
} | |||
private String fuzzy(String path) { | |||
if (path.endsWith(ALL)) { | |||
return path; | |||
} else if (path.endsWith("/")) { | |||
return path + "*"; | |||
} | |||
return path + ALL; | |||
} | |||
} |
@@ -0,0 +1,57 @@ | |||
/* | |||
* 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.guice; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.utils.IdGenerator; | |||
import com.gitblit.utils.WorkQueue; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Provider; | |||
import com.google.inject.Singleton; | |||
/** | |||
* Provides a lazily-instantiated WorkQueue configured from IStoredSettings. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class WorkQueueProvider implements Provider<WorkQueue> { | |||
private final IRuntimeManager runtimeManager; | |||
private volatile WorkQueue workQueue; | |||
@Inject | |||
public WorkQueueProvider(IRuntimeManager runtimeManager) { | |||
this.runtimeManager = runtimeManager; | |||
} | |||
@Override | |||
public synchronized WorkQueue get() { | |||
if (workQueue != null) { | |||
return workQueue; | |||
} | |||
IStoredSettings settings = runtimeManager.getSettings(); | |||
int defaultThreadPoolSize = settings.getInteger(Keys.execution.defaultThreadPoolSize, 1); | |||
IdGenerator idGenerator = new IdGenerator(); | |||
workQueue = new WorkQueue(idGenerator, defaultThreadPoolSize); | |||
return workQueue; | |||
} | |||
} |
@@ -53,6 +53,8 @@ import com.gitblit.utils.HttpUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import com.gitblit.utils.X509Utils.X509Metadata; | |||
import com.gitblit.wicket.GitBlitWebSession; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
/** | |||
* The authentication manager handles user login & logout. | |||
@@ -60,6 +62,7 @@ import com.gitblit.wicket.GitBlitWebSession; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class AuthenticationManager implements IAuthenticationManager { | |||
private final Logger logger = LoggerFactory.getLogger(getClass()); | |||
@@ -76,6 +79,7 @@ public class AuthenticationManager implements IAuthenticationManager { | |||
private final Map<String, String> legacyRedirects; | |||
@Inject | |||
public AuthenticationManager( | |||
IRuntimeManager runtimeManager, | |||
IUserManager userManager) { |
@@ -45,6 +45,8 @@ import com.gitblit.utils.Base64; | |||
import com.gitblit.utils.FederationUtils; | |||
import com.gitblit.utils.JsonUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
/** | |||
* Federation manager controls all aspects of handling federation sets, tokens, | |||
@@ -53,6 +55,7 @@ import com.gitblit.utils.StringUtils; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class FederationManager implements IFederationManager { | |||
private final Logger logger = LoggerFactory.getLogger(getClass()); | |||
@@ -70,6 +73,7 @@ public class FederationManager implements IFederationManager { | |||
private final IRepositoryManager repositoryManager; | |||
@Inject | |||
public FederationManager( | |||
IRuntimeManager runtimeManager, | |||
INotificationManager notificationManager, |
@@ -49,12 +49,10 @@ import ro.fortsoft.pf4j.Version; | |||
import com.gitblit.Constants; | |||
import com.gitblit.Constants.AccessPermission; | |||
import com.gitblit.Constants.AccessRestrictionType; | |||
import com.gitblit.Constants.FederationRequest; | |||
import com.gitblit.Constants.FederationToken; | |||
import com.gitblit.GitBlitException; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.models.FederationModel; | |||
import com.gitblit.models.FederationProposal; | |||
import com.gitblit.models.FederationSet; | |||
@@ -68,7 +66,6 @@ import com.gitblit.models.PluginRegistry.PluginRelease; | |||
import com.gitblit.models.ProjectModel; | |||
import com.gitblit.models.RegistrantAccessPermission; | |||
import com.gitblit.models.RepositoryModel; | |||
import com.gitblit.models.RepositoryUrl; | |||
import com.gitblit.models.SearchResult; | |||
import com.gitblit.models.ServerSettings; | |||
import com.gitblit.models.ServerStatus; | |||
@@ -79,7 +76,6 @@ import com.gitblit.tickets.ITicketService; | |||
import com.gitblit.transport.ssh.IPublicKeyManager; | |||
import com.gitblit.transport.ssh.SshKey; | |||
import com.gitblit.utils.ArrayUtils; | |||
import com.gitblit.utils.HttpUtils; | |||
import com.gitblit.utils.JsonUtils; | |||
import com.gitblit.utils.ObjectCache; | |||
import com.gitblit.utils.StringUtils; | |||
@@ -87,6 +83,10 @@ import com.google.gson.Gson; | |||
import com.google.gson.JsonIOException; | |||
import com.google.gson.JsonSyntaxException; | |||
import com.google.gson.reflect.TypeToken; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Injector; | |||
import com.google.inject.Singleton; | |||
import com.google.inject.Provider; | |||
/** | |||
* GitblitManager is an aggregate interface delegate. It implements all the manager | |||
@@ -100,12 +100,17 @@ import com.google.gson.reflect.TypeToken; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class GitblitManager implements IGitblit { | |||
protected final Logger logger = LoggerFactory.getLogger(getClass()); | |||
protected final ObjectCache<Collection<GitClientApplication>> clientApplications = new ObjectCache<Collection<GitClientApplication>>(); | |||
protected final Provider<IPublicKeyManager> publicKeyManagerProvider; | |||
protected final Provider<ITicketService> ticketServiceProvider; | |||
protected final IStoredSettings settings; | |||
protected final IRuntimeManager runtimeManager; | |||
@@ -118,32 +123,34 @@ public class GitblitManager implements IGitblit { | |||
protected final IAuthenticationManager authenticationManager; | |||
protected final IPublicKeyManager publicKeyManager; | |||
protected final IRepositoryManager repositoryManager; | |||
protected final IProjectManager projectManager; | |||
protected final IFederationManager federationManager; | |||
@Inject | |||
public GitblitManager( | |||
Provider<IPublicKeyManager> publicKeyManagerProvider, | |||
Provider<ITicketService> ticketServiceProvider, | |||
IRuntimeManager runtimeManager, | |||
IPluginManager pluginManager, | |||
INotificationManager notificationManager, | |||
IUserManager userManager, | |||
IAuthenticationManager authenticationManager, | |||
IPublicKeyManager publicKeyManager, | |||
IRepositoryManager repositoryManager, | |||
IProjectManager projectManager, | |||
IFederationManager federationManager) { | |||
this.publicKeyManagerProvider = publicKeyManagerProvider; | |||
this.ticketServiceProvider = ticketServiceProvider; | |||
this.settings = runtimeManager.getSettings(); | |||
this.runtimeManager = runtimeManager; | |||
this.pluginManager = pluginManager; | |||
this.notificationManager = notificationManager; | |||
this.userManager = userManager; | |||
this.authenticationManager = authenticationManager; | |||
this.publicKeyManager = publicKeyManager; | |||
this.repositoryManager = repositoryManager; | |||
this.projectManager = projectManager; | |||
this.federationManager = federationManager; | |||
@@ -349,66 +356,6 @@ public class GitblitManager implements IGitblit { | |||
} | |||
} | |||
/** | |||
* Returns a list of repository URLs and the user access permission. | |||
* | |||
* @param request | |||
* @param user | |||
* @param repository | |||
* @return a list of repository urls | |||
*/ | |||
@Override | |||
public List<RepositoryUrl> getRepositoryUrls(HttpServletRequest request, UserModel user, RepositoryModel repository) { | |||
if (user == null) { | |||
user = UserModel.ANONYMOUS; | |||
} | |||
String username = StringUtils.encodeUsername(UserModel.ANONYMOUS.equals(user) ? "" : user.username); | |||
List<RepositoryUrl> list = new ArrayList<RepositoryUrl>(); | |||
// http/https url | |||
if (settings.getBoolean(Keys.git.enableGitServlet, true)) { | |||
AccessPermission permission = user.getRepositoryPermission(repository).permission; | |||
if (permission.exceeds(AccessPermission.NONE)) { | |||
list.add(new RepositoryUrl(getRepositoryUrl(request, username, repository), permission)); | |||
} | |||
} | |||
// add all other urls | |||
// {0} = repository | |||
// {1} = username | |||
for (String url : settings.getStrings(Keys.web.otherUrls)) { | |||
if (url.contains("{1}")) { | |||
// external url requires username, only add url IF we have one | |||
if (!StringUtils.isEmpty(username)) { | |||
list.add(new RepositoryUrl(MessageFormat.format(url, repository.name, username), null)); | |||
} | |||
} else { | |||
// external url does not require username | |||
list.add(new RepositoryUrl(MessageFormat.format(url, repository.name), null)); | |||
} | |||
} | |||
return list; | |||
} | |||
protected String getRepositoryUrl(HttpServletRequest request, String username, RepositoryModel repository) { | |||
String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null); | |||
if (StringUtils.isEmpty(gitblitUrl)) { | |||
gitblitUrl = HttpUtils.getGitblitURL(request); | |||
} | |||
StringBuilder sb = new StringBuilder(); | |||
sb.append(gitblitUrl); | |||
sb.append(Constants.R_PATH); | |||
sb.append(repository.name); | |||
// inject username into repository url if authentication is required | |||
if (repository.accessRestriction.exceeds(AccessRestrictionType.NONE) | |||
&& !StringUtils.isEmpty(username)) { | |||
sb.insert(sb.indexOf("://") + 3, username + "@"); | |||
} | |||
return sb.toString(); | |||
} | |||
/** | |||
* Returns the list of custom client applications to be used for the | |||
* repository url panel; | |||
@@ -535,18 +482,14 @@ public class GitblitManager implements IGitblit { | |||
} | |||
} | |||
/** | |||
* Throws an exception if trying to get a ticket service. | |||
* | |||
*/ | |||
@Override | |||
public ITicketService getTicketService() { | |||
throw new RuntimeException("This class does not have a ticket service!"); | |||
return ticketServiceProvider.get(); | |||
} | |||
@Override | |||
public IPublicKeyManager getPublicKeyManager() { | |||
return publicKeyManager; | |||
return publicKeyManagerProvider.get(); | |||
} | |||
/* | |||
@@ -596,26 +539,6 @@ public class GitblitManager implements IGitblit { | |||
return runtimeManager.getSettingsModel(); | |||
} | |||
@Override | |||
public boolean isServingRepositories() { | |||
return runtimeManager.isServingRepositories(); | |||
} | |||
@Override | |||
public boolean isServingHTTP() { | |||
return runtimeManager.isServingHTTP(); | |||
} | |||
@Override | |||
public boolean isServingGIT() { | |||
return runtimeManager.isServingGIT(); | |||
} | |||
@Override | |||
public boolean isServingSSH() { | |||
return runtimeManager.isServingSSH(); | |||
} | |||
@Override | |||
public TimeZone getTimezone() { | |||
return runtimeManager.getTimezone(); | |||
@@ -656,6 +579,11 @@ public class GitblitManager implements IGitblit { | |||
return runtimeManager.getStatus(); | |||
} | |||
@Override | |||
public Injector getInjector() { | |||
return runtimeManager.getInjector(); | |||
} | |||
/* | |||
* NOTIFICATION MANAGER | |||
*/ | |||
@@ -780,11 +708,6 @@ public class GitblitManager implements IGitblit { | |||
return userManager.getAllUsers(); | |||
} | |||
@Override | |||
public boolean deleteUser(String username) { | |||
return userManager.deleteUser(username); | |||
} | |||
@Override | |||
public UserModel getUserModel(String username) { | |||
return userManager.getUserModel(username); | |||
@@ -825,9 +748,23 @@ public class GitblitManager implements IGitblit { | |||
return userManager.updateUserModel(username, model); | |||
} | |||
@Override | |||
public boolean deleteUser(String username) { | |||
// delegate to deleteUserModel() to delete public ssh keys | |||
UserModel user = userManager.getUserModel(username); | |||
return deleteUserModel(user); | |||
} | |||
/** | |||
* Delete the user and all associated public ssh keys. | |||
*/ | |||
@Override | |||
public boolean deleteUserModel(UserModel model) { | |||
return userManager.deleteUserModel(model); | |||
boolean success = userManager.deleteUserModel(model); | |||
if (success) { | |||
getPublicKeyManager().removeAllKeys(model.username); | |||
} | |||
return success; | |||
} | |||
@Override | |||
@@ -1023,10 +960,23 @@ public class GitblitManager implements IGitblit { | |||
return repositoryManager.getRepositoryDefaultMetrics(model, repository); | |||
} | |||
/** | |||
* Detect renames and reindex as appropriate. | |||
*/ | |||
@Override | |||
public void updateRepositoryModel(String repositoryName, RepositoryModel repository, | |||
boolean isCreate) throws GitBlitException { | |||
RepositoryModel oldModel = null; | |||
boolean isRename = !isCreate && !repositoryName.equalsIgnoreCase(repository.name); | |||
if (isRename) { | |||
oldModel = repositoryManager.getRepositoryModel(repositoryName); | |||
} | |||
repositoryManager.updateRepositoryModel(repositoryName, repository, isCreate); | |||
if (isRename && ticketServiceProvider.get() != null) { | |||
ticketServiceProvider.get().rename(oldModel, repository); | |||
} | |||
} | |||
@Override | |||
@@ -1039,14 +989,23 @@ public class GitblitManager implements IGitblit { | |||
return repositoryManager.canDelete(model); | |||
} | |||
/** | |||
* Delete the repository and all associated tickets. | |||
*/ | |||
@Override | |||
public boolean deleteRepositoryModel(RepositoryModel model) { | |||
return repositoryManager.deleteRepositoryModel(model); | |||
boolean success = repositoryManager.deleteRepositoryModel(model); | |||
if (success && ticketServiceProvider.get() != null) { | |||
ticketServiceProvider.get().deleteAll(model); | |||
} | |||
return success; | |||
} | |||
@Override | |||
public boolean deleteRepository(String repositoryName) { | |||
return repositoryManager.deleteRepository(repositoryName); | |||
// delegate to deleteRepositoryModel() to destroy indexed tickets | |||
RepositoryModel repository = repositoryManager.getRepositoryModel(repositoryName); | |||
return deleteRepositoryModel(repository); | |||
} | |||
@Override |
@@ -16,14 +16,10 @@ | |||
package com.gitblit.manager; | |||
import java.util.Collection; | |||
import java.util.List; | |||
import javax.servlet.http.HttpServletRequest; | |||
import com.gitblit.GitBlitException; | |||
import com.gitblit.models.GitClientApplication; | |||
import com.gitblit.models.RepositoryModel; | |||
import com.gitblit.models.RepositoryUrl; | |||
import com.gitblit.models.TeamModel; | |||
import com.gitblit.models.UserModel; | |||
import com.gitblit.tickets.ITicketService; | |||
@@ -39,17 +35,6 @@ public interface IGitblit extends IManager, | |||
IProjectManager, | |||
IFederationManager { | |||
/** | |||
* Returns a list of repository URLs and the user access permission. | |||
* | |||
* @param request | |||
* @param user | |||
* @param repository | |||
* @return a list of repository urls | |||
* @since 1.4.0 | |||
*/ | |||
List<RepositoryUrl> getRepositoryUrls(HttpServletRequest request, UserModel user, RepositoryModel repository); | |||
/** | |||
* Creates a complete user object. | |||
* |
@@ -24,9 +24,12 @@ import java.util.TimeZone; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.models.ServerSettings; | |||
import com.gitblit.models.ServerStatus; | |||
import com.google.inject.Injector; | |||
public interface IRuntimeManager extends IManager { | |||
Injector getInjector(); | |||
void setBaseFolder(File folder); | |||
File getBaseFolder(); | |||
@@ -47,42 +50,6 @@ public interface IRuntimeManager extends IManager { | |||
*/ | |||
Locale getLocale(); | |||
/** | |||
* Determine if this Gitblit instance is actively serving git repositories | |||
* or if it is merely a repository viewer. | |||
* | |||
* @return true if Gitblit is serving repositories | |||
* @since 1.4.0 | |||
*/ | |||
boolean isServingRepositories(); | |||
/** | |||
* Determine if this Gitblit instance is actively serving git repositories | |||
* over HTTP. | |||
* | |||
* @return true if Gitblit is serving repositories over HTTP | |||
* @since 1.6.0 | |||
*/ | |||
boolean isServingHTTP(); | |||
/** | |||
* Determine if this Gitblit instance is actively serving git repositories | |||
* over the GIT Daemon protocol. | |||
* | |||
* @return true if Gitblit is serving repositories over the GIT Daemon protocol | |||
* @since 1.6.0 | |||
*/ | |||
boolean isServingGIT(); | |||
/** | |||
* Determine if this Gitblit instance is actively serving git repositories | |||
* over the SSH protocol. | |||
* | |||
* @return true if Gitblit is serving repositories over the SSH protocol | |||
* @since 1.6.0 | |||
*/ | |||
boolean isServingSSH(); | |||
/** | |||
* Determine if this Gitblit instance is running in debug mode | |||
* |
@@ -0,0 +1,75 @@ | |||
/* | |||
* 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.manager; | |||
import java.util.List; | |||
import javax.servlet.http.HttpServletRequest; | |||
import com.gitblit.models.RepositoryModel; | |||
import com.gitblit.models.RepositoryUrl; | |||
import com.gitblit.models.UserModel; | |||
public interface IServicesManager extends IManager { | |||
/** | |||
* Determine if this Gitblit instance is actively serving git repositories | |||
* or if it is merely a repository viewer. | |||
* | |||
* @return true if Gitblit is serving repositories | |||
* @since 1.7.0 | |||
*/ | |||
boolean isServingRepositories(); | |||
/** | |||
* Determine if this Gitblit instance is actively serving git repositories | |||
* over HTTP. | |||
* | |||
* @return true if Gitblit is serving repositories over HTTP | |||
* @since 1.7.0 | |||
*/ | |||
boolean isServingHTTP(); | |||
/** | |||
* Determine if this Gitblit instance is actively serving git repositories | |||
* over the GIT Daemon protocol. | |||
* | |||
* @return true if Gitblit is serving repositories over the GIT Daemon protocol | |||
* @since 1.7.0 | |||
*/ | |||
boolean isServingGIT(); | |||
/** | |||
* Determine if this Gitblit instance is actively serving git repositories | |||
* over the SSH protocol. | |||
* | |||
* @return true if Gitblit is serving repositories over the SSH protocol | |||
* @since 1.7.0 | |||
*/ | |||
boolean isServingSSH(); | |||
/** | |||
* Returns a list of repository URLs and the user access permission. | |||
* | |||
* @param request | |||
* @param user | |||
* @param repository | |||
* @return a list of repository urls | |||
* @since 1.7.0 | |||
*/ | |||
List<RepositoryUrl> getRepositoryUrls(HttpServletRequest request, UserModel user, RepositoryModel repository); | |||
} |
@@ -29,6 +29,8 @@ import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.models.Mailing; | |||
import com.gitblit.service.MailService; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
/** | |||
* The notification manager dispatches notifications. Currently, email is the | |||
@@ -38,6 +40,7 @@ import com.gitblit.service.MailService; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class NotificationManager implements INotificationManager { | |||
private final Logger logger = LoggerFactory.getLogger(getClass()); | |||
@@ -48,6 +51,7 @@ public class NotificationManager implements INotificationManager { | |||
private final MailService mailService; | |||
@Inject | |||
public NotificationManager(IStoredSettings settings) { | |||
this.settings = settings; | |||
this.mailService = new MailService(settings); |
@@ -37,7 +37,9 @@ import java.util.TreeMap; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import ro.fortsoft.pf4j.DefaultExtensionFinder; | |||
import ro.fortsoft.pf4j.DefaultPluginManager; | |||
import ro.fortsoft.pf4j.ExtensionFinder; | |||
import ro.fortsoft.pf4j.PluginClassLoader; | |||
import ro.fortsoft.pf4j.PluginState; | |||
import ro.fortsoft.pf4j.PluginStateEvent; | |||
@@ -58,6 +60,8 @@ import com.gitblit.utils.JsonUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import com.google.common.io.Files; | |||
import com.google.common.io.InputSupplier; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
/** | |||
* The plugin manager maintains the lifecycle of plugins. It is exposed as | |||
@@ -68,32 +72,23 @@ import com.google.common.io.InputSupplier; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class PluginManager implements IPluginManager, PluginStateListener { | |||
private final Logger logger = LoggerFactory.getLogger(getClass()); | |||
private final DefaultPluginManager pf4j; | |||
private final IRuntimeManager runtimeManager; | |||
private DefaultPluginManager pf4j; | |||
// timeout defaults of Maven 3.0.4 in seconds | |||
private int connectTimeout = 20; | |||
private int readTimeout = 12800; | |||
@Inject | |||
public PluginManager(IRuntimeManager runtimeManager) { | |||
File dir = runtimeManager.getFileOrFolder(Keys.plugins.folder, "${baseFolder}/plugins"); | |||
dir.mkdirs(); | |||
this.runtimeManager = runtimeManager; | |||
this.pf4j = new DefaultPluginManager(dir); | |||
try { | |||
Version systemVersion = Version.createVersion(Constants.getVersion()); | |||
pf4j.setSystemVersion(systemVersion); | |||
} catch (Exception e) { | |||
logger.error(null, e); | |||
} | |||
} | |||
@Override | |||
@@ -108,6 +103,42 @@ public class PluginManager implements IPluginManager, PluginStateListener { | |||
@Override | |||
public PluginManager start() { | |||
File dir = runtimeManager.getFileOrFolder(Keys.plugins.folder, "${baseFolder}/plugins"); | |||
dir.mkdirs(); | |||
pf4j = new DefaultPluginManager(dir) { | |||
@Override | |||
protected ExtensionFinder createExtensionFinder() { | |||
DefaultExtensionFinder extensionFinder = new DefaultExtensionFinder(this) { | |||
@Override | |||
protected ExtensionFactory createExtensionFactory() { | |||
return new ExtensionFactory() { | |||
@Override | |||
public Object create(Class<?> extensionType) { | |||
// instantiate && inject the extension | |||
logger.debug("Create instance for extension '{}'", extensionType.getName()); | |||
try { | |||
return runtimeManager.getInjector().getInstance(extensionType); | |||
} catch (Exception e) { | |||
logger.error(e.getMessage(), e); | |||
} | |||
return null; | |||
} | |||
}; | |||
} | |||
}; | |||
addPluginStateListener(extensionFinder); | |||
return extensionFinder; | |||
} | |||
}; | |||
try { | |||
Version systemVersion = Version.createVersion(Constants.getVersion()); | |||
pf4j.setSystemVersion(systemVersion); | |||
} catch (Exception e) { | |||
logger.error(null, e); | |||
} | |||
pf4j.loadPlugins(); | |||
logger.debug("Starting plugins"); | |||
pf4j.startPlugins(); |
@@ -41,6 +41,8 @@ import com.gitblit.utils.DeepCopier; | |||
import com.gitblit.utils.ModelUtils; | |||
import com.gitblit.utils.ObjectCache; | |||
import com.gitblit.utils.StringUtils; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
/** | |||
* Project manager handles project-related functions. | |||
@@ -48,6 +50,7 @@ import com.gitblit.utils.StringUtils; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class ProjectManager implements IProjectManager { | |||
private final Logger logger = LoggerFactory.getLogger(getClass()); | |||
@@ -68,6 +71,7 @@ public class ProjectManager implements IProjectManager { | |||
private FileBasedConfig projectConfigs; | |||
@Inject | |||
public ProjectManager( | |||
IRuntimeManager runtimeManager, | |||
IUserManager userManager, |
@@ -89,6 +89,8 @@ import com.gitblit.utils.ModelUtils; | |||
import com.gitblit.utils.ObjectCache; | |||
import com.gitblit.utils.StringUtils; | |||
import com.gitblit.utils.TimeUtils; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
/** | |||
* Repository manager creates, updates, deletes and caches git repositories. It | |||
@@ -97,6 +99,7 @@ import com.gitblit.utils.TimeUtils; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class RepositoryManager implements IRepositoryManager { | |||
private final Logger logger = LoggerFactory.getLogger(getClass()); | |||
@@ -119,7 +122,7 @@ public class RepositoryManager implements IRepositoryManager { | |||
private final IUserManager userManager; | |||
private final File repositoriesFolder; | |||
private File repositoriesFolder; | |||
private LuceneService luceneExecutor; | |||
@@ -127,6 +130,7 @@ public class RepositoryManager implements IRepositoryManager { | |||
private MirrorService mirrorExecutor; | |||
@Inject | |||
public RepositoryManager( | |||
IRuntimeManager runtimeManager, | |||
IPluginManager pluginManager, | |||
@@ -136,11 +140,11 @@ public class RepositoryManager implements IRepositoryManager { | |||
this.runtimeManager = runtimeManager; | |||
this.pluginManager = pluginManager; | |||
this.userManager = userManager; | |||
this.repositoriesFolder = runtimeManager.getFileOrFolder(Keys.git.repositoriesFolder, "${baseFolder}/git"); | |||
} | |||
@Override | |||
public RepositoryManager start() { | |||
repositoriesFolder = runtimeManager.getFileOrFolder(Keys.git.repositoriesFolder, "${baseFolder}/git"); | |||
logger.info("Repositories folder : {}", repositoriesFolder.getAbsolutePath()); | |||
// initialize utilities | |||
@@ -1934,21 +1938,19 @@ public class RepositoryManager implements IRepositoryManager { | |||
} | |||
protected void confirmWriteAccess() { | |||
if (runtimeManager.isServingRepositories()) { | |||
try { | |||
if (!getRepositoriesFolder().exists()) { | |||
getRepositoriesFolder().mkdirs(); | |||
} | |||
File file = File.createTempFile(".test-", ".txt", getRepositoriesFolder()); | |||
file.delete(); | |||
} catch (Exception e) { | |||
logger.error(""); | |||
logger.error(Constants.BORDER2); | |||
logger.error("Please check filesystem permissions!"); | |||
logger.error("FAILED TO WRITE TO REPOSITORIES FOLDER!!", e); | |||
logger.error(Constants.BORDER2); | |||
logger.error(""); | |||
try { | |||
if (!getRepositoriesFolder().exists()) { | |||
getRepositoriesFolder().mkdirs(); | |||
} | |||
File file = File.createTempFile(".test-", ".txt", getRepositoriesFolder()); | |||
file.delete(); | |||
} catch (Exception e) { | |||
logger.error(""); | |||
logger.error(Constants.BORDER2); | |||
logger.error("Please check filesystem permissions!"); | |||
logger.error("FAILED TO WRITE TO REPOSITORIES FOLDER!!", e); | |||
logger.error(Constants.BORDER2); | |||
logger.error(""); | |||
} | |||
} | |||
} |
@@ -32,7 +32,11 @@ import com.gitblit.models.ServerSettings; | |||
import com.gitblit.models.ServerStatus; | |||
import com.gitblit.models.SettingModel; | |||
import com.gitblit.utils.StringUtils; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Injector; | |||
import com.google.inject.Singleton; | |||
@Singleton | |||
public class RuntimeManager implements IRuntimeManager { | |||
private final Logger logger = LoggerFactory.getLogger(getClass()); | |||
@@ -47,6 +51,10 @@ public class RuntimeManager implements IRuntimeManager { | |||
private TimeZone timezone; | |||
@Inject | |||
private Injector injector; | |||
@Inject | |||
public RuntimeManager(IStoredSettings settings) { | |||
this(settings, null); | |||
} | |||
@@ -74,6 +82,11 @@ public class RuntimeManager implements IRuntimeManager { | |||
return this; | |||
} | |||
@Override | |||
public Injector getInjector() { | |||
return injector; | |||
} | |||
@Override | |||
public File getBaseFolder() { | |||
return baseFolder; | |||
@@ -111,52 +124,6 @@ public class RuntimeManager implements IRuntimeManager { | |||
return settingsModel; | |||
} | |||
/** | |||
* Determine if this Gitblit instance is actively serving git repositories | |||
* or if it is merely a repository viewer. | |||
* | |||
* @return true if Gitblit is serving repositories | |||
*/ | |||
@Override | |||
public boolean isServingRepositories() { | |||
return isServingHTTP() | |||
|| isServingGIT() | |||
|| isServingSSH(); | |||
} | |||
/** | |||
* Determine if this Gitblit instance is actively serving git repositories | |||
* over the HTTP protocol. | |||
* | |||
* @return true if Gitblit is serving repositories over the HTTP protocol | |||
*/ | |||
@Override | |||
public boolean isServingHTTP() { | |||
return settings.getBoolean(Keys.git.enableGitServlet, true); | |||
} | |||
/** | |||
* Determine if this Gitblit instance is actively serving git repositories | |||
* over the Git Daemon protocol. | |||
* | |||
* @return true if Gitblit is serving repositories over the Git Daemon protocol | |||
*/ | |||
@Override | |||
public boolean isServingGIT() { | |||
return settings.getInteger(Keys.git.daemonPort, 0) > 0; | |||
} | |||
/** | |||
* Determine if this Gitblit instance is actively serving git repositories | |||
* over the SSH protocol. | |||
* | |||
* @return true if Gitblit is serving repositories over the SSH protocol | |||
*/ | |||
@Override | |||
public boolean isServingSSH() { | |||
return settings.getInteger(Keys.git.sshPort, 0) > 0; | |||
} | |||
/** | |||
* Returns the preferred timezone for the Gitblit instance. | |||
* |
@@ -18,9 +18,15 @@ package com.gitblit.manager; | |||
import java.io.IOException; | |||
import java.net.URI; | |||
import java.text.MessageFormat; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.Collections; | |||
import java.util.Comparator; | |||
import java.util.Date; | |||
import java.util.HashSet; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Set; | |||
import java.util.concurrent.Executors; | |||
import java.util.concurrent.ScheduledExecutorService; | |||
import java.util.concurrent.TimeUnit; | |||
@@ -30,9 +36,11 @@ import javax.servlet.http.HttpServletRequest; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import com.gitblit.Constants; | |||
import com.gitblit.Constants.AccessPermission; | |||
import com.gitblit.Constants.AccessRestrictionType; | |||
import com.gitblit.Constants.FederationToken; | |||
import com.gitblit.Constants.Transport; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.fanout.FanoutNioService; | |||
@@ -40,14 +48,18 @@ import com.gitblit.fanout.FanoutService; | |||
import com.gitblit.fanout.FanoutSocketService; | |||
import com.gitblit.models.FederationModel; | |||
import com.gitblit.models.RepositoryModel; | |||
import com.gitblit.models.RepositoryUrl; | |||
import com.gitblit.models.UserModel; | |||
import com.gitblit.service.FederationPullService; | |||
import com.gitblit.transport.git.GitDaemon; | |||
import com.gitblit.transport.ssh.SshDaemon; | |||
import com.gitblit.utils.IdGenerator; | |||
import com.gitblit.utils.HttpUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import com.gitblit.utils.TimeUtils; | |||
import com.gitblit.utils.WorkQueue; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Provider; | |||
import com.google.inject.Singleton; | |||
/** | |||
* Services manager manages long-running services/processes that either have no | |||
@@ -57,32 +69,35 @@ import com.gitblit.utils.WorkQueue; | |||
* @author James Moger | |||
* | |||
*/ | |||
public class ServicesManager implements IManager { | |||
@Singleton | |||
public class ServicesManager implements IServicesManager { | |||
private final Logger logger = LoggerFactory.getLogger(getClass()); | |||
private final ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(5); | |||
private final Provider<WorkQueue> workQueueProvider; | |||
private final IStoredSettings settings; | |||
private final IGitblit gitblit; | |||
private final IdGenerator idGenerator; | |||
private final WorkQueue workQueue; | |||
private FanoutService fanoutService; | |||
private GitDaemon gitDaemon; | |||
private SshDaemon sshDaemon; | |||
public ServicesManager(IGitblit gitblit) { | |||
this.settings = gitblit.getSettings(); | |||
@Inject | |||
public ServicesManager( | |||
Provider<WorkQueue> workQueueProvider, | |||
IStoredSettings settings, | |||
IGitblit gitblit) { | |||
this.workQueueProvider = workQueueProvider; | |||
this.settings = settings; | |||
this.gitblit = gitblit; | |||
int defaultThreadPoolSize = settings.getInteger(Keys.execution.defaultThreadPoolSize, 1); | |||
this.idGenerator = new IdGenerator(); | |||
this.workQueue = new WorkQueue(idGenerator, defaultThreadPoolSize); | |||
} | |||
@Override | |||
@@ -107,24 +122,181 @@ public class ServicesManager implements IManager { | |||
if (sshDaemon != null) { | |||
sshDaemon.stop(); | |||
} | |||
workQueue.stop(); | |||
workQueueProvider.get().stop(); | |||
return this; | |||
} | |||
protected String getRepositoryUrl(HttpServletRequest request, String username, RepositoryModel repository) { | |||
String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null); | |||
if (StringUtils.isEmpty(gitblitUrl)) { | |||
gitblitUrl = HttpUtils.getGitblitURL(request); | |||
} | |||
StringBuilder sb = new StringBuilder(); | |||
sb.append(gitblitUrl); | |||
sb.append(Constants.R_PATH); | |||
sb.append(repository.name); | |||
// inject username into repository url if authentication is required | |||
if (repository.accessRestriction.exceeds(AccessRestrictionType.NONE) | |||
&& !StringUtils.isEmpty(username)) { | |||
sb.insert(sb.indexOf("://") + 3, username + "@"); | |||
} | |||
return sb.toString(); | |||
} | |||
/** | |||
* Returns a list of repository URLs and the user access permission. | |||
* | |||
* @param request | |||
* @param user | |||
* @param repository | |||
* @return a list of repository urls | |||
*/ | |||
@Override | |||
public List<RepositoryUrl> getRepositoryUrls(HttpServletRequest request, UserModel user, RepositoryModel repository) { | |||
if (user == null) { | |||
user = UserModel.ANONYMOUS; | |||
} | |||
String username = StringUtils.encodeUsername(UserModel.ANONYMOUS.equals(user) ? "" : user.username); | |||
List<RepositoryUrl> list = new ArrayList<RepositoryUrl>(); | |||
// http/https url | |||
if (settings.getBoolean(Keys.git.enableGitServlet, true)) { | |||
AccessPermission permission = user.getRepositoryPermission(repository).permission; | |||
if (permission.exceeds(AccessPermission.NONE)) { | |||
Transport transport = Transport.fromString(request.getScheme()); | |||
if (permission.atLeast(AccessPermission.PUSH) && !acceptPush(transport)) { | |||
// downgrade the repo permission for this transport | |||
// because it is not an acceptable PUSH transport | |||
permission = AccessPermission.CLONE; | |||
} | |||
list.add(new RepositoryUrl(getRepositoryUrl(request, username, repository), permission)); | |||
} | |||
} | |||
// ssh daemon url | |||
String sshDaemonUrl = getSshDaemonUrl(request, user, repository); | |||
if (!StringUtils.isEmpty(sshDaemonUrl)) { | |||
AccessPermission permission = user.getRepositoryPermission(repository).permission; | |||
if (permission.exceeds(AccessPermission.NONE)) { | |||
if (permission.atLeast(AccessPermission.PUSH) && !acceptPush(Transport.SSH)) { | |||
// downgrade the repo permission for this transport | |||
// because it is not an acceptable PUSH transport | |||
permission = AccessPermission.CLONE; | |||
} | |||
list.add(new RepositoryUrl(sshDaemonUrl, permission)); | |||
} | |||
} | |||
// git daemon url | |||
String gitDaemonUrl = getGitDaemonUrl(request, user, repository); | |||
if (!StringUtils.isEmpty(gitDaemonUrl)) { | |||
AccessPermission permission = getGitDaemonAccessPermission(user, repository); | |||
if (permission.exceeds(AccessPermission.NONE)) { | |||
if (permission.atLeast(AccessPermission.PUSH) && !acceptPush(Transport.GIT)) { | |||
// downgrade the repo permission for this transport | |||
// because it is not an acceptable PUSH transport | |||
permission = AccessPermission.CLONE; | |||
} | |||
list.add(new RepositoryUrl(gitDaemonUrl, permission)); | |||
} | |||
} | |||
// add all other urls | |||
// {0} = repository | |||
// {1} = username | |||
for (String url : settings.getStrings(Keys.web.otherUrls)) { | |||
if (url.contains("{1}")) { | |||
// external url requires username, only add url IF we have one | |||
if (!StringUtils.isEmpty(username)) { | |||
list.add(new RepositoryUrl(MessageFormat.format(url, repository.name, username), null)); | |||
} | |||
} else { | |||
// external url does not require username | |||
list.add(new RepositoryUrl(MessageFormat.format(url, repository.name), null)); | |||
} | |||
} | |||
// sort transports by highest permission and then by transport security | |||
Collections.sort(list, new Comparator<RepositoryUrl>() { | |||
@Override | |||
public int compare(RepositoryUrl o1, RepositoryUrl o2) { | |||
if (!o1.isExternal() && o2.isExternal()) { | |||
// prefer Gitblit over external | |||
return -1; | |||
} else if (o1.isExternal() && !o2.isExternal()) { | |||
// prefer Gitblit over external | |||
return 1; | |||
} else if (o1.isExternal() && o2.isExternal()) { | |||
// sort by Transport ordinal | |||
return o1.transport.compareTo(o2.transport); | |||
} else if (o1.permission.exceeds(o2.permission)) { | |||
// prefer highest permission | |||
return -1; | |||
} else if (o2.permission.exceeds(o1.permission)) { | |||
// prefer highest permission | |||
return 1; | |||
} | |||
// prefer more secure transports | |||
return o1.transport.compareTo(o2.transport); | |||
} | |||
}); | |||
// consider the user's transport preference | |||
RepositoryUrl preferredUrl = null; | |||
Transport preferredTransport = user.getPreferences().getTransport(); | |||
if (preferredTransport != null) { | |||
Iterator<RepositoryUrl> itr = list.iterator(); | |||
while (itr.hasNext()) { | |||
RepositoryUrl url = itr.next(); | |||
if (url.transport.equals(preferredTransport)) { | |||
itr.remove(); | |||
preferredUrl = url; | |||
break; | |||
} | |||
} | |||
} | |||
if (preferredUrl != null) { | |||
list.add(0, preferredUrl); | |||
} | |||
return list; | |||
} | |||
/* (non-Javadoc) | |||
* @see com.gitblit.manager.IServicesManager#isServingRepositories() | |||
*/ | |||
@Override | |||
public boolean isServingRepositories() { | |||
return isServingHTTP() | |||
|| isServingGIT() | |||
|| isServingSSH(); | |||
} | |||
/* (non-Javadoc) | |||
* @see com.gitblit.manager.IServicesManager#isServingHTTP() | |||
*/ | |||
@Override | |||
public boolean isServingHTTP() { | |||
return settings.getBoolean(Keys.git.enableGitServlet, true); | |||
} | |||
/* (non-Javadoc) | |||
* @see com.gitblit.manager.IServicesManager#isServingGIT() | |||
*/ | |||
@Override | |||
public boolean isServingGIT() { | |||
return gitDaemon != null && gitDaemon.isRunning(); | |||
} | |||
/* (non-Javadoc) | |||
* @see com.gitblit.manager.IServicesManager#isServingSSH() | |||
*/ | |||
@Override | |||
public boolean isServingSSH() { | |||
return sshDaemon != null && sshDaemon.isRunning(); | |||
} | |||
@@ -158,6 +330,32 @@ public class ServicesManager implements IManager { | |||
} | |||
} | |||
protected boolean acceptPush(Transport byTransport) { | |||
if (byTransport == null) { | |||
logger.info("Unknown transport, push rejected!"); | |||
return false; | |||
} | |||
Set<Transport> transports = new HashSet<Transport>(); | |||
for (String value : settings.getStrings(Keys.git.acceptedPushTransports)) { | |||
Transport transport = Transport.fromString(value); | |||
if (transport == null) { | |||
logger.info(String.format("Ignoring unknown registered transport %s", value)); | |||
continue; | |||
} | |||
transports.add(transport); | |||
} | |||
if (transports.isEmpty()) { | |||
// no transports are explicitly specified, all are acceptable | |||
return true; | |||
} | |||
// verify that the transport is permitted | |||
return transports.contains(byTransport); | |||
} | |||
protected void configureGitDaemon() { | |||
int port = settings.getInteger(Keys.git.daemonPort, 0); | |||
String bindInterface = settings.getString(Keys.git.daemonBindInterface, "localhost"); | |||
@@ -179,7 +377,7 @@ public class ServicesManager implements IManager { | |||
String bindInterface = settings.getString(Keys.git.sshBindInterface, "localhost"); | |||
if (port > 0) { | |||
try { | |||
sshDaemon = new SshDaemon(gitblit, workQueue); | |||
sshDaemon = new SshDaemon(gitblit, workQueueProvider.get()); | |||
sshDaemon.start(); | |||
} catch (IOException e) { | |||
sshDaemon = null; | |||
@@ -285,7 +483,7 @@ public class ServicesManager implements IManager { | |||
*/ | |||
protected String getHostname(HttpServletRequest request) { | |||
String hostname = request.getServerName(); | |||
String canonicalUrl = gitblit.getSettings().getString(Keys.web.canonicalUrl, null); | |||
String canonicalUrl = settings.getString(Keys.web.canonicalUrl, null); | |||
if (!StringUtils.isEmpty(canonicalUrl)) { | |||
try { | |||
URI uri = new URI(canonicalUrl); |
@@ -36,6 +36,8 @@ import com.gitblit.extensions.UserTeamLifeCycleListener; | |||
import com.gitblit.models.TeamModel; | |||
import com.gitblit.models.UserModel; | |||
import com.gitblit.utils.StringUtils; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
/** | |||
* The user manager manages persistence and retrieval of users and teams. | |||
@@ -43,6 +45,7 @@ import com.gitblit.utils.StringUtils; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class UserManager implements IUserManager { | |||
private final Logger logger = LoggerFactory.getLogger(getClass()); | |||
@@ -57,6 +60,7 @@ public class UserManager implements IUserManager { | |||
private IUserService userService; | |||
@Inject | |||
public UserManager(IRuntimeManager runtimeManager, IPluginManager pluginManager) { | |||
this.settings = runtimeManager.getSettings(); | |||
this.runtimeManager = runtimeManager; |
@@ -19,21 +19,19 @@ import java.io.IOException; | |||
import java.text.MessageFormat; | |||
import javax.servlet.FilterChain; | |||
import javax.servlet.FilterConfig; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.ServletRequest; | |||
import javax.servlet.ServletResponse; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import com.gitblit.manager.IAuthenticationManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.models.RepositoryModel; | |||
import com.gitblit.models.UserModel; | |||
import com.gitblit.utils.StringUtils; | |||
import dagger.ObjectGraph; | |||
/** | |||
* The AccessRestrictionFilter is an AuthenticationFilter that confirms that the | |||
* requested repository can be accessed by the anonymous or named user. | |||
@@ -54,11 +52,15 @@ public abstract class AccessRestrictionFilter extends AuthenticationFilter { | |||
protected IRepositoryManager repositoryManager; | |||
@Override | |||
protected void inject(ObjectGraph dagger, FilterConfig filterConfig) { | |||
super.inject(dagger, filterConfig); | |||
this.runtimeManager = dagger.get(IRuntimeManager.class); | |||
this.repositoryManager = dagger.get(IRepositoryManager.class); | |||
protected AccessRestrictionFilter( | |||
IRuntimeManager runtimeManager, | |||
IAuthenticationManager authenticationManager, | |||
IRepositoryManager repositoryManager) { | |||
super(authenticationManager); | |||
this.runtimeManager = runtimeManager; | |||
this.repositoryManager = repositoryManager; | |||
} | |||
/** |
@@ -21,6 +21,7 @@ import java.util.Enumeration; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import javax.servlet.Filter; | |||
import javax.servlet.FilterChain; | |||
import javax.servlet.FilterConfig; | |||
import javax.servlet.ServletException; | |||
@@ -35,14 +36,11 @@ import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import com.gitblit.Constants; | |||
import com.gitblit.dagger.DaggerFilter; | |||
import com.gitblit.manager.IAuthenticationManager; | |||
import com.gitblit.models.UserModel; | |||
import com.gitblit.utils.DeepCopier; | |||
import com.gitblit.utils.StringUtils; | |||
import dagger.ObjectGraph; | |||
/** | |||
* The AuthenticationFilter is a servlet filter that preprocesses requests that | |||
* match its url pattern definition in the web.xml file. | |||
@@ -52,7 +50,7 @@ import dagger.ObjectGraph; | |||
* @author James Moger | |||
* | |||
*/ | |||
public abstract class AuthenticationFilter extends DaggerFilter { | |||
public abstract class AuthenticationFilter implements Filter { | |||
protected static final String CHALLENGE = "Basic realm=\"" + Constants.NAME + "\""; | |||
@@ -62,9 +60,16 @@ public abstract class AuthenticationFilter extends DaggerFilter { | |||
protected IAuthenticationManager authenticationManager; | |||
protected AuthenticationFilter(IAuthenticationManager authenticationManager) { | |||
this.authenticationManager = authenticationManager; | |||
} | |||
@Override | |||
public void init(FilterConfig filterConfig) throws ServletException { | |||
} | |||
@Override | |||
protected void inject(ObjectGraph dagger, FilterConfig filterConfig) { | |||
this.authenticationManager = dagger.get(IAuthenticationManager.class); | |||
public void destroy() { | |||
} | |||
/** |
@@ -36,7 +36,10 @@ import java.util.Set; | |||
import java.util.TreeSet; | |||
import javax.imageio.ImageIO; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
@@ -52,20 +55,18 @@ import org.eclipse.jgit.revwalk.RevCommit; | |||
import com.gitblit.Constants; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.dagger.DaggerServlet; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.utils.JGitUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import dagger.ObjectGraph; | |||
/** | |||
* Handles requests for branch graphs | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
public class BranchGraphServlet extends DaggerServlet { | |||
@Singleton | |||
public class BranchGraphServlet extends HttpServlet { | |||
private static final long serialVersionUID = 1L; | |||
@@ -82,20 +83,20 @@ public class BranchGraphServlet extends DaggerServlet { | |||
private IRepositoryManager repositoryManager; | |||
public BranchGraphServlet() { | |||
super(); | |||
@Inject | |||
public BranchGraphServlet( | |||
IStoredSettings settings, | |||
IRepositoryManager repositoryManager) { | |||
this.settings = settings; | |||
this.repositoryManager = repositoryManager; | |||
strokeCache = new Stroke[4]; | |||
for (int i = 1; i < strokeCache.length; i++) { | |||
strokeCache[i] = new BasicStroke(i); | |||
} | |||
} | |||
@Override | |||
protected void inject(ObjectGraph dagger) { | |||
this.settings = dagger.get(IStoredSettings.class); | |||
this.repositoryManager = dagger.get(IRepositoryManager.class); | |||
} | |||
/** | |||
* Returns an url to this servlet for the specified parameters. | |||
* |
@@ -15,7 +15,13 @@ | |||
*/ | |||
package com.gitblit.servlet; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import com.gitblit.Constants.AccessRestrictionType; | |||
import com.gitblit.manager.IAuthenticationManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.models.RepositoryModel; | |||
import com.gitblit.models.UserModel; | |||
@@ -27,8 +33,18 @@ import com.gitblit.models.UserModel; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class DownloadZipFilter extends AccessRestrictionFilter { | |||
@Inject | |||
public DownloadZipFilter( | |||
IRuntimeManager runtimeManager, | |||
IAuthenticationManager authenticationManager, | |||
IRepositoryManager repositoryManager) { | |||
super(runtimeManager, authenticationManager, repositoryManager); | |||
} | |||
/** | |||
* Extract the repository name from the url. | |||
* |
@@ -20,7 +20,10 @@ import java.text.MessageFormat; | |||
import java.text.ParseException; | |||
import java.util.Date; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletResponse; | |||
import org.eclipse.jgit.lib.Repository; | |||
@@ -31,15 +34,12 @@ import org.slf4j.LoggerFactory; | |||
import com.gitblit.Constants; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.dagger.DaggerServlet; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.utils.CompressionUtils; | |||
import com.gitblit.utils.JGitUtils; | |||
import com.gitblit.utils.MarkdownUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import dagger.ObjectGraph; | |||
/** | |||
* Streams out a zip file from the specified repository for any tree path at any | |||
* revision. | |||
@@ -47,7 +47,8 @@ import dagger.ObjectGraph; | |||
* @author James Moger | |||
* | |||
*/ | |||
public class DownloadZipServlet extends DaggerServlet { | |||
@Singleton | |||
public class DownloadZipServlet extends HttpServlet { | |||
private static final long serialVersionUID = 1L; | |||
@@ -76,10 +77,10 @@ public class DownloadZipServlet extends DaggerServlet { | |||
} | |||
} | |||
@Override | |||
protected void inject(ObjectGraph dagger) { | |||
this.settings = dagger.get(IStoredSettings.class); | |||
this.repositoryManager = dagger.get(IRepositoryManager.class); | |||
@Inject | |||
public DownloadZipServlet(IStoredSettings settings, IRepositoryManager repositoryManager) { | |||
this.settings = settings; | |||
this.repositoryManager = repositoryManager; | |||
} | |||
/** |
@@ -18,6 +18,9 @@ | |||
import java.io.IOException; | |||
import java.text.MessageFormat; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.Filter; | |||
import javax.servlet.FilterChain; | |||
import javax.servlet.FilterConfig; | |||
import javax.servlet.ServletException; | |||
@@ -31,12 +34,9 @@ import org.slf4j.LoggerFactory; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.dagger.DaggerFilter; | |||
import com.gitblit.manager.IAuthenticationManager; | |||
import com.gitblit.models.UserModel; | |||
import dagger.ObjectGraph; | |||
/** | |||
* This filter enforces authentication via HTTP Basic Authentication, if the settings indicate so. | |||
* It looks at the settings "web.authenticateViewPages" and "web.enforceHttpBasicAuthentication"; if | |||
@@ -45,7 +45,8 @@ import dagger.ObjectGraph; | |||
* @author Laurens Vrijnsen | |||
* | |||
*/ | |||
public class EnforceAuthenticationFilter extends DaggerFilter { | |||
@Singleton | |||
public class EnforceAuthenticationFilter implements Filter { | |||
protected transient Logger logger = LoggerFactory.getLogger(getClass()); | |||
@@ -53,10 +54,21 @@ public class EnforceAuthenticationFilter extends DaggerFilter { | |||
private IAuthenticationManager authenticationManager; | |||
@Inject | |||
public EnforceAuthenticationFilter( | |||
IStoredSettings settings, | |||
IAuthenticationManager authenticationManager) { | |||
this.settings = settings; | |||
this.authenticationManager = authenticationManager; | |||
} | |||
@Override | |||
protected void inject(ObjectGraph dagger, FilterConfig filterConfig) { | |||
this.settings = dagger.get(IStoredSettings.class); | |||
this.authenticationManager = dagger.get(IAuthenticationManager.class); | |||
public void init(FilterConfig config) { | |||
} | |||
@Override | |||
public void destroy() { | |||
} | |||
/* | |||
@@ -87,12 +99,4 @@ public class EnforceAuthenticationFilter extends DaggerFilter { | |||
chain.doFilter(request, response); | |||
} | |||
} | |||
/* | |||
* @see javax.servlet.Filter#destroy() | |||
*/ | |||
@Override | |||
public void destroy() { | |||
} | |||
} |
@@ -25,6 +25,8 @@ import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.http.HttpServletResponse; | |||
import com.gitblit.Constants.FederationRequest; | |||
@@ -43,14 +45,13 @@ import com.gitblit.utils.HttpUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import com.gitblit.utils.TimeUtils; | |||
import dagger.ObjectGraph; | |||
/** | |||
* Handles federation requests. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class FederationServlet extends JsonServlet { | |||
private static final long serialVersionUID = 1L; | |||
@@ -63,12 +64,17 @@ public class FederationServlet extends JsonServlet { | |||
private IFederationManager federationManager; | |||
@Override | |||
protected void inject(ObjectGraph dagger) { | |||
this.settings = dagger.get(IStoredSettings.class); | |||
this.userManager = dagger.get(IUserManager.class); | |||
this.repositoryManager = dagger.get(IRepositoryManager.class); | |||
this.federationManager = dagger.get(IFederationManager.class); | |||
@Inject | |||
public FederationServlet( | |||
IStoredSettings settings, | |||
IUserManager userManager, | |||
IRepositoryManager repositoryManager, | |||
IFederationManager federationManager) { | |||
this.settings = settings; | |||
this.userManager = userManager; | |||
this.repositoryManager = repositoryManager; | |||
this.federationManager = federationManager; | |||
} | |||
/** |
@@ -17,7 +17,8 @@ package com.gitblit.servlet; | |||
import java.text.MessageFormat; | |||
import javax.servlet.FilterConfig; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.http.HttpServletRequest; | |||
import com.gitblit.Constants.AccessRestrictionType; | |||
@@ -25,13 +26,14 @@ import com.gitblit.Constants.AuthorizationControl; | |||
import com.gitblit.GitBlitException; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.manager.IAuthenticationManager; | |||
import com.gitblit.manager.IFederationManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.models.RepositoryModel; | |||
import com.gitblit.models.UserModel; | |||
import com.gitblit.utils.StringUtils; | |||
import dagger.ObjectGraph; | |||
/** | |||
* The GitFilter is an AccessRestrictionFilter which ensures that Git client | |||
* requests for push, clone, or view restricted repositories are authenticated | |||
@@ -40,6 +42,7 @@ import dagger.ObjectGraph; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class GitFilter extends AccessRestrictionFilter { | |||
protected static final String gitReceivePack = "/git-receive-pack"; | |||
@@ -53,11 +56,18 @@ public class GitFilter extends AccessRestrictionFilter { | |||
private IFederationManager federationManager; | |||
@Override | |||
protected void inject(ObjectGraph dagger, FilterConfig filterConfig) { | |||
super.inject(dagger, filterConfig); | |||
this.settings = dagger.get(IStoredSettings.class); | |||
this.federationManager = dagger.get(IFederationManager.class); | |||
@Inject | |||
public GitFilter( | |||
IStoredSettings settings, | |||
IRuntimeManager runtimeManager, | |||
IAuthenticationManager authenticationManager, | |||
IRepositoryManager repositoryManager, | |||
IFederationManager federationManager) { | |||
super(runtimeManager, authenticationManager, repositoryManager); | |||
this.settings = settings; | |||
this.federationManager = federationManager; | |||
} | |||
/** |
@@ -20,6 +20,8 @@ import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND; | |||
import java.io.IOException; | |||
import java.util.Enumeration; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.FilterChain; | |||
import javax.servlet.FilterConfig; | |||
import javax.servlet.ServletConfig; | |||
@@ -33,14 +35,11 @@ import javax.servlet.http.HttpServletResponse; | |||
import org.eclipse.jgit.http.server.GitFilter; | |||
import com.gitblit.dagger.DaggerContext; | |||
import com.gitblit.git.GitblitReceivePackFactory; | |||
import com.gitblit.git.GitblitUploadPackFactory; | |||
import com.gitblit.git.RepositoryResolver; | |||
import com.gitblit.manager.IGitblit; | |||
import dagger.ObjectGraph; | |||
/** | |||
* The GitServlet provides http/https access to Git repositories. | |||
* Access to this servlet is protected by the GitFilter. | |||
@@ -48,24 +47,23 @@ import dagger.ObjectGraph; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class GitServlet extends HttpServlet { | |||
private static final long serialVersionUID = 1L; | |||
private final GitFilter gitFilter; | |||
public GitServlet() { | |||
@Inject | |||
public GitServlet(IGitblit gitblit) { | |||
gitFilter = new GitFilter(); | |||
gitFilter.setRepositoryResolver(new RepositoryResolver<HttpServletRequest>(gitblit)); | |||
gitFilter.setUploadPackFactory(new GitblitUploadPackFactory<HttpServletRequest>(gitblit)); | |||
gitFilter.setReceivePackFactory(new GitblitReceivePackFactory<HttpServletRequest>(gitblit)); | |||
} | |||
@Override | |||
public void init(final ServletConfig config) throws ServletException { | |||
ServletContext context = config.getServletContext(); | |||
ObjectGraph dagger = (ObjectGraph) context.getAttribute(DaggerContext.INJECTOR_NAME); | |||
IGitblit gitblit = dagger.get(IGitblit.class); | |||
gitFilter.setRepositoryResolver(new RepositoryResolver<HttpServletRequest>(gitblit)); | |||
gitFilter.setUploadPackFactory(new GitblitUploadPackFactory<HttpServletRequest>(gitblit)); | |||
gitFilter.setReceivePackFactory(new GitblitReceivePackFactory<HttpServletRequest>(gitblit)); | |||
gitFilter.init(new FilterConfig() { | |||
@Override |
@@ -31,14 +31,17 @@ import javax.naming.NamingException; | |||
import javax.servlet.ServletContext; | |||
import javax.servlet.ServletContextEvent; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import com.gitblit.Constants; | |||
import com.gitblit.DaggerModule; | |||
import com.gitblit.FileSettings; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.WebXmlSettings; | |||
import com.gitblit.dagger.DaggerContext; | |||
import com.gitblit.extensions.LifeCycleListener; | |||
import com.gitblit.guice.CoreModule; | |||
import com.gitblit.guice.WebModule; | |||
import com.gitblit.manager.IAuthenticationManager; | |||
import com.gitblit.manager.IFederationManager; | |||
import com.gitblit.manager.IGitblit; | |||
@@ -48,28 +51,34 @@ import com.gitblit.manager.IPluginManager; | |||
import com.gitblit.manager.IProjectManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.manager.IServicesManager; | |||
import com.gitblit.manager.IUserManager; | |||
import com.gitblit.tickets.ITicketService; | |||
import com.gitblit.transport.ssh.IPublicKeyManager; | |||
import com.gitblit.utils.ContainerUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import dagger.ObjectGraph; | |||
import com.google.inject.AbstractModule; | |||
import com.google.inject.Guice; | |||
import com.google.inject.Injector; | |||
import com.google.inject.servlet.GuiceServletContextListener; | |||
/** | |||
* 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 | |||
* | |||
*/ | |||
public class GitblitContext extends DaggerContext { | |||
public class GitblitContext extends GuiceServletContextListener { | |||
private static GitblitContext gitblit; | |||
protected final Logger logger = LoggerFactory.getLogger(getClass()); | |||
private final List<IManager> managers = new ArrayList<IManager>(); | |||
private final IStoredSettings goSettings; | |||
@@ -111,12 +120,16 @@ public class GitblitContext extends DaggerContext { | |||
return null; | |||
} | |||
@Override | |||
protected Injector getInjector() { | |||
return Guice.createInjector(getModules()); | |||
} | |||
/** | |||
* Returns Gitblit's Dagger injection modules. | |||
* Returns Gitblit's Guice injection modules. | |||
*/ | |||
@Override | |||
protected Object [] getModules() { | |||
return new Object [] { new DaggerModule() }; | |||
protected AbstractModule [] getModules() { | |||
return new AbstractModule [] { new CoreModule(), new WebModule() }; | |||
} | |||
/** | |||
@@ -127,18 +140,20 @@ public class GitblitContext extends DaggerContext { | |||
*/ | |||
@Override | |||
public final void contextInitialized(ServletContextEvent contextEvent) { | |||
super.contextInitialized(contextEvent); | |||
ServletContext context = contextEvent.getServletContext(); | |||
configureContext(context); | |||
startCore(context); | |||
} | |||
/** | |||
* Prepare runtime settings and start all manager instances. | |||
*/ | |||
protected void configureContext(ServletContext context) { | |||
ObjectGraph injector = getInjector(context); | |||
protected void startCore(ServletContext context) { | |||
Injector injector = (Injector) context.getAttribute(Injector.class.getName()); | |||
// create the runtime settings object | |||
IStoredSettings runtimeSettings = injector.get(IStoredSettings.class); | |||
IStoredSettings runtimeSettings = injector.getInstance(IStoredSettings.class); | |||
final File baseFolder; | |||
if (goSettings != null) { | |||
@@ -168,7 +183,7 @@ public class GitblitContext extends DaggerContext { | |||
// Manually configure IRuntimeManager | |||
logManager(IRuntimeManager.class); | |||
IRuntimeManager runtime = injector.get(IRuntimeManager.class); | |||
IRuntimeManager runtime = injector.getInstance(IRuntimeManager.class); | |||
runtime.setBaseFolder(baseFolder); | |||
runtime.getStatus().isGO = goSettings != null; | |||
runtime.getStatus().servletContainer = context.getServerInfo(); | |||
@@ -186,7 +201,9 @@ public class GitblitContext extends DaggerContext { | |||
startManager(injector, IRepositoryManager.class); | |||
startManager(injector, IProjectManager.class); | |||
startManager(injector, IFederationManager.class); | |||
startManager(injector, ITicketService.class); | |||
startManager(injector, IGitblit.class); | |||
startManager(injector, IServicesManager.class); | |||
// start the plugin manager last so that plugins can depend on | |||
// deterministic access to all other managers in their start() methods | |||
@@ -196,7 +213,7 @@ public class GitblitContext extends DaggerContext { | |||
logger.info("All managers started."); | |||
logger.info(""); | |||
IPluginManager pluginManager = injector.get(IPluginManager.class); | |||
IPluginManager pluginManager = injector.getInstance(IPluginManager.class); | |||
for (LifeCycleListener listener : pluginManager.getExtensions(LifeCycleListener.class)) { | |||
try { | |||
listener.onStartup(); | |||
@@ -218,12 +235,12 @@ public class GitblitContext extends DaggerContext { | |||
return null; | |||
} | |||
protected <X extends IManager> X loadManager(ObjectGraph injector, Class<X> clazz) { | |||
X x = injector.get(clazz); | |||
protected <X extends IManager> X loadManager(Injector injector, Class<X> clazz) { | |||
X x = injector.getInstance(clazz); | |||
return x; | |||
} | |||
protected <X extends IManager> X startManager(ObjectGraph injector, Class<X> clazz) { | |||
protected <X extends IManager> X startManager(Injector injector, Class<X> clazz) { | |||
X x = loadManager(injector, clazz); | |||
logManager(clazz); | |||
x.start(); | |||
@@ -236,11 +253,17 @@ public class GitblitContext extends DaggerContext { | |||
logger.info("----[{}]----", clazz.getName()); | |||
} | |||
@Override | |||
public final void contextDestroyed(ServletContextEvent contextEvent) { | |||
super.contextDestroyed(contextEvent); | |||
ServletContext context = contextEvent.getServletContext(); | |||
destroyContext(context); | |||
} | |||
/** | |||
* Gitblit is being shutdown either because the servlet container is | |||
* shutting down or because the servlet container is re-deploying Gitblit. | |||
*/ | |||
@Override | |||
protected void destroyContext(ServletContext context) { | |||
logger.info("Gitblit context destroyed by servlet container."); | |||
@@ -21,6 +21,7 @@ import java.lang.reflect.Type; | |||
import java.text.MessageFormat; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
@@ -28,7 +29,6 @@ import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import com.gitblit.Constants; | |||
import com.gitblit.dagger.DaggerServlet; | |||
import com.gitblit.utils.JsonUtils; | |||
import com.gitblit.utils.StringUtils; | |||
@@ -38,7 +38,7 @@ import com.gitblit.utils.StringUtils; | |||
* @author James Moger | |||
* | |||
*/ | |||
public abstract class JsonServlet extends DaggerServlet { | |||
public abstract class JsonServlet extends HttpServlet { | |||
private static final long serialVersionUID = 1L; | |||
@@ -21,24 +21,25 @@ import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.OutputStream; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.ServletContext; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import com.gitblit.Keys; | |||
import com.gitblit.dagger.DaggerServlet; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import dagger.ObjectGraph; | |||
/** | |||
* Handles requests for logo.png | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
public class LogoServlet extends DaggerServlet { | |||
@Singleton | |||
public class LogoServlet extends HttpServlet { | |||
private static final long serialVersionUID = 1L; | |||
@@ -46,9 +47,9 @@ public class LogoServlet extends DaggerServlet { | |||
private IRuntimeManager runtimeManager; | |||
@Override | |||
protected void inject(ObjectGraph dagger) { | |||
this.runtimeManager = dagger.get(IRuntimeManager.class); | |||
@Inject | |||
public LogoServlet(IRuntimeManager runtimeManager) { | |||
this.runtimeManager = runtimeManager; | |||
} | |||
@Override |
@@ -15,6 +15,13 @@ | |||
*/ | |||
package com.gitblit.servlet; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import com.gitblit.manager.IAuthenticationManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
/** | |||
* The PagesFilter is an AccessRestrictionFilter which ensures the gh-pages | |||
@@ -23,7 +30,17 @@ package com.gitblit.servlet; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class PagesFilter extends RawFilter { | |||
@Inject | |||
public PagesFilter( | |||
IRuntimeManager runtimeManager, | |||
IAuthenticationManager authenticationManager, | |||
IRepositoryManager repositoryManager) { | |||
super(runtimeManager, authenticationManager, repositoryManager); | |||
} | |||
} |
@@ -15,10 +15,14 @@ | |||
*/ | |||
package com.gitblit.servlet; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import com.gitblit.Constants; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
/** | |||
* Serves the content of a gh-pages branch. | |||
@@ -26,6 +30,7 @@ import com.gitblit.Constants; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class PagesServlet extends RawServlet { | |||
private static final long serialVersionUID = 1L; | |||
@@ -46,6 +51,14 @@ public class PagesServlet extends RawServlet { | |||
return baseURL + Constants.PAGES + repository + "/" + (path == null ? "" : ("/" + path)); | |||
} | |||
@Inject | |||
public PagesServlet( | |||
IRuntimeManager runtimeManager, | |||
IRepositoryManager repositoryManager) { | |||
super(runtimeManager, repositoryManager); | |||
} | |||
@Override | |||
protected String getBranch(String repository, HttpServletRequest request) { | |||
return "gh-pages"; |
@@ -16,9 +16,13 @@ | |||
package com.gitblit.servlet; | |||
import java.io.IOException; | |||
import java.util.ArrayList; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.Filter; | |||
import javax.servlet.FilterChain; | |||
import javax.servlet.FilterConfig; | |||
import javax.servlet.ServletException; | |||
@@ -27,13 +31,10 @@ import javax.servlet.ServletResponse; | |||
import ro.fortsoft.pf4j.PluginWrapper; | |||
import com.gitblit.dagger.DaggerFilter; | |||
import com.gitblit.extensions.HttpRequestFilter; | |||
import com.gitblit.manager.IPluginManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import dagger.ObjectGraph; | |||
/** | |||
* A request filter than allows registered extension request filters to access | |||
* request data. The intended purpose is for server monitoring plugins. | |||
@@ -41,15 +42,29 @@ import dagger.ObjectGraph; | |||
* @author David Ostrovsky | |||
* @since 1.6.0 | |||
*/ | |||
public class ProxyFilter extends DaggerFilter { | |||
private List<HttpRequestFilter> filters; | |||
@Singleton | |||
public class ProxyFilter implements Filter { | |||
private final IRuntimeManager runtimeManager; | |||
private final IPluginManager pluginManager; | |||
private final List<HttpRequestFilter> filters; | |||
@Inject | |||
public ProxyFilter( | |||
IRuntimeManager runtimeManager, | |||
IPluginManager pluginManager) { | |||
this.runtimeManager = runtimeManager; | |||
this.pluginManager = pluginManager; | |||
this.filters = new ArrayList<>(); | |||
} | |||
@Override | |||
protected void inject(ObjectGraph dagger, FilterConfig filterConfig) throws ServletException { | |||
IRuntimeManager runtimeManager = dagger.get(IRuntimeManager.class); | |||
IPluginManager pluginManager = dagger.get(IPluginManager.class); | |||
public void init(FilterConfig filterConfig) throws ServletException { | |||
filters = pluginManager.getExtensions(HttpRequestFilter.class); | |||
filters.addAll(pluginManager.getExtensions(HttpRequestFilter.class)); | |||
for (HttpRequestFilter f : filters) { | |||
// wrap the filter config for Gitblit settings retrieval | |||
PluginWrapper pluginWrapper = pluginManager.whichPlugin(f.getClass()); |
@@ -21,7 +21,10 @@ import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.OutputStream; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
@@ -34,11 +37,8 @@ import org.apache.commons.compress.compressors.CompressorStreamFactory; | |||
import org.apache.wicket.util.io.ByteArrayOutputStream; | |||
import org.eclipse.jgit.lib.FileMode; | |||
import com.gitblit.dagger.DaggerServlet; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import dagger.ObjectGraph; | |||
/** | |||
* Handles requests for the Barnum pt (patchset tool). | |||
* | |||
@@ -47,7 +47,8 @@ import dagger.ObjectGraph; | |||
* @author James Moger | |||
* | |||
*/ | |||
public class PtServlet extends DaggerServlet { | |||
@Singleton | |||
public class PtServlet extends HttpServlet { | |||
private static final long serialVersionUID = 1L; | |||
@@ -55,9 +56,9 @@ public class PtServlet extends DaggerServlet { | |||
private IRuntimeManager runtimeManager; | |||
@Override | |||
protected void inject(ObjectGraph dagger) { | |||
this.runtimeManager = dagger.get(IRuntimeManager.class); | |||
@Inject | |||
public PtServlet(IRuntimeManager runtimeManager) { | |||
this.runtimeManager = runtimeManager; | |||
} | |||
@Override |
@@ -15,9 +15,15 @@ | |||
*/ | |||
package com.gitblit.servlet; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import org.eclipse.jgit.lib.Repository; | |||
import com.gitblit.Constants.AccessRestrictionType; | |||
import com.gitblit.manager.IAuthenticationManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.models.RepositoryModel; | |||
import com.gitblit.models.UserModel; | |||
@@ -28,8 +34,18 @@ import com.gitblit.models.UserModel; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class RawFilter extends AccessRestrictionFilter { | |||
@Inject | |||
public RawFilter( | |||
IRuntimeManager runtimeManager, | |||
IAuthenticationManager authenticationManager, | |||
IRepositoryManager repositoryManager) { | |||
super(runtimeManager, authenticationManager, repositoryManager); | |||
} | |||
/** | |||
* Extract the repository name from the url. | |||
* |
@@ -28,8 +28,11 @@ import java.util.List; | |||
import java.util.Map; | |||
import java.util.TreeMap; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.ServletContext; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
@@ -48,7 +51,6 @@ import org.slf4j.LoggerFactory; | |||
import com.gitblit.Constants; | |||
import com.gitblit.Keys; | |||
import com.gitblit.dagger.DaggerServlet; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.models.PathModel; | |||
@@ -57,28 +59,30 @@ import com.gitblit.utils.JGitUtils; | |||
import com.gitblit.utils.MarkdownUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import dagger.ObjectGraph; | |||
/** | |||
* Serves the content of a branch. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
public class RawServlet extends DaggerServlet { | |||
@Singleton | |||
public class RawServlet extends HttpServlet { | |||
private static final long serialVersionUID = 1L; | |||
private transient Logger logger = LoggerFactory.getLogger(RawServlet.class); | |||
private IRuntimeManager runtimeManager; | |||
private final IRuntimeManager runtimeManager; | |||
private IRepositoryManager repositoryManager; | |||
private final IRepositoryManager repositoryManager; | |||
@Override | |||
protected void inject(ObjectGraph dagger) { | |||
this.runtimeManager = dagger.get(IRuntimeManager.class); | |||
this.repositoryManager = dagger.get(IRepositoryManager.class); | |||
@Inject | |||
public RawServlet( | |||
IRuntimeManager runtimeManager, | |||
IRepositoryManager repositoryManager) { | |||
this.runtimeManager = runtimeManager; | |||
this.repositoryManager = repositoryManager; | |||
} | |||
/** |
@@ -18,32 +18,33 @@ package com.gitblit.servlet; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import com.gitblit.Keys; | |||
import com.gitblit.dagger.DaggerServlet; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.utils.FileUtils; | |||
import dagger.ObjectGraph; | |||
/** | |||
* Handles requests for robots.txt | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
public class RobotsTxtServlet extends DaggerServlet { | |||
@Singleton | |||
public class RobotsTxtServlet extends HttpServlet { | |||
private static final long serialVersionUID = 1L; | |||
private IRuntimeManager runtimeManager; | |||
@Override | |||
protected void inject(ObjectGraph dagger) { | |||
this.runtimeManager = dagger.get(IRuntimeManager.class); | |||
@Inject | |||
public RobotsTxtServlet(IRuntimeManager runtimeManager) { | |||
this.runtimeManager = runtimeManager; | |||
} | |||
@Override |
@@ -18,8 +18,9 @@ package com.gitblit.servlet; | |||
import java.io.IOException; | |||
import java.text.MessageFormat; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.FilterChain; | |||
import javax.servlet.FilterConfig; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.ServletRequest; | |||
import javax.servlet.ServletResponse; | |||
@@ -29,11 +30,10 @@ import javax.servlet.http.HttpServletResponse; | |||
import com.gitblit.Constants.RpcRequest; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.manager.IAuthenticationManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.models.UserModel; | |||
import dagger.ObjectGraph; | |||
/** | |||
* The RpcFilter is a servlet filter that secures the RpcServlet. | |||
* | |||
@@ -47,17 +47,23 @@ import dagger.ObjectGraph; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class RpcFilter extends AuthenticationFilter { | |||
private IStoredSettings settings; | |||
private IRuntimeManager runtimeManager; | |||
@Override | |||
protected void inject(ObjectGraph dagger, FilterConfig filterConfig) { | |||
super.inject(dagger, filterConfig); | |||
this.settings = dagger.get(IStoredSettings.class); | |||
this.runtimeManager = dagger.get(IRuntimeManager.class); | |||
@Inject | |||
public RpcFilter( | |||
IStoredSettings settings, | |||
IRuntimeManager runtimeManager, | |||
IAuthenticationManager authenticationManager) { | |||
super(authenticationManager); | |||
this.settings = settings; | |||
this.runtimeManager = runtimeManager; | |||
} | |||
/** |
@@ -23,6 +23,8 @@ import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
@@ -47,13 +49,12 @@ import com.gitblit.utils.JGitUtils; | |||
import com.gitblit.utils.RpcUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import dagger.ObjectGraph; | |||
/** | |||
* Handles remote procedure calls. | |||
* | |||
* @author James Moger | |||
*/ | |||
@Singleton | |||
public class RpcServlet extends JsonServlet { | |||
private static final long serialVersionUID = 1L; | |||
@@ -64,10 +65,10 @@ public class RpcServlet extends JsonServlet { | |||
private IGitblit gitblit; | |||
@Override | |||
protected void inject(ObjectGraph dagger) { | |||
this.settings = dagger.get(IStoredSettings.class); | |||
this.gitblit = dagger.get(IGitblit.class); | |||
@Inject | |||
public RpcServlet(IStoredSettings settings, IGitblit gitblit) { | |||
this.settings = settings; | |||
this.gitblit = gitblit; | |||
} | |||
/** |
@@ -19,13 +19,15 @@ import java.io.IOException; | |||
import java.net.URL; | |||
import java.text.MessageFormat; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.dagger.DaggerServlet; | |||
import com.gitblit.manager.IAuthenticationManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IUserManager; | |||
@@ -33,15 +35,14 @@ import com.gitblit.models.RepositoryModel; | |||
import com.gitblit.models.UserModel; | |||
import com.gitblit.utils.StringUtils; | |||
import dagger.ObjectGraph; | |||
/** | |||
* Handles requests for Sparkleshare Invites | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
public class SparkleShareInviteServlet extends DaggerServlet { | |||
@Singleton | |||
public class SparkleShareInviteServlet extends HttpServlet { | |||
private static final long serialVersionUID = 1L; | |||
@@ -53,12 +54,17 @@ public class SparkleShareInviteServlet extends DaggerServlet { | |||
private IRepositoryManager repositoryManager; | |||
@Override | |||
protected void inject(ObjectGraph dagger) { | |||
this.settings = dagger.get(IStoredSettings.class); | |||
this.userManager = dagger.get(IUserManager.class); | |||
this.authenticationManager = dagger.get(IAuthenticationManager.class); | |||
this.repositoryManager = dagger.get(IRepositoryManager.class); | |||
@Inject | |||
public SparkleShareInviteServlet( | |||
IStoredSettings settings, | |||
IUserManager userManager, | |||
IAuthenticationManager authenticationManager, | |||
IRepositoryManager repositoryManager) { | |||
this.settings = settings; | |||
this.userManager = userManager; | |||
this.authenticationManager = authenticationManager; | |||
this.repositoryManager = repositoryManager; | |||
} | |||
@Override |
@@ -18,8 +18,9 @@ package com.gitblit.servlet; | |||
import java.io.IOException; | |||
import java.text.MessageFormat; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.FilterChain; | |||
import javax.servlet.FilterConfig; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.ServletRequest; | |||
import javax.servlet.ServletResponse; | |||
@@ -27,6 +28,7 @@ import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import com.gitblit.Constants.AccessRestrictionType; | |||
import com.gitblit.manager.IAuthenticationManager; | |||
import com.gitblit.manager.IProjectManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
@@ -34,8 +36,6 @@ import com.gitblit.models.ProjectModel; | |||
import com.gitblit.models.RepositoryModel; | |||
import com.gitblit.models.UserModel; | |||
import dagger.ObjectGraph; | |||
/** | |||
* The SyndicationFilter is an AuthenticationFilter which ensures that feed | |||
* requests for projects or view-restricted repositories have proper authentication | |||
@@ -44,18 +44,24 @@ import dagger.ObjectGraph; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class SyndicationFilter extends AuthenticationFilter { | |||
private IRuntimeManager runtimeManager; | |||
private IRepositoryManager repositoryManager; | |||
private IProjectManager projectManager; | |||
@Override | |||
protected void inject(ObjectGraph dagger, FilterConfig filterConfig) { | |||
super.inject(dagger, filterConfig); | |||
this.runtimeManager = dagger.get(IRuntimeManager.class); | |||
this.repositoryManager = dagger.get(IRepositoryManager.class); | |||
this.projectManager = dagger.get(IProjectManager.class); | |||
@Inject | |||
public SyndicationFilter( | |||
IRuntimeManager runtimeManager, | |||
IAuthenticationManager authenticationManager, | |||
IRepositoryManager repositoryManager, | |||
IProjectManager projectManager) { | |||
super(authenticationManager); | |||
this.runtimeManager = runtimeManager; | |||
this.repositoryManager = repositoryManager; | |||
this.projectManager = projectManager; | |||
} | |||
/** |
@@ -22,6 +22,10 @@ import java.util.Collections; | |||
import java.util.List; | |||
import java.util.Map; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.http.HttpServlet; | |||
import org.eclipse.jgit.lib.ObjectId; | |||
import org.eclipse.jgit.lib.Repository; | |||
import org.eclipse.jgit.revwalk.RevCommit; | |||
@@ -31,7 +35,6 @@ import org.slf4j.LoggerFactory; | |||
import com.gitblit.Constants; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.dagger.DaggerServlet; | |||
import com.gitblit.manager.IProjectManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.models.FeedEntryModel; | |||
@@ -46,8 +49,6 @@ import com.gitblit.utils.JGitUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import com.gitblit.utils.SyndicationUtils; | |||
import dagger.ObjectGraph; | |||
/** | |||
* SyndicationServlet generates RSS 2.0 feeds and feed links. | |||
* | |||
@@ -56,7 +57,8 @@ import dagger.ObjectGraph; | |||
* @author James Moger | |||
* | |||
*/ | |||
public class SyndicationServlet extends DaggerServlet { | |||
@Singleton | |||
public class SyndicationServlet extends HttpServlet { | |||
private static final long serialVersionUID = 1L; | |||
@@ -68,11 +70,15 @@ public class SyndicationServlet extends DaggerServlet { | |||
private IProjectManager projectManager; | |||
@Override | |||
protected void inject(ObjectGraph dagger) { | |||
this.settings = dagger.get(IStoredSettings.class); | |||
this.repositoryManager = dagger.get(IRepositoryManager.class); | |||
this.projectManager = dagger.get(IProjectManager.class); | |||
@Inject | |||
public SyndicationServlet( | |||
IStoredSettings settings, | |||
IRepositoryManager repositoryManager, | |||
IProjectManager projectManager) { | |||
this.settings = settings; | |||
this.repositoryManager = repositoryManager; | |||
this.projectManager = projectManager; | |||
} | |||
/** |
@@ -72,6 +72,8 @@ import com.gitblit.models.TicketModel.Change; | |||
import com.gitblit.utils.ArrayUtils; | |||
import com.gitblit.utils.JGitUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
/** | |||
* Implementation of a ticket service based on an orphan branch. All tickets | |||
@@ -81,6 +83,7 @@ import com.gitblit.utils.StringUtils; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class BranchTicketService extends ITicketService implements RefsChangedListener { | |||
public static final String BRANCH = "refs/meta/gitblit/tickets"; | |||
@@ -91,6 +94,7 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi | |||
private final Map<String, AtomicLong> lastAssignedId; | |||
@Inject | |||
public BranchTicketService( | |||
IRuntimeManager runtimeManager, | |||
IPluginManager pluginManager, | |||
@@ -112,6 +116,7 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi | |||
@Override | |||
public BranchTicketService start() { | |||
log.info("{} started", getClass().getSimpleName()); | |||
return this; | |||
} | |||
@@ -42,6 +42,8 @@ import com.gitblit.models.TicketModel.Change; | |||
import com.gitblit.utils.ArrayUtils; | |||
import com.gitblit.utils.FileUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
/** | |||
* Implementation of a ticket service based on a directory within the repository. | |||
@@ -51,6 +53,7 @@ import com.gitblit.utils.StringUtils; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class FileTicketService extends ITicketService { | |||
private static final String JOURNAL = "journal.json"; | |||
@@ -59,6 +62,7 @@ public class FileTicketService extends ITicketService { | |||
private final Map<String, AtomicLong> lastAssignedId; | |||
@Inject | |||
public FileTicketService( | |||
IRuntimeManager runtimeManager, | |||
IPluginManager pluginManager, | |||
@@ -77,6 +81,7 @@ public class FileTicketService extends ITicketService { | |||
@Override | |||
public FileTicketService start() { | |||
log.info("{} started", getClass().getSimpleName()); | |||
return this; | |||
} | |||
@@ -36,6 +36,7 @@ import org.slf4j.LoggerFactory; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.extensions.TicketHook; | |||
import com.gitblit.manager.IManager; | |||
import com.gitblit.manager.INotificationManager; | |||
import com.gitblit.manager.IPluginManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
@@ -63,7 +64,7 @@ import com.google.common.cache.CacheBuilder; | |||
* @author James Moger | |||
* | |||
*/ | |||
public abstract class ITicketService { | |||
public abstract class ITicketService implements IManager { | |||
public static final String SETTING_UPDATE_DIFFSTATS = "migration.updateDiffstats"; | |||
@@ -176,12 +177,14 @@ public abstract class ITicketService { | |||
* Start the service. | |||
* @since 1.4.0 | |||
*/ | |||
@Override | |||
public abstract ITicketService start(); | |||
/** | |||
* Stop the service. | |||
* @since 1.4.0 | |||
*/ | |||
@Override | |||
public final ITicketService stop() { | |||
indexer.close(); | |||
ticketsCache.invalidateAll(); |
@@ -28,6 +28,8 @@ import com.gitblit.models.RepositoryModel; | |||
import com.gitblit.models.TicketModel; | |||
import com.gitblit.models.TicketModel.Attachment; | |||
import com.gitblit.models.TicketModel.Change; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
/** | |||
* Implementation of a ticket service that rejects everything. | |||
@@ -35,8 +37,10 @@ import com.gitblit.models.TicketModel.Change; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class NullTicketService extends ITicketService { | |||
@Inject | |||
public NullTicketService( | |||
IRuntimeManager runtimeManager, | |||
IPluginManager pluginManager, | |||
@@ -58,6 +62,7 @@ public class NullTicketService extends ITicketService { | |||
@Override | |||
public NullTicketService start() { | |||
log.info("{} started", getClass().getSimpleName()); | |||
return this; | |||
} | |||
@@ -43,6 +43,8 @@ import com.gitblit.models.TicketModel.Attachment; | |||
import com.gitblit.models.TicketModel.Change; | |||
import com.gitblit.utils.ArrayUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
/** | |||
* Implementation of a ticket service based on a Redis key-value store. All | |||
@@ -53,6 +55,7 @@ import com.gitblit.utils.StringUtils; | |||
* @author James Moger | |||
* | |||
*/ | |||
@Singleton | |||
public class RedisTicketService extends ITicketService { | |||
private final JedisPool pool; | |||
@@ -61,6 +64,7 @@ public class RedisTicketService extends ITicketService { | |||
journal, ticket, counter | |||
} | |||
@Inject | |||
public RedisTicketService( | |||
IRuntimeManager runtimeManager, | |||
IPluginManager pluginManager, | |||
@@ -80,6 +84,10 @@ public class RedisTicketService extends ITicketService { | |||
@Override | |||
public RedisTicketService start() { | |||
log.info("{} started", getClass().getSimpleName()); | |||
if (!isReady()) { | |||
log.warn("{} is not ready!", getClass().getSimpleName()); | |||
} | |||
return this; | |||
} | |||
@@ -29,6 +29,7 @@ import com.gitblit.manager.IRuntimeManager; | |||
import com.google.common.base.Charsets; | |||
import com.google.common.base.Joiner; | |||
import com.google.common.io.Files; | |||
import com.google.inject.Inject; | |||
/** | |||
* Manages public keys on the filesystem. | |||
@@ -42,6 +43,7 @@ public class FileKeyManager extends IPublicKeyManager { | |||
protected final Map<File, Long> lastModifieds; | |||
@Inject | |||
public FileKeyManager(IRuntimeManager runtimeManager) { | |||
this.runtimeManager = runtimeManager; | |||
this.lastModifieds = new ConcurrentHashMap<File, Long>(); |
@@ -20,6 +20,8 @@ import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import com.google.inject.Inject; | |||
/** | |||
* Memory public key manager. | |||
* | |||
@@ -30,6 +32,7 @@ public class MemoryKeyManager extends IPublicKeyManager { | |||
final Map<String, List<SshKey>> keys; | |||
@Inject | |||
public MemoryKeyManager() { | |||
keys = new HashMap<String, List<SshKey>>(); | |||
} |
@@ -17,6 +17,8 @@ package com.gitblit.transport.ssh; | |||
import java.util.List; | |||
import com.google.inject.Inject; | |||
/** | |||
* Rejects all public key management requests. | |||
* | |||
@@ -25,6 +27,7 @@ import java.util.List; | |||
*/ | |||
public class NullKeyManager extends IPublicKeyManager { | |||
@Inject | |||
public NullKeyManager() { | |||
} | |||
@@ -43,6 +43,7 @@ import com.gitblit.manager.IPluginManager; | |||
import com.gitblit.manager.IProjectManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.manager.IServicesManager; | |||
import com.gitblit.manager.IUserManager; | |||
import com.gitblit.tickets.ITicketService; | |||
import com.gitblit.transport.ssh.IPublicKeyManager; | |||
@@ -89,7 +90,11 @@ import com.gitblit.wicket.pages.TicketsPage; | |||
import com.gitblit.wicket.pages.TreePage; | |||
import com.gitblit.wicket.pages.UserPage; | |||
import com.gitblit.wicket.pages.UsersPage; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Provider; | |||
import com.google.inject.Singleton; | |||
@Singleton | |||
public class GitBlitWebApp extends WebApplication implements GitblitWicketApp { | |||
private final Class<? extends WebPage> homePageClass = MyDashboardPage.class; | |||
@@ -98,6 +103,10 @@ public class GitBlitWebApp extends WebApplication implements GitblitWicketApp { | |||
private final Map<String, CacheControl> cacheablePages = new HashMap<String, CacheControl>(); | |||
private final Provider<IPublicKeyManager> publicKeyManagerProvider; | |||
private final Provider<ITicketService> ticketServiceProvider; | |||
private final IStoredSettings settings; | |||
private final IRuntimeManager runtimeManager; | |||
@@ -110,8 +119,6 @@ public class GitBlitWebApp extends WebApplication implements GitblitWicketApp { | |||
private final IAuthenticationManager authenticationManager; | |||
private final IPublicKeyManager publicKeyManager; | |||
private final IRepositoryManager repositoryManager; | |||
private final IProjectManager projectManager; | |||
@@ -120,30 +127,37 @@ public class GitBlitWebApp extends WebApplication implements GitblitWicketApp { | |||
private final IGitblit gitblit; | |||
private final IServicesManager services; | |||
@Inject | |||
public GitBlitWebApp( | |||
Provider<IPublicKeyManager> publicKeyManagerProvider, | |||
Provider<ITicketService> ticketServiceProvider, | |||
IRuntimeManager runtimeManager, | |||
IPluginManager pluginManager, | |||
INotificationManager notificationManager, | |||
IUserManager userManager, | |||
IAuthenticationManager authenticationManager, | |||
IPublicKeyManager publicKeyManager, | |||
IRepositoryManager repositoryManager, | |||
IProjectManager projectManager, | |||
IFederationManager federationManager, | |||
IGitblit gitblit) { | |||
IGitblit gitblit, | |||
IServicesManager services) { | |||
super(); | |||
this.publicKeyManagerProvider = publicKeyManagerProvider; | |||
this.ticketServiceProvider = ticketServiceProvider; | |||
this.settings = runtimeManager.getSettings(); | |||
this.runtimeManager = runtimeManager; | |||
this.pluginManager = pluginManager; | |||
this.notificationManager = notificationManager; | |||
this.userManager = userManager; | |||
this.authenticationManager = authenticationManager; | |||
this.publicKeyManager = publicKeyManager; | |||
this.repositoryManager = repositoryManager; | |||
this.projectManager = projectManager; | |||
this.federationManager = federationManager; | |||
this.gitblit = gitblit; | |||
this.services = services; | |||
} | |||
@Override | |||
@@ -380,7 +394,7 @@ public class GitBlitWebApp extends WebApplication implements GitblitWicketApp { | |||
*/ | |||
@Override | |||
public IPublicKeyManager keys() { | |||
return publicKeyManager; | |||
return publicKeyManagerProvider.get(); | |||
} | |||
/* (non-Javadoc) | |||
@@ -415,12 +429,20 @@ public class GitBlitWebApp extends WebApplication implements GitblitWicketApp { | |||
return gitblit; | |||
} | |||
/* (non-Javadoc) | |||
* @see com.gitblit.wicket.Webapp#services() | |||
*/ | |||
@Override | |||
public IServicesManager services() { | |||
return services; | |||
} | |||
/* (non-Javadoc) | |||
* @see com.gitblit.wicket.Webapp#tickets() | |||
*/ | |||
@Override | |||
public ITicketService tickets() { | |||
return gitblit.getTicketService(); | |||
return ticketServiceProvider.get(); | |||
} | |||
/* (non-Javadoc) |
@@ -14,6 +14,7 @@ import com.gitblit.manager.IPluginManager; | |||
import com.gitblit.manager.IProjectManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.manager.IServicesManager; | |||
import com.gitblit.manager.IUserManager; | |||
import com.gitblit.tickets.ITicketService; | |||
import com.gitblit.transport.ssh.IPublicKeyManager; | |||
@@ -65,6 +66,8 @@ public interface GitblitWicketApp { | |||
public abstract IGitblit gitblit(); | |||
public abstract IServicesManager services(); | |||
public abstract ITicketService tickets(); | |||
public abstract TimeZone getTimezone(); |
@@ -17,6 +17,8 @@ package com.gitblit.wicket; | |||
import java.util.Date; | |||
import com.google.inject.Inject; | |||
import com.google.inject.Singleton; | |||
import javax.servlet.http.HttpServletRequest; | |||
import org.apache.wicket.protocol.http.IWebApplicationFactory; | |||
@@ -28,7 +30,6 @@ import org.eclipse.jgit.revwalk.RevCommit; | |||
import com.gitblit.IStoredSettings; | |||
import com.gitblit.Keys; | |||
import com.gitblit.dagger.DaggerWicketFilter; | |||
import com.gitblit.manager.IProjectManager; | |||
import com.gitblit.manager.IRepositoryManager; | |||
import com.gitblit.manager.IRuntimeManager; | |||
@@ -37,8 +38,6 @@ import com.gitblit.models.RepositoryModel; | |||
import com.gitblit.utils.JGitUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import dagger.ObjectGraph; | |||
/** | |||
* | |||
* Customization of the WicketFilter to allow smart browser-side caching of | |||
@@ -47,7 +46,8 @@ import dagger.ObjectGraph; | |||
* @author James Moger | |||
* | |||
*/ | |||
public class GitblitWicketFilter extends DaggerWicketFilter { | |||
@Singleton | |||
public class GitblitWicketFilter extends WicketFilter { | |||
private IStoredSettings settings; | |||
@@ -59,13 +59,19 @@ public class GitblitWicketFilter extends DaggerWicketFilter { | |||
private GitBlitWebApp webapp; | |||
@Override | |||
protected void inject(ObjectGraph dagger) { | |||
this.settings = dagger.get(IStoredSettings.class); | |||
this.runtimeManager = dagger.get(IRuntimeManager.class); | |||
this.repositoryManager = dagger.get(IRepositoryManager.class); | |||
this.projectManager = dagger.get(IProjectManager.class); | |||
this.webapp = dagger.get(GitBlitWebApp.class); | |||
@Inject | |||
public GitblitWicketFilter( | |||
IStoredSettings settings, | |||
IRuntimeManager runtimeManager, | |||
IRepositoryManager repositoryManager, | |||
IProjectManager projectManager, | |||
GitBlitWebApp webapp) { | |||
this.settings = settings; | |||
this.runtimeManager = runtimeManager; | |||
this.repositoryManager = repositoryManager; | |||
this.projectManager = projectManager; | |||
this.webapp = webapp; | |||
} | |||
@Override |
@@ -55,7 +55,7 @@ public class EmptyRepositoryPage extends RepositoryPage { | |||
} | |||
HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest(); | |||
List<RepositoryUrl> repositoryUrls = app().gitblit().getRepositoryUrls(req, user, repository); | |||
List<RepositoryUrl> repositoryUrls = app().services().getRepositoryUrls(req, user, repository); | |||
RepositoryUrl primaryUrl = repositoryUrls.size() == 0 ? null : repositoryUrls.get(0); | |||
String url = primaryUrl != null ? primaryUrl.url : ""; | |||
@@ -1505,7 +1505,7 @@ public class TicketPage extends RepositoryPage { | |||
*/ | |||
protected RepositoryUrl getRepositoryUrl(UserModel user, RepositoryModel repository) { | |||
HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest(); | |||
List<RepositoryUrl> urls = app().gitblit().getRepositoryUrls(req, user, repository); | |||
List<RepositoryUrl> urls = app().services().getRepositoryUrls(req, user, repository); | |||
if (ArrayUtils.isEmpty(urls)) { | |||
return null; | |||
} |
@@ -104,7 +104,7 @@ public class UserPage extends RootPage { | |||
if (isMyProfile) { | |||
addPreferences(user); | |||
if (app().gitblit().isServingSSH()) { | |||
if (app().services().isServingSSH()) { | |||
// show the SSH key management tab | |||
addSshKeys(user); | |||
} else { | |||
@@ -248,14 +248,14 @@ public class UserPage extends RootPage { | |||
emailMeOnMyTicketChanges).setVisible(app().notifier().isSendingMail())); | |||
List<Transport> availableTransports = new ArrayList<>(); | |||
if (app().gitblit().isServingSSH()) { | |||
if (app().services().isServingSSH()) { | |||
availableTransports.add(Transport.SSH); | |||
} | |||
if (app().gitblit().isServingHTTP()) { | |||
if (app().services().isServingHTTP()) { | |||
availableTransports.add(Transport.HTTPS); | |||
availableTransports.add(Transport.HTTP); | |||
} | |||
if (app().gitblit().isServingGIT()) { | |||
if (app().services().isServingGIT()) { | |||
availableTransports.add(Transport.GIT); | |||
} | |||
@@ -80,7 +80,7 @@ public class RepositoryUrlPanel extends BasePanel { | |||
HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest(); | |||
List<RepositoryUrl> repositoryUrls = app().gitblit().getRepositoryUrls(req, user, repository); | |||
List<RepositoryUrl> repositoryUrls = app().services().getRepositoryUrls(req, user, repository); | |||
// grab primary url from the top of the list | |||
primaryUrl = repositoryUrls.size() == 0 ? null : repositoryUrls.get(0); | |||
@@ -165,7 +165,7 @@ public class RepositoryUrlPanel extends BasePanel { | |||
if (repository.isMirror) { | |||
urlPanel.add(WicketUtils.newImage("accessRestrictionIcon", "mirror_16x16.png", | |||
getString("gb.isMirror"))); | |||
} else if (app().gitblit().isServingRepositories()) { | |||
} else if (app().services().isServingRepositories()) { | |||
switch (repository.accessRestriction) { | |||
case NONE: | |||
urlPanel.add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false)); |
@@ -57,6 +57,7 @@ The following dependencies are automatically downloaded by Gitblit GO (or alread | |||
- [jedis](https://github.com/xetorthio/jedis) (MIT) | |||
- [Mina SSHD](https://mina.apache.org) (Apache 2.0) | |||
- [pf4j](https://github.com/decebals/pf4j) (Apache 2.0) | |||
- [google-guice](https://code.google.com/p/google-guice) (Apache 2.0) | |||
### Other Build Dependencies | |||
- [Fancybox image viewer](http://fancybox.net) (MIT and GPL dual-licensed) |
@@ -28,6 +28,7 @@ import com.gitblit.manager.IRuntimeManager; | |||
import com.gitblit.models.ServerSettings; | |||
import com.gitblit.models.ServerStatus; | |||
import com.gitblit.models.SettingModel; | |||
import com.google.inject.Injector; | |||
public class MockRuntimeManager implements IRuntimeManager { | |||
@@ -56,6 +57,11 @@ public class MockRuntimeManager implements IRuntimeManager { | |||
this.serverSettings = new ServerSettings(); | |||
} | |||
@Override | |||
public Injector getInjector() { | |||
return null; | |||
} | |||
@Override | |||
public void setBaseFolder(File folder) { | |||
this.baseFolder = folder; | |||
@@ -76,26 +82,6 @@ public class MockRuntimeManager implements IRuntimeManager { | |||
return Locale.getDefault(); | |||
} | |||
@Override | |||
public boolean isServingRepositories() { | |||
return true; | |||
} | |||
@Override | |||
public boolean isServingHTTP() { | |||
return true; | |||
} | |||
@Override | |||
public boolean isServingGIT() { | |||
return true; | |||
} | |||
@Override | |||
public boolean isServingSSH() { | |||
return true; | |||
} | |||
@Override | |||
public boolean isDebugMode() { | |||
return true; |