| | |
| | | /* |
| | | * Copyright 2011 gitblit.com. |
| | | * 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. |
| | |
| | | package com.gitblit; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.text.MessageFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Collection; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.TimeZone; |
| | | |
| | | import javax.naming.Context; |
| | | import javax.naming.InitialContext; |
| | | import javax.naming.NamingException; |
| | | import javax.servlet.ServletContext; |
| | | import javax.servlet.annotation.WebListener; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.gitblit.dagger.DaggerContextListener; |
| | | import com.gitblit.git.GitServlet; |
| | | import org.eclipse.jgit.lib.Repository; |
| | | |
| | | import com.gitblit.Constants.FederationRequest; |
| | | import com.gitblit.Constants.FederationToken; |
| | | import com.gitblit.manager.IAuthenticationManager; |
| | | import com.gitblit.manager.IFederationManager; |
| | | import com.gitblit.manager.IGitblitManager; |
| | | import com.gitblit.manager.IManager; |
| | | import com.gitblit.manager.INotificationManager; |
| | | import com.gitblit.manager.IProjectManager; |
| | | import com.gitblit.manager.IRepositoryManager; |
| | | import com.gitblit.manager.IRuntimeManager; |
| | | import com.gitblit.manager.IServicesManager; |
| | | import com.gitblit.manager.ISessionManager; |
| | | import com.gitblit.manager.IUserManager; |
| | | import com.gitblit.utils.ContainerUtils; |
| | | import com.gitblit.utils.StringUtils; |
| | | import com.gitblit.wicket.GitblitWicketFilter; |
| | | |
| | | import dagger.ObjectGraph; |
| | | import com.gitblit.models.FederationModel; |
| | | import com.gitblit.models.FederationProposal; |
| | | import com.gitblit.models.FederationSet; |
| | | import com.gitblit.models.ForkModel; |
| | | import com.gitblit.models.GitClientApplication; |
| | | import com.gitblit.models.Metric; |
| | | 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; |
| | | import com.gitblit.models.TeamModel; |
| | | import com.gitblit.models.UserModel; |
| | | |
| | | /** |
| | | * 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 followed by |
| | | * instantiating and registering all servlets and filters. |
| | | * |
| | | * Leveraging Servlet 3 and Dagger static dependency injection allows Gitblit to |
| | | * be modular and completely code-driven rather then relying on the fragility of |
| | | * a web.xml descriptor and the static & monolithic design previously used. |
| | | * GitBlit is an aggregate interface delegate. It implements all the manager |
| | | * interfaces and delegates all methods calls to the actual manager implementations. |
| | | * It's primary purpose is to provide complete management control to the git |
| | | * upload and receive pack functions. |
| | | * |
| | | * @author James Moger |
| | | * |
| | | */ |
| | | @WebListener |
| | | public class GitBlit extends DaggerContextListener { |
| | | public class GitBlit implements IRuntimeManager, |
| | | INotificationManager, |
| | | IUserManager, |
| | | IAuthenticationManager, |
| | | IRepositoryManager, |
| | | IProjectManager, |
| | | IGitblitManager, |
| | | IFederationManager { |
| | | |
| | | private static GitBlit gitblit; |
| | | private final IRuntimeManager runtimeManager; |
| | | |
| | | private final List<IManager> managers = new ArrayList<IManager>(); |
| | | private final INotificationManager notificationManager; |
| | | |
| | | private final IStoredSettings goSettings; |
| | | private final IUserManager userManager; |
| | | |
| | | private final File goBaseFolder; |
| | | private final IAuthenticationManager authenticationManager; |
| | | |
| | | /** |
| | | * Construct a Gitblit WAR/Express context. |
| | | */ |
| | | public GitBlit() { |
| | | this.goSettings = null; |
| | | this.goBaseFolder = null; |
| | | gitblit = this; |
| | | private final IRepositoryManager repositoryManager; |
| | | |
| | | private final IProjectManager projectManager; |
| | | |
| | | private final IGitblitManager gitblitManager; |
| | | |
| | | private final IFederationManager federationManager; |
| | | |
| | | public GitBlit( |
| | | IRuntimeManager runtimeManager, |
| | | INotificationManager notificationManager, |
| | | IUserManager userManager, |
| | | IAuthenticationManager authenticationManager, |
| | | IRepositoryManager repositoryManager, |
| | | IProjectManager projectManager, |
| | | IGitblitManager gitblitManager, |
| | | IFederationManager federationManager) { |
| | | |
| | | this.runtimeManager = runtimeManager; |
| | | this.notificationManager = notificationManager; |
| | | this.userManager = userManager; |
| | | this.authenticationManager = authenticationManager; |
| | | this.repositoryManager = repositoryManager; |
| | | this.projectManager = projectManager; |
| | | this.gitblitManager = gitblitManager; |
| | | this.federationManager = federationManager; |
| | | } |
| | | |
| | | /** |
| | | * Construct a Gitblit GO context. |
| | | * |
| | | * @param settings |
| | | * @param baseFolder |
| | | */ |
| | | public GitBlit(IStoredSettings settings, File baseFolder) { |
| | | this.goSettings = settings; |
| | | this.goBaseFolder = baseFolder; |
| | | gitblit = this; |
| | | } |
| | | |
| | | /** |
| | | * This method is only used for unit and integration testing. |
| | | * |
| | | * @param managerClass |
| | | * @return a manager |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public static <X extends IManager> X getManager(Class<X> managerClass) { |
| | | for (IManager manager : gitblit.managers) { |
| | | if (managerClass.isAssignableFrom(manager.getClass())) { |
| | | return (X) manager; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * Returns Gitblit's Dagger injection modules. |
| | | */ |
| | | @Override |
| | | protected Object [] getModules() { |
| | | return new Object [] { new DaggerModule() }; |
| | | public GitBlit start() { |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | | * Prepare runtime settings and start all manager instances. |
| | | */ |
| | | @Override |
| | | protected void beforeServletInjection(ServletContext context) { |
| | | ObjectGraph injector = getInjector(context); |
| | | |
| | | // create the runtime settings object |
| | | IStoredSettings runtimeSettings = injector.get(IStoredSettings.class); |
| | | final File baseFolder; |
| | | |
| | | if (goSettings != null) { |
| | | // Gitblit GO |
| | | baseFolder = configureGO(context, goSettings, goBaseFolder, runtimeSettings); |
| | | } else { |
| | | // servlet container |
| | | WebXmlSettings webxmlSettings = new WebXmlSettings(context); |
| | | String contextRealPath = context.getRealPath("/"); |
| | | File contextFolder = (contextRealPath != null) ? new File(contextRealPath) : null; |
| | | |
| | | if (!StringUtils.isEmpty(System.getenv("OPENSHIFT_DATA_DIR"))) { |
| | | // RedHat OpenShift |
| | | baseFolder = configureExpress(context, webxmlSettings, contextFolder, runtimeSettings); |
| | | } else { |
| | | // standard WAR |
| | | baseFolder = configureWAR(context, webxmlSettings, contextFolder, runtimeSettings); |
| | | } |
| | | |
| | | // Test for Tomcat forward-slash/%2F issue and auto-adjust settings |
| | | ContainerUtils.CVE_2007_0450.test(runtimeSettings); |
| | | } |
| | | |
| | | // Manually configure IRuntimeManager |
| | | logManager(IRuntimeManager.class); |
| | | IRuntimeManager runtime = injector.get(IRuntimeManager.class); |
| | | runtime.setBaseFolder(baseFolder); |
| | | runtime.getStatus().isGO = goSettings != null; |
| | | runtime.getStatus().servletContainer = context.getServerInfo(); |
| | | runtime.start(); |
| | | managers.add(runtime); |
| | | |
| | | // start all other managers |
| | | startManager(injector, INotificationManager.class); |
| | | startManager(injector, IUserManager.class); |
| | | startManager(injector, ISessionManager.class); |
| | | startManager(injector, IRepositoryManager.class); |
| | | startManager(injector, IProjectManager.class); |
| | | startManager(injector, IGitblitManager.class); |
| | | startManager(injector, IFederationManager.class); |
| | | startManager(injector, IServicesManager.class); |
| | | |
| | | logger.info(""); |
| | | logger.info("All managers started."); |
| | | logger.info(""); |
| | | public GitBlit stop() { |
| | | return this; |
| | | } |
| | | |
| | | protected <X extends IManager> X startManager(ObjectGraph injector, Class<X> clazz) { |
| | | logManager(clazz); |
| | | X x = injector.get(clazz); |
| | | x.start(); |
| | | managers.add(x); |
| | | return x; |
| | | } |
| | | |
| | | protected void logManager(Class<? extends IManager> clazz) { |
| | | logger.info(""); |
| | | logger.info("----[{}]----", clazz.getName()); |
| | | } |
| | | |
| | | /** |
| | | * Instantiate and inject all filters and servlets into the container using |
| | | * the servlet 3 specification. |
| | | /* |
| | | * ISTOREDSETTINGS |
| | | * |
| | | * these methods are necessary for (nearly) seamless Groovy hook operation |
| | | * after the massive refactor. |
| | | */ |
| | | |
| | | public boolean getBoolean(String key, boolean defaultValue) { |
| | | return runtimeManager.getSettings().getBoolean(key, defaultValue); |
| | | } |
| | | |
| | | public String getString(String key, String defaultValue) { |
| | | return runtimeManager.getSettings().getString(key, defaultValue); |
| | | } |
| | | |
| | | public int getInteger(String key, int defaultValue) { |
| | | return runtimeManager.getSettings().getInteger(key, defaultValue); |
| | | } |
| | | |
| | | public List<String> getStrings(String key) { |
| | | return runtimeManager.getSettings().getStrings(key); |
| | | } |
| | | |
| | | /* |
| | | * RUNTIME MANAGER |
| | | */ |
| | | |
| | | @Override |
| | | protected void injectServlets(ServletContext context) { |
| | | // access restricted servlets |
| | | serve(context, Constants.GIT_PATH, GitServlet.class, GitFilter.class); |
| | | serve(context, Constants.PAGES, PagesServlet.class, PagesFilter.class); |
| | | serve(context, Constants.RPC_PATH, RpcServlet.class, RpcFilter.class); |
| | | serve(context, Constants.ZIP_PATH, DownloadZipServlet.class, DownloadZipFilter.class); |
| | | serve(context, Constants.SYNDICATION_PATH, SyndicationServlet.class, SyndicationFilter.class); |
| | | |
| | | // servlets |
| | | serve(context, Constants.FEDERATION_PATH, FederationServlet.class); |
| | | serve(context, Constants.SPARKLESHARE_INVITE_PATH, SparkleShareInviteServlet.class); |
| | | serve(context, Constants.BRANCH_GRAPH_PATH, BranchGraphServlet.class); |
| | | file(context, "/robots.txt", RobotsTxtServlet.class); |
| | | file(context, "/logo.png", LogoServlet.class); |
| | | |
| | | // optional force basic authentication |
| | | filter(context, "/*", EnforceAuthenticationFilter.class, null); |
| | | |
| | | // Wicket |
| | | String toIgnore = StringUtils.flattenStrings(getRegisteredPaths(), ","); |
| | | Map<String, String> params = new HashMap<String, String>(); |
| | | params.put(GitblitWicketFilter.FILTER_MAPPING_PARAM, "/*"); |
| | | params.put(GitblitWicketFilter.IGNORE_PATHS_PARAM, toIgnore); |
| | | filter(context, "/*", GitblitWicketFilter.class, params); |
| | | public File getBaseFolder() { |
| | | return runtimeManager.getBaseFolder(); |
| | | } |
| | | |
| | | /** |
| | | * 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."); |
| | | for (IManager manager : managers) { |
| | | logger.debug("stopping {}", manager.getClass().getSimpleName()); |
| | | manager.stop(); |
| | | } |
| | | public void setBaseFolder(File folder) { |
| | | runtimeManager.setBaseFolder(folder); |
| | | } |
| | | |
| | | /** |
| | | * Configures Gitblit GO |
| | | * |
| | | * @param context |
| | | * @param settings |
| | | * @param baseFolder |
| | | * @param runtimeSettings |
| | | * @return the base folder |
| | | @Override |
| | | public Date getBootDate() { |
| | | return runtimeManager.getBootDate(); |
| | | } |
| | | |
| | | @Override |
| | | public ServerSettings getSettingsModel() { |
| | | return runtimeManager.getSettingsModel(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean isServingRepositories() { |
| | | return runtimeManager.isServingRepositories(); |
| | | } |
| | | |
| | | @Override |
| | | public TimeZone getTimezone() { |
| | | return runtimeManager.getTimezone(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean isDebugMode() { |
| | | return runtimeManager.isDebugMode(); |
| | | } |
| | | |
| | | @Override |
| | | public File getFileOrFolder(String key, String defaultFileOrFolder) { |
| | | return runtimeManager.getFileOrFolder(key, defaultFileOrFolder); |
| | | } |
| | | |
| | | @Override |
| | | public File getFileOrFolder(String fileOrFolder) { |
| | | return runtimeManager.getFileOrFolder(fileOrFolder); |
| | | } |
| | | |
| | | @Override |
| | | public IStoredSettings getSettings() { |
| | | return runtimeManager.getSettings(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateSettings(Map<String, String> updatedSettings) { |
| | | return runtimeManager.updateSettings(updatedSettings); |
| | | } |
| | | |
| | | @Override |
| | | public ServerStatus getStatus() { |
| | | return runtimeManager.getStatus(); |
| | | } |
| | | |
| | | /* |
| | | * NOTIFICATION MANAGER |
| | | */ |
| | | protected File configureGO( |
| | | ServletContext context, |
| | | IStoredSettings goSettings, |
| | | File goBaseFolder, |
| | | IStoredSettings runtimeSettings) { |
| | | |
| | | logger.debug("configuring Gitblit GO"); |
| | | |
| | | // merge the stored settings into the runtime settings |
| | | // |
| | | // if runtimeSettings is also a FileSettings w/o a specified target file, |
| | | // the target file for runtimeSettings is set to "localSettings". |
| | | runtimeSettings.merge(goSettings); |
| | | File base = goBaseFolder; |
| | | return base; |
| | | @Override |
| | | public void sendMailToAdministrators(String subject, String message) { |
| | | notificationManager.sendMailToAdministrators(subject, message); |
| | | } |
| | | |
| | | @Override |
| | | public void sendMail(String subject, String message, Collection<String> toAddresses) { |
| | | notificationManager.sendMail(subject, message, toAddresses); |
| | | } |
| | | |
| | | /** |
| | | * Configures a standard WAR instance of Gitblit. |
| | | * |
| | | * @param context |
| | | * @param webxmlSettings |
| | | * @param contextFolder |
| | | * @param runtimeSettings |
| | | * @return the base folder |
| | | @Override |
| | | public void sendMail(String subject, String message, String... toAddresses) { |
| | | notificationManager.sendMail(subject, message, toAddresses); |
| | | } |
| | | |
| | | @Override |
| | | public void sendHtmlMail(String subject, String message, Collection<String> toAddresses) { |
| | | notificationManager.sendHtmlMail(subject, message, toAddresses); |
| | | } |
| | | |
| | | @Override |
| | | public void sendHtmlMail(String subject, String message, String... toAddresses) { |
| | | notificationManager.sendHtmlMail(subject, message, toAddresses); |
| | | } |
| | | |
| | | /* |
| | | * SESSION MANAGER |
| | | */ |
| | | protected File configureWAR( |
| | | ServletContext context, |
| | | WebXmlSettings webxmlSettings, |
| | | File contextFolder, |
| | | IStoredSettings runtimeSettings) { |
| | | |
| | | // Gitblit is running in a standard servlet container |
| | | logger.debug("configuring Gitblit WAR"); |
| | | logger.info("WAR contextFolder is " + ((contextFolder != null) ? contextFolder.getAbsolutePath() : "<empty>")); |
| | | |
| | | String path = webxmlSettings.getString(Constants.baseFolder, Constants.contextFolder$ + "/WEB-INF/data"); |
| | | |
| | | if (path.contains(Constants.contextFolder$) && contextFolder == null) { |
| | | // warn about null contextFolder (issue-199) |
| | | logger.error(""); |
| | | logger.error(MessageFormat.format("\"{0}\" depends on \"{1}\" but \"{2}\" is returning NULL for \"{1}\"!", |
| | | Constants.baseFolder, Constants.contextFolder$, context.getServerInfo())); |
| | | logger.error(MessageFormat.format("Please specify a non-parameterized path for <context-param> {0} in web.xml!!", Constants.baseFolder)); |
| | | logger.error(MessageFormat.format("OR configure your servlet container to specify a \"{0}\" parameter in the context configuration!!", Constants.baseFolder)); |
| | | logger.error(""); |
| | | } |
| | | |
| | | try { |
| | | // try to lookup JNDI env-entry for the baseFolder |
| | | InitialContext ic = new InitialContext(); |
| | | Context env = (Context) ic.lookup("java:comp/env"); |
| | | String val = (String) env.lookup("baseFolder"); |
| | | if (!StringUtils.isEmpty(val)) { |
| | | path = val; |
| | | } |
| | | } catch (NamingException n) { |
| | | logger.error("Failed to get JNDI env-entry: " + n.getExplanation()); |
| | | } |
| | | |
| | | File base = com.gitblit.utils.FileUtils.resolveParameter(Constants.contextFolder$, contextFolder, path); |
| | | base.mkdirs(); |
| | | |
| | | // try to extract the data folder resource to the baseFolder |
| | | File localSettings = new File(base, "gitblit.properties"); |
| | | if (!localSettings.exists()) { |
| | | extractResources(context, "/WEB-INF/data/", base); |
| | | } |
| | | |
| | | // delegate all config to baseFolder/gitblit.properties file |
| | | FileSettings fileSettings = new FileSettings(localSettings.getAbsolutePath()); |
| | | |
| | | // merge the stored settings into the runtime settings |
| | | // |
| | | // if runtimeSettings is also a FileSettings w/o a specified target file, |
| | | // the target file for runtimeSettings is set to "localSettings". |
| | | runtimeSettings.merge(fileSettings); |
| | | |
| | | return base; |
| | | @Override |
| | | public UserModel authenticate(String username, char[] password) { |
| | | return authenticationManager.authenticate(username, password); |
| | | } |
| | | |
| | | /** |
| | | * Configures an OpenShift instance of Gitblit. |
| | | * |
| | | * @param context |
| | | * @param webxmlSettings |
| | | * @param contextFolder |
| | | * @param runtimeSettings |
| | | * @return the base folder |
| | | @Override |
| | | public UserModel authenticate(HttpServletRequest httpRequest) { |
| | | return authenticationManager.authenticate(httpRequest, false); |
| | | } |
| | | @Override |
| | | public UserModel authenticate(HttpServletRequest httpRequest, boolean requiresCertificate) { |
| | | return authenticationManager.authenticate(httpRequest, requiresCertificate); |
| | | } |
| | | |
| | | @Override |
| | | public void setCookie(HttpServletResponse response, UserModel user) { |
| | | authenticationManager.setCookie(response, user); |
| | | } |
| | | |
| | | @Override |
| | | public void logout(HttpServletResponse response, UserModel user) { |
| | | authenticationManager.logout(response, user); |
| | | } |
| | | |
| | | @Override |
| | | public boolean supportsCredentialChanges(UserModel user) { |
| | | return authenticationManager.supportsCredentialChanges(user); |
| | | } |
| | | |
| | | @Override |
| | | public boolean supportsDisplayNameChanges(UserModel user) { |
| | | return authenticationManager.supportsDisplayNameChanges(user); |
| | | } |
| | | |
| | | @Override |
| | | public boolean supportsEmailAddressChanges(UserModel user) { |
| | | return authenticationManager.supportsEmailAddressChanges(user); |
| | | } |
| | | |
| | | @Override |
| | | public boolean supportsTeamMembershipChanges(UserModel user) { |
| | | return authenticationManager.supportsTeamMembershipChanges(user); |
| | | } |
| | | |
| | | @Override |
| | | public boolean supportsTeamMembershipChanges(TeamModel team) { |
| | | return authenticationManager.supportsTeamMembershipChanges(team); |
| | | } |
| | | |
| | | /* |
| | | * USER MANAGER |
| | | */ |
| | | private File configureExpress( |
| | | ServletContext context, |
| | | WebXmlSettings webxmlSettings, |
| | | File contextFolder, |
| | | IStoredSettings runtimeSettings) { |
| | | |
| | | // Gitblit is running in OpenShift/JBoss |
| | | logger.debug("configuring Gitblit Express"); |
| | | String openShift = System.getenv("OPENSHIFT_DATA_DIR"); |
| | | File base = new File(openShift); |
| | | logger.info("EXPRESS contextFolder is " + contextFolder.getAbsolutePath()); |
| | | |
| | | // Copy the included scripts to the configured groovy folder |
| | | String path = webxmlSettings.getString(Keys.groovy.scriptsFolder, "groovy"); |
| | | File localScripts = com.gitblit.utils.FileUtils.resolveParameter(Constants.baseFolder$, base, path); |
| | | if (!localScripts.exists()) { |
| | | File warScripts = new File(contextFolder, "/WEB-INF/data/groovy"); |
| | | if (!warScripts.equals(localScripts)) { |
| | | try { |
| | | com.gitblit.utils.FileUtils.copy(localScripts, warScripts.listFiles()); |
| | | } catch (IOException e) { |
| | | logger.error(MessageFormat.format( |
| | | "Failed to copy included Groovy scripts from {0} to {1}", |
| | | warScripts, localScripts)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // merge the WebXmlSettings into the runtime settings (for backwards-compatibilty) |
| | | runtimeSettings.merge(webxmlSettings); |
| | | |
| | | // settings are to be stored in openshift/gitblit.properties |
| | | File localSettings = new File(base, "gitblit.properties"); |
| | | FileSettings fileSettings = new FileSettings(localSettings.getAbsolutePath()); |
| | | |
| | | // merge the stored settings into the runtime settings |
| | | // |
| | | // if runtimeSettings is also a FileSettings w/o a specified target file, |
| | | // the target file for runtimeSettings is set to "localSettings". |
| | | runtimeSettings.merge(fileSettings); |
| | | |
| | | return base; |
| | | @Override |
| | | public void setup(IRuntimeManager runtimeManager) { |
| | | } |
| | | |
| | | protected void extractResources(ServletContext context, String path, File toDir) { |
| | | for (String resource : context.getResourcePaths(path)) { |
| | | // extract the resource to the directory if it does not exist |
| | | File f = new File(toDir, resource.substring(path.length())); |
| | | if (!f.exists()) { |
| | | InputStream is = null; |
| | | OutputStream os = null; |
| | | try { |
| | | if (resource.charAt(resource.length() - 1) == '/') { |
| | | // directory |
| | | f.mkdirs(); |
| | | extractResources(context, resource, f); |
| | | } else { |
| | | // file |
| | | f.getParentFile().mkdirs(); |
| | | is = context.getResourceAsStream(resource); |
| | | os = new FileOutputStream(f); |
| | | byte [] buffer = new byte[4096]; |
| | | int len = 0; |
| | | while ((len = is.read(buffer)) > -1) { |
| | | os.write(buffer, 0, len); |
| | | } |
| | | } |
| | | } catch (FileNotFoundException e) { |
| | | logger.error("Failed to find resource \"" + resource + "\"", e); |
| | | } catch (IOException e) { |
| | | logger.error("Failed to copy resource \"" + resource + "\" to " + f, e); |
| | | } finally { |
| | | if (is != null) { |
| | | try { |
| | | is.close(); |
| | | } catch (IOException e) { |
| | | // ignore |
| | | } |
| | | } |
| | | if (os != null) { |
| | | try { |
| | | os.close(); |
| | | } catch (IOException e) { |
| | | // ignore |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | @Override |
| | | public List<String> getAllUsernames() { |
| | | return userManager.getAllUsernames(); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserModel> getAllUsers() { |
| | | return userManager.getAllUsers(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean deleteUser(String username) { |
| | | return userManager.deleteUser(username); |
| | | } |
| | | |
| | | @Override |
| | | public UserModel getUserModel(String username) { |
| | | return userManager.getUserModel(username); |
| | | } |
| | | |
| | | @Override |
| | | public List<TeamModel> getAllTeams() { |
| | | return userManager.getAllTeams(); |
| | | } |
| | | |
| | | @Override |
| | | public TeamModel getTeamModel(String teamname) { |
| | | return userManager.getTeamModel(teamname); |
| | | } |
| | | |
| | | @Override |
| | | public String getCookie(UserModel model) { |
| | | return userManager.getCookie(model); |
| | | } |
| | | |
| | | @Override |
| | | public UserModel getUserModel(char[] cookie) { |
| | | return userManager.getUserModel(cookie); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateUserModel(UserModel model) { |
| | | return userManager.updateUserModel(model); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateUserModels(Collection<UserModel> models) { |
| | | return userManager.updateUserModels(models); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateUserModel(String username, UserModel model) { |
| | | return userManager.updateUserModel(username, model); |
| | | } |
| | | |
| | | @Override |
| | | public boolean deleteUserModel(UserModel model) { |
| | | return userManager.deleteUserModel(model); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getAllTeamNames() { |
| | | return userManager.getAllTeamNames(); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getTeamNamesForRepositoryRole(String role) { |
| | | return userManager.getTeamNamesForRepositoryRole(role); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateTeamModel(TeamModel model) { |
| | | return userManager.updateTeamModel(model); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateTeamModels(Collection<TeamModel> models) { |
| | | return userManager.updateTeamModels(models); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateTeamModel(String teamname, TeamModel model) { |
| | | return userManager.updateTeamModel(teamname, model); |
| | | } |
| | | |
| | | @Override |
| | | public boolean deleteTeamModel(TeamModel model) { |
| | | return userManager.deleteTeamModel(model); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getUsernamesForRepositoryRole(String role) { |
| | | return userManager.getUsernamesForRepositoryRole(role); |
| | | } |
| | | |
| | | @Override |
| | | public boolean renameRepositoryRole(String oldRole, String newRole) { |
| | | return userManager.renameRepositoryRole(oldRole, newRole); |
| | | } |
| | | |
| | | @Override |
| | | public boolean deleteRepositoryRole(String role) { |
| | | return userManager.deleteRepositoryRole(role); |
| | | } |
| | | |
| | | @Override |
| | | public boolean deleteTeam(String teamname) { |
| | | return userManager.deleteTeam(teamname); |
| | | } |
| | | |
| | | /* |
| | | * REPOSITORY MANAGER |
| | | */ |
| | | |
| | | @Override |
| | | public Date getLastActivityDate() { |
| | | return repositoryManager.getLastActivityDate(); |
| | | } |
| | | |
| | | @Override |
| | | public File getRepositoriesFolder() { |
| | | return repositoryManager.getRepositoriesFolder(); |
| | | } |
| | | |
| | | @Override |
| | | public File getHooksFolder() { |
| | | return repositoryManager.getHooksFolder(); |
| | | } |
| | | |
| | | @Override |
| | | public File getGrapesFolder() { |
| | | return repositoryManager.getGrapesFolder(); |
| | | } |
| | | |
| | | @Override |
| | | public List<RegistrantAccessPermission> getUserAccessPermissions(UserModel user) { |
| | | return repositoryManager.getUserAccessPermissions(user); |
| | | } |
| | | |
| | | @Override |
| | | public List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository) { |
| | | return repositoryManager.getUserAccessPermissions(repository); |
| | | } |
| | | |
| | | @Override |
| | | public boolean setUserAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions) { |
| | | return repositoryManager.setUserAccessPermissions(repository, permissions); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getRepositoryUsers(RepositoryModel repository) { |
| | | return repositoryManager.getRepositoryUsers(repository); |
| | | } |
| | | |
| | | @Override |
| | | public List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository) { |
| | | return repositoryManager.getTeamAccessPermissions(repository); |
| | | } |
| | | |
| | | @Override |
| | | public boolean setTeamAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions) { |
| | | return repositoryManager.setTeamAccessPermissions(repository, permissions); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getRepositoryTeams(RepositoryModel repository) { |
| | | return repositoryManager.getRepositoryTeams(repository); |
| | | } |
| | | @Override |
| | | public void addToCachedRepositoryList(RepositoryModel model) { |
| | | repositoryManager.addToCachedRepositoryList(model); |
| | | } |
| | | |
| | | @Override |
| | | public void resetRepositoryListCache() { |
| | | repositoryManager.resetRepositoryListCache(); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getRepositoryList() { |
| | | return repositoryManager.getRepositoryList(); |
| | | } |
| | | |
| | | @Override |
| | | public Repository getRepository(String repositoryName) { |
| | | return repositoryManager.getRepository(repositoryName); |
| | | } |
| | | |
| | | @Override |
| | | public Repository getRepository(String repositoryName, boolean logError) { |
| | | return repositoryManager.getRepository(repositoryName, logError); |
| | | } |
| | | |
| | | @Override |
| | | public List<RepositoryModel> getRepositoryModels(UserModel user) { |
| | | return repositoryManager.getRepositoryModels(user); |
| | | } |
| | | |
| | | @Override |
| | | public RepositoryModel getRepositoryModel(UserModel user, String repositoryName) { |
| | | return repositoryManager.getRepositoryModel(repositoryName); |
| | | } |
| | | |
| | | @Override |
| | | public RepositoryModel getRepositoryModel(String repositoryName) { |
| | | return repositoryManager.getRepositoryModel(repositoryName); |
| | | } |
| | | |
| | | @Override |
| | | public long getStarCount(RepositoryModel repository) { |
| | | return repositoryManager.getStarCount(repository); |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasRepository(String repositoryName) { |
| | | return repositoryManager.hasRepository(repositoryName); |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasRepository(String repositoryName, boolean caseSensitiveCheck) { |
| | | return repositoryManager.hasRepository(repositoryName, caseSensitiveCheck); |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasFork(String username, String origin) { |
| | | return repositoryManager.hasFork(username, origin); |
| | | } |
| | | |
| | | @Override |
| | | public String getFork(String username, String origin) { |
| | | return repositoryManager.getFork(username, origin); |
| | | } |
| | | |
| | | @Override |
| | | public ForkModel getForkNetwork(String repository) { |
| | | return repositoryManager.getForkNetwork(repository); |
| | | } |
| | | |
| | | @Override |
| | | public long updateLastChangeFields(Repository r, RepositoryModel model) { |
| | | return repositoryManager.updateLastChangeFields(r, model); |
| | | } |
| | | |
| | | @Override |
| | | public List<Metric> getRepositoryDefaultMetrics(RepositoryModel model, Repository repository) { |
| | | return repositoryManager.getRepositoryDefaultMetrics(model, repository); |
| | | } |
| | | |
| | | @Override |
| | | public void updateRepositoryModel(String repositoryName, RepositoryModel repository, |
| | | boolean isCreate) throws GitBlitException { |
| | | repositoryManager.updateRepositoryModel(repositoryName, repository, isCreate); |
| | | } |
| | | |
| | | @Override |
| | | public void updateConfiguration(Repository r, RepositoryModel repository) { |
| | | repositoryManager.updateConfiguration(r, repository); |
| | | } |
| | | |
| | | @Override |
| | | public boolean deleteRepositoryModel(RepositoryModel model) { |
| | | return repositoryManager.deleteRepositoryModel(model); |
| | | } |
| | | |
| | | @Override |
| | | public boolean deleteRepository(String repositoryName) { |
| | | return repositoryManager.deleteRepository(repositoryName); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getAllScripts() { |
| | | return repositoryManager.getAllScripts(); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getPreReceiveScriptsInherited(RepositoryModel repository) { |
| | | return repositoryManager.getPreReceiveScriptsInherited(repository); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getPreReceiveScriptsUnused(RepositoryModel repository) { |
| | | return repositoryManager.getPreReceiveScriptsUnused(repository); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getPostReceiveScriptsInherited(RepositoryModel repository) { |
| | | return repositoryManager.getPostReceiveScriptsInherited(repository); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getPostReceiveScriptsUnused(RepositoryModel repository) { |
| | | return repositoryManager.getPostReceiveScriptsUnused(repository); |
| | | } |
| | | |
| | | @Override |
| | | public List<SearchResult> search(String query, int page, int pageSize, List<String> repositories) { |
| | | return repositoryManager.search(query, page, pageSize, repositories); |
| | | } |
| | | |
| | | @Override |
| | | public boolean isCollectingGarbage() { |
| | | return repositoryManager.isCollectingGarbage(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean isCollectingGarbage(String repositoryName) { |
| | | return repositoryManager.isCollectingGarbage(repositoryName); |
| | | } |
| | | |
| | | /* |
| | | * PROJECT MANAGER |
| | | */ |
| | | |
| | | @Override |
| | | public List<ProjectModel> getProjectModels(UserModel user, boolean includeUsers) { |
| | | return projectManager.getProjectModels(user, includeUsers); |
| | | } |
| | | |
| | | @Override |
| | | public ProjectModel getProjectModel(String name, UserModel user) { |
| | | return projectManager.getProjectModel(name, user); |
| | | } |
| | | |
| | | @Override |
| | | public ProjectModel getProjectModel(String name) { |
| | | return projectManager.getProjectModel(name); |
| | | } |
| | | |
| | | @Override |
| | | public List<ProjectModel> getProjectModels(List<RepositoryModel> repositoryModels, boolean includeUsers) { |
| | | return projectManager.getProjectModels(repositoryModels, includeUsers); |
| | | } |
| | | |
| | | /* |
| | | * FEDERATION MANAGER |
| | | */ |
| | | |
| | | @Override |
| | | public File getProposalsFolder() { |
| | | return federationManager.getProposalsFolder(); |
| | | } |
| | | |
| | | @Override |
| | | public UserModel getFederationUser() { |
| | | return federationManager.getFederationUser(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean canFederate() { |
| | | return federationManager.canFederate(); |
| | | } |
| | | |
| | | @Override |
| | | public List<FederationModel> getFederationRegistrations() { |
| | | return federationManager.getFederationRegistrations(); |
| | | } |
| | | |
| | | @Override |
| | | public FederationModel getFederationRegistration(String url, String name) { |
| | | return federationManager.getFederationRegistration(url, name); |
| | | } |
| | | |
| | | @Override |
| | | public List<FederationSet> getFederationSets(String gitblitUrl) { |
| | | return federationManager.getFederationSets(gitblitUrl); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getFederationTokens() { |
| | | return federationManager.getFederationTokens(); |
| | | } |
| | | |
| | | @Override |
| | | public String getFederationToken(FederationToken type) { |
| | | return federationManager.getFederationToken(type); |
| | | } |
| | | |
| | | @Override |
| | | public String getFederationToken(String value) { |
| | | return federationManager.getFederationToken(value); |
| | | } |
| | | |
| | | @Override |
| | | public boolean validateFederationRequest(FederationRequest req, String token) { |
| | | return federationManager.validateFederationRequest(req, token); |
| | | } |
| | | |
| | | @Override |
| | | public boolean acknowledgeFederationStatus(String identification, FederationModel registration) { |
| | | return federationManager.acknowledgeFederationStatus(identification, registration); |
| | | } |
| | | |
| | | @Override |
| | | public List<FederationModel> getFederationResultRegistrations() { |
| | | return federationManager.getFederationResultRegistrations(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean submitFederationProposal(FederationProposal proposal, String gitblitUrl) { |
| | | return federationManager.submitFederationProposal(proposal, gitblitUrl); |
| | | } |
| | | |
| | | @Override |
| | | public List<FederationProposal> getPendingFederationProposals() { |
| | | return federationManager.getPendingFederationProposals(); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, RepositoryModel> getRepositories(String gitblitUrl, String token) { |
| | | return federationManager.getRepositories(gitblitUrl, token); |
| | | } |
| | | |
| | | @Override |
| | | public FederationProposal createFederationProposal(String gitblitUrl, String token) { |
| | | return federationManager.createFederationProposal(gitblitUrl, token); |
| | | } |
| | | |
| | | @Override |
| | | public FederationProposal getPendingFederationProposal(String token) { |
| | | return federationManager.getPendingFederationProposal(token); |
| | | } |
| | | |
| | | @Override |
| | | public boolean deletePendingFederationProposal(FederationProposal proposal) { |
| | | return federationManager.deletePendingFederationProposal(proposal); |
| | | } |
| | | |
| | | /* |
| | | * GITBLIT MANAGER |
| | | */ |
| | | |
| | | @Override |
| | | public RepositoryModel fork(RepositoryModel repository, UserModel user) throws GitBlitException { |
| | | return gitblitManager.fork(repository, user); |
| | | } |
| | | |
| | | @Override |
| | | public void updateTeamModel(String teamname, TeamModel team, boolean isCreate) |
| | | throws GitBlitException { |
| | | gitblitManager.updateTeamModel(teamname, team, isCreate); |
| | | } |
| | | |
| | | @Override |
| | | public void updateUserModel(String username, UserModel user, boolean isCreate) |
| | | throws GitBlitException { |
| | | gitblitManager.updateUserModel(username, user, isCreate); |
| | | } |
| | | |
| | | @Override |
| | | public List<RepositoryUrl> getRepositoryUrls(HttpServletRequest request, UserModel user, RepositoryModel repository) { |
| | | return gitblitManager.getRepositoryUrls(request, user, repository); |
| | | } |
| | | |
| | | @Override |
| | | public Collection<GitClientApplication> getClientApplications() { |
| | | return gitblitManager.getClientApplications(); |
| | | } |
| | | } |