*.directory\r
/.gradle
/projects.conf
+/pom.xml
<property name="project.build.dir" value="${basedir}/build" />\r
<property name="project.deploy.dir" value="${basedir}/deploy" />\r
<property name="project.war.dir" value="${basedir}/war" />\r
+ <property name="project.jar.dir" value="${basedir}/jar" />\r
<property name="project.site.dir" value="${basedir}/site" />\r
<property name="project.resources.dir" value="${basedir}/resources" /> \r
<property name="project.express.dir" value="${basedir}/express" />\r
+ <property name="project.maven.repo.url" value="enter here your Maven repo URL" />\r
+ <property name="project.maven.repo.id" value="gitblit.maven.repo" />\r
<available property="hasBuildProps" file="${basedir}/build.properties"/>\r
\r
<!--\r
</loadfile> \r
<property name="distribution.zipfile" value="gitblit-${gb.version}.zip" />\r
<property name="distribution.warfile" value="gitblit-${gb.version}.war" />\r
+ <property name="distribution.jarfile" value="gitblit-${gb.version}.jar" />\r
+ <property name="distribution.pomfile" value="${basedir}/pom.xml" />\r
<property name="fedclient.zipfile" value="fedclient-${gb.version}.zip" />\r
<property name="manager.zipfile" value="manager-${gb.version}.zip" />\r
<property name="gbapi.zipfile" value="gbapi-${gb.version}.zip" />\r
</target>\r
\r
\r
+ <!--\r
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+ Build Gitblit JAR for usage in other projects plug-ins (i.e. Gerrit)\r
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+ -->\r
+ <target name="buildJAR" depends="compile" description="Build Gitblit JAR">\r
+\r
+ <echo>Building Gitblit JAR ${gb.version}</echo>\r
+\r
+ <delete dir="${project.jar.dir}" />\r
+\r
+ <!-- Gitblit classes -->\r
+ <mkdir dir="${project.jar.dir}"/>\r
+ <copy todir="${project.jar.dir}">\r
+ <fileset dir="${project.build.dir}">\r
+ <exclude name="WEB-INF/" />\r
+ <exclude name="com/gitblit/tests/" />\r
+ <exclude name="com/gitblit/build/**" />\r
+ <exclude name="com/gitblit/client/**" />\r
+ <exclude name="com/gitblit/AddIndexedBranch*.class" />\r
+ <exclude name="com/gitblit/GitBlitServer*.class" />\r
+ <exclude name="com/gitblit/Launcher*.class" />\r
+ <exclude name="com/gitblit/MakeCertificate*.class" />\r
+ </fileset>\r
+ </copy>\r
+\r
+ <!-- Build the JAR file -->\r
+ <jar basedir="${project.jar.dir}" destfile="${distribution.jarfile}" compress="true" />\r
+ </target>\r
+\r
+ <!--\r
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+ Build pom.xml for GitBlit JAR Maven module\r
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+ -->\r
+ <target name="buildMaven" depends="buildJAR" description="Build pom.xml for Gitblit JAR Maven module">\r
+ <copy tofile="${distribution.pomfile}" file="${distribution.pomfileTmplt}"/>\r
+ <replace file="${distribution.pomfile}" token="@gb.version@" value="${gb.version}" />\r
+ </target>\r
+\r
+ <!--\r
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+ Install Gitblit JAR for usage as Maven module\r
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+ -->\r
+ <target name="installMaven" depends="buildMaven" description="Install Gitblit JAR as Maven module">\r
+ <exec executable="mvn">\r
+ <arg value="install:install-file" />\r
+ <arg value="-Dfile=${distribution.jarfile}" />\r
+ <arg value="-DpomFile=${distribution.pomfile}" />\r
+ <arg value="-DcreateChecksum=true" />\r
+ </exec>\r
+ </target>\r
+\r
+ <!--\r
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+ Upload Gitblit JAR to remote Maven repository\r
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+ -->\r
+ <target name="uploadMaven" depends="buildJAR" description="Upload Gitblit JAR to remote Maven repository">\r
+ <exec executable="mvn">\r
+ <arg value="deploy:deploy-file" />\r
+ <arg value="-Dfile=${distribution.jarfile}" />\r
+ <arg value="-DpomFile=${distribution.pomfile}" />\r
+ <arg value="-Durl=${project.maven.repo.url}" />\r
+ <arg value="-DrepositoryId=${project.maven.repo.id}" />\r
+ <arg value="-DcreateChecksum=true" />\r
+ </exec>\r
+ </target>\r
+\r
<!-- \r
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
Build the stand-alone, command-line Gitblit Federation Client\r
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.gitblit</groupId>
+ <artifactId>gitblit</artifactId>
+ <version>1.1.0</version>
+</project>
import javax.servlet.ServletContextEvent;\r
import javax.servlet.ServletContextListener;\r
import javax.servlet.http.Cookie;\r
+import javax.servlet.http.HttpServletRequest;\r
\r
import org.apache.wicket.protocol.http.WebResponse;\r
+import org.apache.wicket.resource.ContextRelativeResource;\r
+import org.apache.wicket.util.resource.ResourceStreamNotFoundException;\r
import org.eclipse.jgit.lib.Repository;\r
import org.eclipse.jgit.lib.RepositoryCache;\r
import org.eclipse.jgit.lib.RepositoryCache.FileKey;\r
import com.gitblit.utils.MetricUtils;\r
import com.gitblit.utils.ObjectCache;\r
import com.gitblit.utils.StringUtils;\r
+import com.gitblit.wicket.WicketUtils;\r
\r
/**\r
* GitBlit is the servlet context listener singleton that acts as the core for\r
}\r
}\r
\r
+ public GitBlit(final IUserService userService) {\r
+ this.userService = userService;\r
+ gitblit = this;\r
+ }\r
+\r
/**\r
* Returns the Gitblit singleton.\r
* \r
return null;\r
}\r
\r
+ /**\r
+ * Authenticate a user based on HTTP request paramters.\r
+ * This method is inteded to be used as fallback when other\r
+ * means of authentication are failing (username / password or cookies).\r
+ * @param httpRequest\r
+ * @return a user object or null\r
+ */\r
+ public UserModel authenticate(HttpServletRequest httpRequest) {\r
+ return null;\r
+ }\r
+\r
+ /**\r
+ * Open a file resource using the Servlet container.\r
+ * @param file to open\r
+ * @return InputStream of the opened file\r
+ * @throws ResourceStreamNotFoundException\r
+ */\r
+ public InputStream getResourceAsStream(String file) throws ResourceStreamNotFoundException {\r
+ ContextRelativeResource res = WicketUtils.getResource(file);\r
+ return res.getResourceStream().getInputStream();\r
+ }\r
+\r
/**\r
* Sets a cookie for the specified user.\r
* \r
* Parse the properties file and aggregate all the comments by the setting\r
* key. A setting model tracks the current value, the default value, the\r
* description of the setting and and directives about the setting.\r
+ * @param referencePropertiesInputStream\r
* \r
* @return Map<String, SettingModel>\r
*/\r
- private ServerSettings loadSettingModels() {\r
+ private ServerSettings loadSettingModels(InputStream referencePropertiesInputStream) {\r
ServerSettings settingsModel = new ServerSettings();\r
settingsModel.supportsCredentialChanges = userService.supportsCredentialChanges();\r
settingsModel.supportsDisplayNameChanges = userService.supportsDisplayNameChanges();\r
// Read bundled Gitblit properties to extract setting descriptions.\r
// This copy is pristine and only used for populating the setting\r
// models map.\r
- InputStream is = servletContext.getResourceAsStream("/WEB-INF/reference.properties");\r
+ InputStream is = referencePropertiesInputStream;\r
BufferedReader propertiesReader = new BufferedReader(new InputStreamReader(is));\r
StringBuilder description = new StringBuilder();\r
SettingModel setting = new SettingModel();\r
logTimezone(Constants.NAME, getTimezone());\r
\r
serverStatus = new ServerStatus(isGO());\r
- String realm = settings.getString(Keys.realm.userService, "users.properties");\r
- IUserService loginService = null;\r
- try {\r
- // check to see if this "file" is a login service class\r
- Class<?> realmClass = Class.forName(realm);\r
- loginService = (IUserService) realmClass.newInstance();\r
- } catch (Throwable t) {\r
- loginService = new GitblitUserService();\r
+\r
+ if (this.userService == null) {\r
+ String realm = settings.getString(Keys.realm.userService, "users.properties");\r
+ IUserService loginService = null;\r
+ try {\r
+ // check to see if this "file" is a login service class\r
+ Class<?> realmClass = Class.forName(realm);\r
+ loginService = (IUserService) realmClass.newInstance();\r
+ } catch (Throwable t) {\r
+ loginService = new GitblitUserService();\r
+ }\r
+ setUserService(loginService);\r
}\r
- setUserService(loginService);\r
\r
// load and cache the project metadata\r
projectConfigs = new FileBasedConfig(getFileOrFolder(Keys.web.projectsFile, "projects.conf"), FS.detect());\r
getProjectConfigs();\r
- \r
mailExecutor = new MailExecutor(settings);\r
if (mailExecutor.isReady()) {\r
logger.info("Mail executor is scheduled to process the message queue every 2 minutes.");\r
*/\r
@Override\r
public void contextInitialized(ServletContextEvent contextEvent) {\r
+ contextInitialized(contextEvent, contextEvent.getServletContext().getResourceAsStream("/WEB-INF/reference.properties"));\r
+ }\r
+\r
+ public void contextInitialized(ServletContextEvent contextEvent, InputStream referencePropertiesInputStream) {\r
servletContext = contextEvent.getServletContext();\r
if (settings == null) {\r
// Gitblit WAR is running in a servlet container\r
}\r
}\r
\r
- settingsModel = loadSettingModels();\r
+ settingsModel = loadSettingModels(referencePropertiesInputStream);\r
serverStatus.servletContainer = servletContext.getServerInfo();\r
}\r
\r
addToCachedRepositoryList(cloneModel);\r
return cloneModel;\r
}\r
+\r
+ /**\r
+ * Allow to understand if GitBlit supports and is configured to allow\r
+ * cookie-based authentication.\r
+ * \r
+ * @return status of Cookie authentication enablement.\r
+ */\r
+ public boolean allowCookieAuthentication() {\r
+ return GitBlit.getBoolean(Keys.web.allowCookieAuthentication, true) && userService.supportsCookies();\r
+ }\r
}\r
return permission;\r
}\r
\r
- private boolean canAccess(RepositoryModel repository, AccessRestrictionType ifRestriction, AccessPermission requirePermission) {\r
+ protected boolean canAccess(RepositoryModel repository, AccessRestrictionType ifRestriction, AccessPermission requirePermission) {\r
if (repository.accessRestriction.atLeast(ifRestriction)) {\r
AccessPermission permission = getRepositoryPermission(repository);\r
return permission.atLeast(requirePermission);\r
}\r
return nameVerified && emailVerified;\r
}\r
+ \r
+ public boolean hasBranchPermission(String repositoryName, String branch) {\r
+ // Default UserModel doesn't implement branch-level security. Other Realms (i.e. Gerrit) may override this method.\r
+ return hasRepositoryPermission(repositoryName);\r
+ }\r
}\r
super();\r
logger = LoggerFactory.getLogger(getClass());\r
customizeHeader();\r
- loginByCookie();\r
+ login();\r
}\r
\r
public BasePage(PageParameters params) {\r
super(params);\r
logger = LoggerFactory.getLogger(getClass());\r
customizeHeader();\r
- loginByCookie();\r
+ login();\r
}\r
\r
private void customizeHeader() {\r
super.onAfterRender();\r
} \r
\r
- private void loginByCookie() {\r
- if (!GitBlit.getBoolean(Keys.web.allowCookieAuthentication, false)) {\r
- return;\r
- }\r
- UserModel user = null;\r
-\r
- // Grab cookie from Browser Session\r
+ private void login() {\r
Cookie[] cookies = ((WebRequest) getRequestCycle().getRequest()).getCookies();\r
- if (cookies != null && cookies.length > 0) {\r
+ UserModel user = null;\r
+ if (GitBlit.self().allowCookieAuthentication() && cookies != null && cookies.length > 0) {\r
+ // Grab cookie from Browser Session\r
user = GitBlit.self().authenticate(cookies);\r
+ } else {\r
+ user = GitBlit.self().authenticate(((WebRequest) getRequestCycle().getRequest()).getHttpServletRequest());\r
}\r
\r
// Login the user\r
\r
import java.io.File;\r
import java.io.FileInputStream;\r
-import java.io.FileNotFoundException;\r
import java.io.InputStream;\r
import java.io.InputStreamReader;\r
import java.text.MessageFormat;\r
}\r
String message;\r
try { \r
- ContextRelativeResource res = WicketUtils.getResource(file);\r
- InputStream is = res.getResourceStream().getInputStream();\r
+ InputStream is = GitBlit.self().getResourceAsStream(file);\r
InputStreamReader reader = new InputStreamReader(is, Constants.CHARACTER_ENCODING);\r
message = MarkdownUtils.transformMarkdown(reader);\r
reader.close();\r
import com.gitblit.PagesServlet;\r
import com.gitblit.SyndicationServlet;\r
import com.gitblit.models.ProjectModel;\r
+import com.gitblit.models.RefModel;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.SubmoduleModel;\r
import com.gitblit.models.UserModel;\r
}\r
objectId = WicketUtils.getObject(params);\r
\r
+ if (objectId != null) {\r
+ RefModel branch = null;\r
+ if ((branch = JGitUtils.getBranch(getRepository(), objectId)) != null) {\r
+ boolean canAccess = GitBlitWebSession\r
+ .get()\r
+ .getUser()\r
+ .hasBranchPermission(getRepositoryModel().name,\r
+ branch.reference.getName());\r
+ if (!canAccess) {\r
+ error("Access denied", true);\r
+ }\r
+ }\r
+ }\r
if (StringUtils.isEmpty(repositoryName)) {\r
error(MessageFormat.format(getString("gb.repositoryNotSpecifiedFor"), getPageName()), true);\r
}\r
getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));\r
}\r
}\r
-}
\ No newline at end of file
+}
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.gitblit</groupId>
+ <artifactId>gitblit</artifactId>
+ <version>@gb.version@</version>
+</project>