Implement custom IPublicKeyManager provider
1 files added
8 files modified
| | |
| | | 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);
|
| | | IGitblit gitblit = new GitblitManager(null, runtime, null, notifications, users, null, repositories, null, federation); |
| | |
|
| | | FederationPullService puller = new FederationPullService(gitblit, federation.getFederationRegistrations()) {
|
| | | @Override
|
| | |
| | | import com.google.inject.Guice; |
| | | import com.google.inject.Inject; |
| | | import com.google.inject.Injector; |
| | | import com.google.inject.Provider; |
| | | import com.google.inject.Singleton; |
| | | |
| | | /** |
| | |
| | | |
| | | @Inject |
| | | public GitBlit( |
| | | Provider<IPublicKeyManager> publicKeyManagerProvider, |
| | | IRuntimeManager runtimeManager, |
| | | IPluginManager pluginManager, |
| | | INotificationManager notificationManager, |
| | | IUserManager userManager, |
| | | IAuthenticationManager authenticationManager, |
| | | IPublicKeyManager publicKeyManager, |
| | | IRepositoryManager repositoryManager, |
| | | IProjectManager projectManager, |
| | | IFederationManager federationManager) { |
| | | |
| | | super(runtimeManager, |
| | | super( |
| | | publicKeyManagerProvider, |
| | | runtimeManager, |
| | | pluginManager, |
| | | notificationManager, |
| | | userManager, |
| | | authenticationManager, |
| | | publicKeyManager, |
| | | repositoryManager, |
| | | projectManager, |
| | | federationManager); |
| | |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | |
| | | import com.gitblit.FileSettings; |
| | | import com.gitblit.GitBlit; |
| | | import com.gitblit.IStoredSettings; |
| | | import com.gitblit.Keys; |
| | | import com.gitblit.manager.AuthenticationManager; |
| | | import com.gitblit.manager.FederationManager; |
| | | import com.gitblit.manager.IAuthenticationManager; |
| | |
| | | import com.gitblit.manager.RuntimeManager; |
| | | import com.gitblit.manager.ServicesManager; |
| | | 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.utils.WorkQueue; |
| | | import com.google.inject.AbstractModule; |
| | | import com.google.inject.Provides; |
| | | |
| | | /** |
| | | * CoreModule references all the core business objects. |
| | |
| | | bind(IStoredSettings.class).toInstance(new FileSettings()); |
| | | |
| | | // bind complex providers |
| | | bind(IPublicKeyManager.class).toProvider(IPublicKeyManagerProvider.class); |
| | | bind(WorkQueue.class).toProvider(WorkQueueProvider.class); |
| | | |
| | | // core managers |
| | |
| | | |
| | | // manager for long-running daemons and services |
| | | bind(IServicesManager.class).to(ServicesManager.class); |
| | | } |
| | | |
| | | @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; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | /* |
| | | * 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; |
| | | } |
| | | } |
| | |
| | | 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 |
| | |
| | | |
| | | protected final ObjectCache<Collection<GitClientApplication>> clientApplications = new ObjectCache<Collection<GitClientApplication>>(); |
| | | |
| | | protected final Provider<IPublicKeyManager> publicKeyManagerProvider; |
| | | |
| | | protected final IStoredSettings settings; |
| | | |
| | | protected final IRuntimeManager runtimeManager; |
| | |
| | | |
| | | protected final IAuthenticationManager authenticationManager; |
| | | |
| | | protected final IPublicKeyManager publicKeyManager; |
| | | |
| | | protected final IRepositoryManager repositoryManager; |
| | | |
| | | protected final IProjectManager projectManager; |
| | |
| | | |
| | | @Inject |
| | | public GitblitManager( |
| | | Provider<IPublicKeyManager> publicKeyManagerProvider, |
| | | IRuntimeManager runtimeManager, |
| | | IPluginManager pluginManager, |
| | | INotificationManager notificationManager, |
| | | IUserManager userManager, |
| | | IAuthenticationManager authenticationManager, |
| | | IPublicKeyManager publicKeyManager, |
| | | IRepositoryManager repositoryManager, |
| | | IProjectManager projectManager, |
| | | IFederationManager federationManager) { |
| | | |
| | | this.publicKeyManagerProvider = publicKeyManagerProvider; |
| | | |
| | | 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; |
| | |
| | | |
| | | @Override |
| | | public IPublicKeyManager getPublicKeyManager() { |
| | | return publicKeyManager; |
| | | return publicKeyManagerProvider.get(); |
| | | } |
| | | |
| | | /* |
| | |
| | | } |
| | | |
| | | @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 |
| | |
| | | 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. |
| | |
| | | |
| | | protected final Map<File, Long> lastModifieds; |
| | | |
| | | @Inject |
| | | public FileKeyManager(IRuntimeManager runtimeManager) { |
| | | this.runtimeManager = runtimeManager; |
| | | this.lastModifieds = new ConcurrentHashMap<File, Long>(); |
| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import com.google.inject.Inject; |
| | | |
| | | /** |
| | | * Memory public key manager. |
| | | * |
| | |
| | | |
| | | final Map<String, List<SshKey>> keys; |
| | | |
| | | @Inject |
| | | public MemoryKeyManager() { |
| | | keys = new HashMap<String, List<SshKey>>(); |
| | | } |
| | |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.google.inject.Inject; |
| | | |
| | | /** |
| | | * Rejects all public key management requests. |
| | | * |
| | |
| | | */ |
| | | public class NullKeyManager extends IPublicKeyManager { |
| | | |
| | | @Inject |
| | | public NullKeyManager() { |
| | | } |
| | | |
| | |
| | | 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 |
| | |
| | | private final Class<? extends WebPage> newRepositoryPageClass = NewRepositoryPage.class; |
| | | |
| | | private final Map<String, CacheControl> cacheablePages = new HashMap<String, CacheControl>(); |
| | | |
| | | private final Provider<IPublicKeyManager> publicKeyManagerProvider; |
| | | |
| | | private final IStoredSettings settings; |
| | | |
| | |
| | | |
| | | private final IAuthenticationManager authenticationManager; |
| | | |
| | | private final IPublicKeyManager publicKeyManager; |
| | | |
| | | private final IRepositoryManager repositoryManager; |
| | | |
| | | private final IProjectManager projectManager; |
| | |
| | | |
| | | @Inject |
| | | public GitBlitWebApp( |
| | | Provider<IPublicKeyManager> publicKeyManagerProvider, |
| | | IRuntimeManager runtimeManager, |
| | | IPluginManager pluginManager, |
| | | INotificationManager notificationManager, |
| | | IUserManager userManager, |
| | | IAuthenticationManager authenticationManager, |
| | | IPublicKeyManager publicKeyManager, |
| | | IRepositoryManager repositoryManager, |
| | | IProjectManager projectManager, |
| | | IFederationManager federationManager, |
| | |
| | | IServicesManager services) { |
| | | |
| | | super(); |
| | | this.publicKeyManagerProvider = publicKeyManagerProvider; |
| | | 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; |
| | |
| | | */ |
| | | @Override |
| | | public IPublicKeyManager keys() { |
| | | return publicKeyManager; |
| | | return publicKeyManagerProvider.get(); |
| | | } |
| | | |
| | | /* (non-Javadoc) |