| | |
| | | import java.util.Collection; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Locale; |
| | | import java.util.Map; |
| | | import java.util.TimeZone; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import org.eclipse.jgit.api.CloneCommand; |
| | | import org.eclipse.jgit.api.FetchCommand; |
| | | import org.eclipse.jgit.api.Git; |
| | | import org.eclipse.jgit.lib.Ref; |
| | | import org.eclipse.jgit.lib.Repository; |
| | | import org.eclipse.jgit.transport.RefSpec; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import ro.fortsoft.pf4j.PluginState; |
| | | import ro.fortsoft.pf4j.PluginWrapper; |
| | | import ro.fortsoft.pf4j.Version; |
| | | |
| | | import com.gitblit.Constants; |
| | | import com.gitblit.Constants.AccessPermission; |
| | |
| | | import com.gitblit.models.FederationSet; |
| | | import com.gitblit.models.ForkModel; |
| | | import com.gitblit.models.GitClientApplication; |
| | | import com.gitblit.models.Mailing; |
| | | import com.gitblit.models.Metric; |
| | | import com.gitblit.models.PluginRegistry.InstallState; |
| | | import com.gitblit.models.PluginRegistry.PluginRegistration; |
| | | 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.SettingModel; |
| | | import com.gitblit.models.TeamModel; |
| | | import com.gitblit.models.UserModel; |
| | | 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.JGitUtils; |
| | | import com.gitblit.utils.JsonUtils; |
| | | import com.gitblit.utils.ObjectCache; |
| | | import com.gitblit.utils.StringUtils; |
| | |
| | | import com.google.gson.JsonIOException; |
| | | import com.google.gson.JsonSyntaxException; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.google.inject.Injector; |
| | | |
| | | /** |
| | | * GitblitManager is an aggregate interface delegate. It implements all the manager |
| | |
| | | |
| | | protected final IRuntimeManager runtimeManager; |
| | | |
| | | protected final IPluginManager pluginManager; |
| | | |
| | | protected final INotificationManager notificationManager; |
| | | |
| | | protected final IUserManager userManager; |
| | | |
| | | protected final IAuthenticationManager authenticationManager; |
| | | |
| | | protected final IPublicKeyManager publicKeyManager; |
| | | |
| | | protected final IRepositoryManager repositoryManager; |
| | | |
| | |
| | | |
| | | public GitblitManager( |
| | | IRuntimeManager runtimeManager, |
| | | IPluginManager pluginManager, |
| | | INotificationManager notificationManager, |
| | | IUserManager userManager, |
| | | IAuthenticationManager authenticationManager, |
| | | IPublicKeyManager publicKeyManager, |
| | | IRepositoryManager repositoryManager, |
| | | IProjectManager projectManager, |
| | | IFederationManager federationManager) { |
| | | |
| | | 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; |
| | |
| | | |
| | | // clone the repository |
| | | try { |
| | | JGitUtils.cloneRepository(repositoryManager.getRepositoriesFolder(), cloneName, fromUrl, true, null); |
| | | Repository canonical = getRepository(repository.name); |
| | | File folder = new File(repositoryManager.getRepositoriesFolder(), cloneName); |
| | | CloneCommand clone = new CloneCommand(); |
| | | clone.setBare(true); |
| | | |
| | | // fetch branches with exclusions |
| | | Collection<Ref> branches = canonical.getRefDatabase().getRefs(Constants.R_HEADS).values(); |
| | | List<String> branchesToClone = new ArrayList<String>(); |
| | | for (Ref branch : branches) { |
| | | String name = branch.getName(); |
| | | if (name.startsWith(Constants.R_TICKET)) { |
| | | // exclude ticket branches |
| | | continue; |
| | | } |
| | | branchesToClone.add(name); |
| | | } |
| | | clone.setBranchesToClone(branchesToClone); |
| | | clone.setURI(fromUrl); |
| | | clone.setDirectory(folder); |
| | | Git git = clone.call(); |
| | | |
| | | // fetch tags |
| | | FetchCommand fetch = git.fetch(); |
| | | fetch.setRefSpecs(new RefSpec("+refs/tags/*:refs/tags/*")); |
| | | fetch.call(); |
| | | |
| | | git.getRepository().close(); |
| | | } catch (Exception e) { |
| | | throw new GitBlitException(e); |
| | | } |
| | |
| | | if (!ArrayUtils.isEmpty(repository.owners)) { |
| | | for (String owner : repository.owners) { |
| | | UserModel originOwner = userManager.getUserModel(owner); |
| | | if (originOwner != null) { |
| | | if (originOwner != null && !originOwner.canClone(cloneModel)) { |
| | | // origin owner can't yet clone fork, grant explicit clone access |
| | | originOwner.setRepositoryPermission(cloneName, AccessPermission.CLONE); |
| | | reviseUser(originOwner.username, originOwner); |
| | | } |
| | |
| | | for (String name : users) { |
| | | if (!name.equalsIgnoreCase(user.username)) { |
| | | UserModel cloneUser = userManager.getUserModel(name); |
| | | if (cloneUser.canClone(repository)) { |
| | | // origin user can clone origin, grant clone access to fork |
| | | if (cloneUser.canClone(repository) && !cloneUser.canClone(cloneModel)) { |
| | | // origin user can't yet clone fork, grant explicit clone access |
| | | cloneUser.setRepositoryPermission(cloneName, AccessPermission.CLONE); |
| | | } |
| | | cloneUsers.add(cloneUser); |
| | |
| | | List<TeamModel> cloneTeams = new ArrayList<TeamModel>(); |
| | | for (String name : teams) { |
| | | TeamModel cloneTeam = userManager.getTeamModel(name); |
| | | if (cloneTeam.canClone(repository)) { |
| | | // origin team can clone origin, grant clone access to fork |
| | | if (cloneTeam.canClone(repository) && !cloneTeam.canClone(cloneModel)) { |
| | | // origin team can't yet clone fork, grant explicit clone access |
| | | cloneTeam.setRepositoryPermission(cloneName, AccessPermission.CLONE); |
| | | } |
| | | cloneTeams.add(cloneTeam); |
| | |
| | | repositoryManager.updateRepositoryModel(model.name, model, false); |
| | | } |
| | | } |
| | | |
| | | // rename the user's ssh public keystore |
| | | getPublicKeyManager().renameUser(username, user.username); |
| | | } |
| | | if (!userManager.updateUserModel(username, user)) { |
| | | throw new GitBlitException("Failed to update user!"); |
| | |
| | | } |
| | | |
| | | 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(HttpUtils.getGitblitURL(request)); |
| | | sb.append(gitblitUrl); |
| | | sb.append(Constants.R_PATH); |
| | | sb.append(repository.name); |
| | | |
| | |
| | | // no user definitions, use system definitions |
| | | if (!clientApplications.hasCurrent("system", new Date(0))) { |
| | | try { |
| | | InputStream is = getClass().getResourceAsStream("/clientapps.json"); |
| | | InputStream is = GitblitManager.class.getResourceAsStream("/clientapps.json"); |
| | | Collection<GitClientApplication> clients = readClientApplications(is); |
| | | is.close(); |
| | | if (clients != null) { |
| | |
| | | // Read bundled Gitblit properties to extract setting descriptions. |
| | | // This copy is pristine and only used for populating the setting |
| | | // models map. |
| | | InputStream is = getClass().getResourceAsStream("/reference.properties"); |
| | | InputStream is = GitblitManager.class.getResourceAsStream("/reference.properties"); |
| | | BufferedReader propertiesReader = new BufferedReader(new InputStreamReader(is)); |
| | | StringBuilder description = new StringBuilder(); |
| | | SettingModel setting = new SettingModel(); |
| | |
| | | } catch (IOException e) { |
| | | logger.error("Failed to load resource copy of gitblit.properties"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 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!"); |
| | | } |
| | | |
| | | @Override |
| | | public IPublicKeyManager getPublicKeyManager() { |
| | | return publicKeyManager; |
| | | } |
| | | |
| | | /* |
| | |
| | | } |
| | | |
| | | @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(); |
| | | } |
| | | |
| | | @Override |
| | | public Locale getLocale() { |
| | | return runtimeManager.getLocale(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return runtimeManager.getStatus(); |
| | | } |
| | | |
| | | @Override |
| | | public Injector getInjector() { |
| | | return runtimeManager.getInjector(); |
| | | } |
| | | |
| | | /* |
| | | * NOTIFICATION MANAGER |
| | | */ |
| | | |
| | | @Override |
| | | public boolean isSendingMail() { |
| | | return notificationManager.isSendingMail(); |
| | | } |
| | | |
| | | @Override |
| | | public void sendMailToAdministrators(String subject, String message) { |
| | |
| | | } |
| | | |
| | | @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); |
| | | public void send(Mailing mail) { |
| | | notificationManager.send(mail); |
| | | } |
| | | |
| | | /* |
| | |
| | | } |
| | | return user; |
| | | } |
| | | |
| | | @Override |
| | | public UserModel authenticate(String username, SshKey key) { |
| | | return authenticationManager.authenticate(username, key); |
| | | } |
| | | |
| | | @Override |
| | | public UserModel authenticate(HttpServletRequest httpRequest, boolean requiresCertificate) { |
| | | UserModel user = authenticationManager.authenticate(httpRequest, requiresCertificate); |
| | |
| | | user = federationManager.authenticate(httpRequest); |
| | | } |
| | | return user; |
| | | } |
| | | |
| | | @Override |
| | | public String getCookie(HttpServletRequest request) { |
| | | return authenticationManager.getCookie(request); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void resetRepositoryCache(String repositoryName) { |
| | | repositoryManager.resetRepositoryCache(repositoryName); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getRepositoryList() { |
| | | return repositoryManager.getRepositoryList(); |
| | | } |
| | |
| | | @Override |
| | | public void updateConfiguration(Repository r, RepositoryModel repository) { |
| | | repositoryManager.updateConfiguration(r, repository); |
| | | } |
| | | |
| | | @Override |
| | | public boolean canDelete(RepositoryModel model) { |
| | | return repositoryManager.canDelete(model); |
| | | } |
| | | |
| | | @Override |
| | |
| | | public boolean deletePendingFederationProposal(FederationProposal proposal) { |
| | | return federationManager.deletePendingFederationProposal(proposal); |
| | | } |
| | | |
| | | @Override |
| | | public void closeAll() { |
| | | repositoryManager.closeAll(); |
| | | } |
| | | |
| | | @Override |
| | | public void close(String repository) { |
| | | repositoryManager.close(repository); |
| | | } |
| | | |
| | | @Override |
| | | public boolean isIdle(Repository repository) { |
| | | return repositoryManager.isIdle(repository); |
| | | } |
| | | |
| | | /* |
| | | * PLUGIN MANAGER |
| | | */ |
| | | |
| | | @Override |
| | | public Version getSystemVersion() { |
| | | return pluginManager.getSystemVersion(); |
| | | } |
| | | |
| | | @Override |
| | | public void startPlugins() { |
| | | pluginManager.startPlugins(); |
| | | } |
| | | |
| | | @Override |
| | | public void stopPlugins() { |
| | | pluginManager.stopPlugins(); |
| | | } |
| | | |
| | | @Override |
| | | public List<PluginWrapper> getPlugins() { |
| | | return pluginManager.getPlugins(); |
| | | } |
| | | |
| | | @Override |
| | | public PluginWrapper getPlugin(String pluginId) { |
| | | return pluginManager.getPlugin(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public List<Class<?>> getExtensionClasses(String pluginId) { |
| | | return pluginManager.getExtensionClasses(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public <T> List<T> getExtensions(Class<T> clazz) { |
| | | return pluginManager.getExtensions(clazz); |
| | | } |
| | | |
| | | @Override |
| | | public PluginWrapper whichPlugin(Class<?> clazz) { |
| | | return pluginManager.whichPlugin(clazz); |
| | | } |
| | | |
| | | @Override |
| | | public PluginState startPlugin(String pluginId) { |
| | | return pluginManager.startPlugin(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public PluginState stopPlugin(String pluginId) { |
| | | return pluginManager.stopPlugin(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean disablePlugin(String pluginId) { |
| | | return pluginManager.disablePlugin(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean enablePlugin(String pluginId) { |
| | | return pluginManager.enablePlugin(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean uninstallPlugin(String pluginId) { |
| | | return pluginManager.uninstallPlugin(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean refreshRegistry(boolean verifyChecksum) { |
| | | return pluginManager.refreshRegistry(verifyChecksum); |
| | | } |
| | | |
| | | @Override |
| | | public boolean installPlugin(String url, boolean verifyChecksum) throws IOException { |
| | | return pluginManager.installPlugin(url, verifyChecksum); |
| | | } |
| | | |
| | | @Override |
| | | public boolean upgradePlugin(String pluginId, String url, boolean verifyChecksum) throws IOException { |
| | | return pluginManager.upgradePlugin(pluginId, url, verifyChecksum); |
| | | } |
| | | |
| | | @Override |
| | | public List<PluginRegistration> getRegisteredPlugins() { |
| | | return pluginManager.getRegisteredPlugins(); |
| | | } |
| | | |
| | | @Override |
| | | public List<PluginRegistration> getRegisteredPlugins(InstallState state) { |
| | | return pluginManager.getRegisteredPlugins(state); |
| | | } |
| | | |
| | | @Override |
| | | public PluginRegistration lookupPlugin(String pluginId) { |
| | | return pluginManager.lookupPlugin(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public PluginRelease lookupRelease(String pluginId, String version) { |
| | | return pluginManager.lookupRelease(pluginId, version); |
| | | } |
| | | } |