| | |
| | | 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 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.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; |
| | |
| | | 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.utils.JsonUtils; |
| | | import com.gitblit.utils.ObjectCache; |
| | | import com.gitblit.utils.StringUtils; |
| | | import com.gitblit.utils.XssFilter; |
| | | 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 |
| | |
| | | * @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 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.notificationManager = notificationManager; |
| | | this.userManager = userManager; |
| | | this.authenticationManager = authenticationManager; |
| | | this.publicKeyManager = publicKeyManager; |
| | | this.repositoryManager = repositoryManager; |
| | | this.projectManager = projectManager; |
| | | this.federationManager = federationManager; |
| | |
| | | RepositoryModel cloneModel = repository.cloneAs(cloneName); |
| | | // owner has REWIND/RW+ permissions |
| | | cloneModel.addOwner(user.username); |
| | | |
| | | // ensure initial access restriction of the fork |
| | | // is not lower than the source repository (issue-495/ticket-167) |
| | | if (repository.accessRestriction.exceeds(cloneModel.accessRestriction)) { |
| | | cloneModel.accessRestriction = repository.accessRestriction; |
| | | } |
| | | |
| | | repositoryManager.updateRepositoryModel(cloneName, cloneModel, false); |
| | | |
| | | // add the owner of the source repository to the clone's access list |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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; |
| | | * |
| | |
| | | // 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(); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 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(); |
| | | } |
| | | |
| | | /* |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean isServingRepositories() { |
| | | return runtimeManager.isServingRepositories(); |
| | | public TimeZone getTimezone() { |
| | | return runtimeManager.getTimezone(); |
| | | } |
| | | |
| | | @Override |
| | | public TimeZone getTimezone() { |
| | | return runtimeManager.getTimezone(); |
| | | public Locale getLocale() { |
| | | return runtimeManager.getLocale(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return runtimeManager.getStatus(); |
| | | } |
| | | |
| | | @Override |
| | | public Injector getInjector() { |
| | | return runtimeManager.getInjector(); |
| | | } |
| | | |
| | | @Override |
| | | public XssFilter getXssFilter() { |
| | | return runtimeManager.getXssFilter(); |
| | | } |
| | | |
| | | /* |
| | | * NOTIFICATION MANAGER |
| | | */ |
| | | |
| | | @Override |
| | | public boolean isSendingMail() { |
| | | return notificationManager.isSendingMail(); |
| | | } |
| | | |
| | | @Override |
| | | public void sendMailToAdministrators(String subject, String message) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean deleteUser(String username) { |
| | | return userManager.deleteUser(username); |
| | | } |
| | | |
| | | @Override |
| | | public UserModel getUserModel(String username) { |
| | | return userManager.getUserModel(username); |
| | | } |
| | |
| | | } |
| | | |
| | | @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 |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void resetRepositoryCache(String repositoryName) { |
| | | repositoryManager.resetRepositoryCache(repositoryName); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getRepositoryList() { |
| | | return repositoryManager.getRepositoryList(); |
| | | } |
| | |
| | | @Override |
| | | public Repository getRepository(String repositoryName, boolean logError) { |
| | | return repositoryManager.getRepository(repositoryName, logError); |
| | | } |
| | | |
| | | @Override |
| | | public List<RepositoryModel> getRepositoryModels() { |
| | | return repositoryManager.getRepositoryModels(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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 |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean canDelete(RepositoryModel model) { |
| | | 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 |
| | |
| | | */ |
| | | |
| | | @Override |
| | | public Version getSystemVersion() { |
| | | return pluginManager.getSystemVersion(); |
| | | } |
| | | |
| | | @Override |
| | | public void startPlugins() { |
| | | pluginManager.startPlugins(); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean deletePlugin(String pluginId) { |
| | | return pluginManager.deletePlugin(pluginId); |
| | | public boolean uninstallPlugin(String pluginId) { |
| | | return pluginManager.uninstallPlugin(pluginId); |
| | | } |
| | | |
| | | @Override |