# SINCE 1.5.0\r
git.sshBackend = NIO2\r
\r
-# SSH public key authenticator\r
-#\r
-# SINCE 1.5.0\r
-git.sshPublicKeyAuthenticator = com.gitblit.transport.ssh.CachingPublicKeyAuthenticator\r
-\r
# Allow push/pull over http/https with JGit servlet.\r
# If you do NOT want to allow Git clients to clone/push to Gitblit set this\r
# to false. You might want to do this if you are only using ssh:// or git://.\r
import com.gitblit.manager.RepositoryManager;
import com.gitblit.manager.RuntimeManager;
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.wicket.GitBlitWebApp;
import dagger.Module;
INotificationManager.class,
IUserManager.class,
IAuthenticationManager.class,
+ IPublicKeyManager.class,
IRepositoryManager.class,
IProjectManager.class,
IFederationManager.class,
// the Gitblit Wicket app
GitBlitWebApp.class
- }
+ }
)
public class DaggerModule {
userManager);
}
+ @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;
+ }
+ }
+
@Provides @Singleton IRepositoryManager provideRepositoryManager(
IRuntimeManager runtimeManager,
IUserManager userManager) {
INotificationManager notificationManager,
IUserManager userManager,
IAuthenticationManager authenticationManager,
+ IPublicKeyManager publicKeyManager,
IRepositoryManager repositoryManager,
IProjectManager projectManager,
IFederationManager federationManager) {
notificationManager,
userManager,
authenticationManager,
+ publicKeyManager,
repositoryManager,
projectManager,
federationManager);
INotificationManager notificationManager,
IUserManager userManager,
IAuthenticationManager authenticationManager,
+ IPublicKeyManager publicKeyManager,
IRepositoryManager repositoryManager,
IProjectManager projectManager,
IFederationManager federationManager,
notificationManager,
userManager,
authenticationManager,
+ publicKeyManager,
repositoryManager,
projectManager,
federationManager,
UserManager users = new UserManager(runtime).start();\r
RepositoryManager repositories = new RepositoryManager(runtime, users).start();\r
FederationManager federation = new FederationManager(runtime, notifications, repositories).start();\r
- IGitblit gitblit = new GitblitManager(runtime, notifications, users, null, repositories, null, federation);\r
+ IGitblit gitblit = new GitblitManager(runtime, notifications, users, null, null, repositories, null, federation);\r
\r
FederationPullService puller = new FederationPullService(gitblit, federation.getFederationRegistrations()) {\r
@Override\r
import com.gitblit.tickets.ITicketService;
import com.gitblit.tickets.NullTicketService;
import com.gitblit.tickets.RedisTicketService;
+import com.gitblit.transport.ssh.IPublicKeyManager;
import com.gitblit.utils.StringUtils;
import dagger.Module;
INotificationManager notificationManager,
IUserManager userManager,
IAuthenticationManager authenticationManager,
+ IPublicKeyManager publicKeyManager,
IRepositoryManager repositoryManager,
IProjectManager projectManager,
IFederationManager federationManager) {
notificationManager,
userManager,
authenticationManager,
+ publicKeyManager,
repositoryManager,
projectManager,
federationManager);
FileTicketService.class,
BranchTicketService.class,
RedisTicketService.class
- }
+ }
)
class GitBlitModule {
import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
import com.gitblit.tickets.ITicketService;
+import com.gitblit.transport.ssh.IPublicKeyManager;
import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.HttpUtils;
import com.gitblit.utils.JsonUtils;
protected final IAuthenticationManager authenticationManager;
+ protected final IPublicKeyManager publicKeyManager;
+
protected final IRepositoryManager repositoryManager;
protected final IProjectManager projectManager;
INotificationManager notificationManager,
IUserManager userManager,
IAuthenticationManager authenticationManager,
+ IPublicKeyManager publicKeyManager,
IRepositoryManager repositoryManager,
IProjectManager projectManager,
IFederationManager federationManager) {
this.notificationManager = notificationManager;
this.userManager = userManager;
this.authenticationManager = authenticationManager;
+ this.publicKeyManager = publicKeyManager;
this.repositoryManager = repositoryManager;
this.projectManager = projectManager;
this.federationManager = federationManager;
throw new RuntimeException("This class does not have a ticket service!");
}
+ @Override
+ public IPublicKeyManager getPublicKeyManager() {
+ return publicKeyManager;
+ }
+
/*
* ISTOREDSETTINGS
*
import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
import com.gitblit.tickets.ITicketService;
+import com.gitblit.transport.ssh.IPublicKeyManager;
public interface IGitblit extends IManager,
IRuntimeManager,
*/
ITicketService getTicketService();
+ /**
+ * Returns the SSH public key manager.
+ *
+ * @return the SSH public key manager
+ */
+ IPublicKeyManager getPublicKeyManager();
+
}
\ No newline at end of file
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.IRuntimeManager;
import com.gitblit.manager.IUserManager;
+import com.gitblit.transport.ssh.IPublicKeyManager;
import com.gitblit.utils.ContainerUtils;
import com.gitblit.utils.StringUtils;
String contextRealPath = context.getRealPath("/");
File contextFolder = (contextRealPath != null) ? new File(contextRealPath) : null;
- // if the base folder dosen't match the default assume they don't want to use express,
+ // if the base folder dosen't match the default assume they don't want to use express,
// this allows for other containers to customise the basefolder per context.
String defaultBase = Constants.contextFolder$ + "/WEB-INF/data";
String base = lookupBaseFolderFromJndi();
startManager(injector, INotificationManager.class);
startManager(injector, IUserManager.class);
startManager(injector, IAuthenticationManager.class);
+ startManager(injector, IPublicKeyManager.class);
startManager(injector, IRepositoryManager.class);
startManager(injector, IProjectManager.class);
startManager(injector, IFederationManager.class);
import com.google.common.base.Preconditions;
/**
- *
+ *
* @author Eric Myrhe
- *
+ *
*/
public class CachingPublicKeyAuthenticator implements PublickeyAuthenticator,
SessionListener {
protected final Logger log = LoggerFactory.getLogger(getClass());
- protected final IKeyManager keyManager;
+ protected final IPublicKeyManager keyManager;
protected final IAuthenticationManager authManager;
private final Map<ServerSession, Map<PublicKey, Boolean>> cache =
new ConcurrentHashMap<ServerSession, Map<PublicKey, Boolean>>();
- public CachingPublicKeyAuthenticator(IKeyManager keyManager,
+ public CachingPublicKeyAuthenticator(IPublicKeyManager keyManager,
IAuthenticationManager authManager) {
this.keyManager = keyManager;
this.authManager = authManager;
return false;
}
- public IKeyManager getKeyManager() {
- return keyManager;
- }
-
+ @Override
public void sessionCreated(Session session) {
}
+ @Override
public void sessionEvent(Session sesssion, Event event) {
}
+ @Override
public void sessionClosed(Session session) {
cache.remove(session);
}
import com.google.common.io.Files;
/**
- * Manages SSH keys on the filesystem.
+ * Manages public keys on the filesystem.
*
* @author James Moger
*
*/
-public class FileKeyManager extends IKeyManager {
+public class FileKeyManager extends IPublicKeyManager {
protected final IRuntimeManager runtimeManager;
@Override
public FileKeyManager start() {
+ log.info(toString());
return this;
}
+++ /dev/null
-/*
- * 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.transport.ssh;
-
-import java.security.PublicKey;
-import java.text.MessageFormat;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
-
-/**
- *
- * @author James Moger
- *
- */
-public abstract class IKeyManager {
-
- protected final Logger log = LoggerFactory.getLogger(getClass());
-
- protected final LoadingCache<String, List<PublicKey>> keyCache = CacheBuilder
- .newBuilder().
- expireAfterAccess(15, TimeUnit.MINUTES).
- maximumSize(100)
- .build(new CacheLoader<String, List<PublicKey>>() {
- @Override
- public List<PublicKey> load(String username) {
- return getKeysImpl(username);
- }
- });
-
- public abstract IKeyManager start();
-
- public abstract boolean isReady();
-
- public abstract IKeyManager stop();
-
- public final List<PublicKey> getKeys(String username) {
- try {
- if (isStale(username)) {
- keyCache.invalidate(username);
- }
- return keyCache.get(username);
- } catch (ExecutionException e) {
- log.error(MessageFormat.format("failed to retrieve keys for {0}", username), e);
- }
- return null;
- }
-
- protected abstract boolean isStale(String username);
-
- protected abstract List<PublicKey> getKeysImpl(String username);
-
- public abstract boolean addKey(String username, String data);
-
- public abstract boolean removeKey(String username, String data);
-
- public abstract boolean removeAllKeys(String username);
-}
--- /dev/null
+/*
+ * 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.transport.ssh;
+
+import java.security.PublicKey;
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.gitblit.manager.IManager;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+
+/**
+ * Parent class for public key managers.
+ *
+ * @author James Moger
+ *
+ */
+public abstract class IPublicKeyManager implements IManager {
+
+ protected final Logger log = LoggerFactory.getLogger(getClass());
+
+ protected final LoadingCache<String, List<PublicKey>> keyCache = CacheBuilder
+ .newBuilder().
+ expireAfterAccess(15, TimeUnit.MINUTES).
+ maximumSize(100)
+ .build(new CacheLoader<String, List<PublicKey>>() {
+ @Override
+ public List<PublicKey> load(String username) {
+ return getKeysImpl(username);
+ }
+ });
+
+ @Override
+ public abstract IPublicKeyManager start();
+
+ public abstract boolean isReady();
+
+ @Override
+ public abstract IPublicKeyManager stop();
+
+ public final List<PublicKey> getKeys(String username) {
+ try {
+ if (isStale(username)) {
+ keyCache.invalidate(username);
+ }
+ return keyCache.get(username);
+ } catch (ExecutionException e) {
+ log.error(MessageFormat.format("failed to retrieve keys for {0}", username), e);
+ }
+ return null;
+ }
+
+ protected abstract boolean isStale(String username);
+
+ protected abstract List<PublicKey> getKeysImpl(String username);
+
+ public abstract boolean addKey(String username, String data);
+
+ public abstract boolean removeKey(String username, String data);
+
+ public abstract boolean removeAllKeys(String username);
+}
--- /dev/null
+/*
+ * 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.transport.ssh;
+
+import java.security.PublicKey;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Memory public key manager.
+ *
+ * @author James Moger
+ *
+ */
+public class MemoryKeyManager extends IPublicKeyManager {
+
+ Map<String, List<PublicKey>> keys;
+
+ public MemoryKeyManager() {
+ keys = new HashMap<String, List<PublicKey>>();
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName();
+ }
+
+ @Override
+ public MemoryKeyManager start() {
+ log.info(toString());
+ return this;
+ }
+
+ @Override
+ public boolean isReady() {
+ return true;
+ }
+
+ @Override
+ public MemoryKeyManager stop() {
+ return this;
+ }
+
+ @Override
+ protected boolean isStale(String username) {
+ return false;
+ }
+
+ @Override
+ protected List<PublicKey> getKeysImpl(String username) {
+ String id = username.toLowerCase();
+ if (keys.containsKey(id)) {
+ return keys.get(id);
+ }
+ return null;
+ }
+
+ @Override
+ public boolean addKey(String username, String data) {
+ return false;
+ }
+
+ @Override
+ public boolean removeKey(String username, String data) {
+ return false;
+ }
+
+ @Override
+ public boolean removeAllKeys(String username) {
+ String id = username.toLowerCase();
+ keys.remove(id.toLowerCase());
+ return true;
+ }
+
+ /* Test method for populating the memory key manager */
+ public void addKey(String username, PublicKey key) {
+ String id = username.toLowerCase();
+ if (!keys.containsKey(id)) {
+ keys.put(id, new ArrayList<PublicKey>());
+ }
+ keys.get(id).add(key);
+ }
+}
import java.util.List;
/**
- * Rejects all SSH key management requests.
+ * Rejects all public key management requests.
*
* @author James Moger
*
*/
-public class NullKeyManager extends IKeyManager {
+public class NullKeyManager extends IPublicKeyManager {
public NullKeyManager() {
}
@Override
public NullKeyManager start() {
+ log.info(toString());
return this;
}
private static final Logger logger = LoggerFactory.getLogger(SshCommandFactory.class);
private final IGitblit gitblit;
- private final CachingPublicKeyAuthenticator keyAuthenticator;
private final ScheduledExecutorService startExecutor;
- public SshCommandFactory(IGitblit gitblit,
- CachingPublicKeyAuthenticator keyAuthenticator,
- IdGenerator idGenerator) {
+ public SshCommandFactory(IGitblit gitblit, IdGenerator idGenerator) {
this.gitblit = gitblit;
- this.keyAuthenticator = keyAuthenticator;
int threads = 2;// cfg.getInt("sshd","commandStartThreads", 2);
WorkQueue workQueue = new WorkQueue(idGenerator);
root.registerDispatcher(user, GitblitDispatchCommand.class);
root.registerDispatcher(user, GitDispatchCommand.class);
- root.setAuthenticator(keyAuthenticator);
-
return root;
}
import java.text.MessageFormat;
import java.util.concurrent.atomic.AtomicBoolean;
-import javax.inject.Singleton;
-
import org.apache.sshd.SshServer;
import org.apache.sshd.common.io.IoServiceFactoryFactory;
import org.apache.sshd.common.io.mina.MinaServiceFactoryFactory;
import com.gitblit.Constants;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
-import com.gitblit.manager.IAuthenticationManager;
import com.gitblit.manager.IGitblit;
import com.gitblit.utils.IdGenerator;
import com.gitblit.utils.StringUtils;
-import dagger.Module;
-import dagger.ObjectGraph;
-import dagger.Provides;
-
/**
* Manager for the ssh transport. Roughly analogous to the
* {@link com.gitblit.transport.git.GitDaemon} class.
private final IGitblit gitblit;
private final SshServer sshd;
- private final ObjectGraph injector;
/**
* Construct the Gitblit SSH daemon.
*/
public SshDaemon(IGitblit gitblit, IdGenerator idGenerator) {
this.gitblit = gitblit;
- this.injector = ObjectGraph.create(new SshModule());
IStoredSettings settings = gitblit.getSettings();
int port = settings.getInteger(Keys.git.sshPort, 0);
String bindInterface = settings.getString(Keys.git.sshBindInterface,
"localhost");
- IKeyManager keyManager = getKeyManager();
-
String sshBackendStr = settings.getString(Keys.git.sshBackend,
SshSessionBackend.NIO2.name());
SshSessionBackend backend = SshSessionBackend.valueOf(sshBackendStr);
File hostKeyStore = new File(gitblit.getBaseFolder(), HOST_KEY_STORE);
CachingPublicKeyAuthenticator keyAuthenticator =
- getPublicKeyAuthenticator(keyManager, gitblit);
+ new CachingPublicKeyAuthenticator(gitblit.getPublicKeyManager(), gitblit);
sshd = SshServer.setUpDefaultServer();
sshd.setPort(addr.getPort());
sshd.setSessionFactory(new SshServerSessionFactory());
sshd.setFileSystemFactory(new DisabledFilesystemFactory());
sshd.setTcpipForwardingFilter(new NonForwardingFilter());
- sshd.setCommandFactory(new SshCommandFactory(gitblit, keyAuthenticator, idGenerator));
+ sshd.setCommandFactory(new SshCommandFactory(gitblit, idGenerator));
sshd.setShellFactory(new WelcomeShell(settings));
String version = Constants.getGitBlitVersion() + " (" + sshd.getVersion() + ")";
run = new AtomicBoolean(false);
}
- private CachingPublicKeyAuthenticator getPublicKeyAuthenticator(
- IKeyManager keyManager, IGitblit gitblit) {
- IStoredSettings settings = gitblit.getSettings();
- String clazz = settings.getString(Keys.git.sshPublicKeyAuthenticator,
- CachingPublicKeyAuthenticator.class.getName());
- if (StringUtils.isEmpty(clazz)) {
- clazz = CachingPublicKeyAuthenticator.class.getName();
- }
- try {
- Class<CachingPublicKeyAuthenticator> authClass =
- (Class<CachingPublicKeyAuthenticator>) Class.forName(clazz);
- return authClass.getConstructor(
- new Class[] { IKeyManager.class,
- IAuthenticationManager.class }).newInstance(
- keyManager, gitblit);
- } catch (Exception e) {
- log.error("failed to create ssh auth manager " + clazz, e);
- }
- return null;
- }
-
public String formatUrl(String gituser, String servername, String repository) {
if (sshd.getPort() == DEFAULT_PORT) {
// standard port
}
}
}
-
- @SuppressWarnings("unchecked")
- protected IKeyManager getKeyManager() {
- IKeyManager keyManager = null;
- IStoredSettings settings = gitblit.getSettings();
- String clazz = settings.getString(Keys.git.sshKeysManager, FileKeyManager.class.getName());
- if (StringUtils.isEmpty(clazz)) {
- clazz = FileKeyManager.class.getName();
- }
- try {
- Class<? extends IKeyManager> managerClass = (Class<? extends IKeyManager>) Class.forName(clazz);
- keyManager = injector.get(managerClass).start();
- if (keyManager.isReady()) {
- log.info("{} is ready.", keyManager);
- } else {
- log.warn("{} is disabled.", keyManager);
- }
- } catch (Exception e) {
- log.error("failed to create ssh key manager " + clazz, e);
- keyManager = injector.get(NullKeyManager.class).start();
- }
- return keyManager;
- }
-
- @SuppressWarnings("unchecked")
- protected IKeyManager getKeyAuthenticator() {
- IKeyManager keyManager = null;
- IStoredSettings settings = gitblit.getSettings();
- String clazz = settings.getString(Keys.git.sshKeysManager, FileKeyManager.class.getName());
- if (StringUtils.isEmpty(clazz)) {
- clazz = FileKeyManager.class.getName();
- }
- try {
- Class<? extends IKeyManager> managerClass = (Class<? extends IKeyManager>) Class.forName(clazz);
- keyManager = injector.get(managerClass).start();
- if (keyManager.isReady()) {
- log.info("{} is ready.", keyManager);
- } else {
- log.warn("{} is disabled.", keyManager);
- }
- } catch (Exception e) {
- log.error("failed to create ssh key manager " + clazz, e);
- keyManager = injector.get(NullKeyManager.class).start();
- }
- return keyManager;
- }
-
- /**
- * A nested Dagger graph is used for constructor dependency injection of
- * complex classes.
- *
- * @author James Moger
- *
- */
- @Module(
- library = true,
- injects = {
- NullKeyManager.class,
- FileKeyManager.class
- }
- )
- class SshModule {
-
- @Provides @Singleton NullKeyManager provideNullKeyManager() {
- return new NullKeyManager();
- }
-
- @Provides @Singleton FileKeyManager provideFileKeyManager() {
- return new FileKeyManager(SshDaemon.this.gitblit);
- }
- }
}
import com.gitblit.models.UserModel;
import com.gitblit.transport.ssh.CommandMetaData;
-import com.gitblit.transport.ssh.CachingPublicKeyAuthenticator;
-import com.gitblit.transport.ssh.gitblit.BaseKeyCommand;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.cli.SubcommandHandler;
import com.google.common.base.Charsets;
cmd.setOutputStream(out);
cmd.setErrorStream(err);
cmd.setExitCallback(exit);
-
- if (cmd instanceof BaseKeyCommand) {
- BaseKeyCommand k = (BaseKeyCommand) cmd;
- k.setAuthenticator(authenticator);
- }
- }
-
- private CachingPublicKeyAuthenticator authenticator;
-
- public void setAuthenticator(CachingPublicKeyAuthenticator authenticator) {
- this.authenticator = authenticator;
}
}
import java.io.UnsupportedEncodingException;
import java.util.List;
-import com.gitblit.transport.ssh.IKeyManager;
-import com.gitblit.transport.ssh.CachingPublicKeyAuthenticator;
+import com.gitblit.transport.ssh.IPublicKeyManager;
import com.gitblit.transport.ssh.commands.SshCommand;
import com.google.common.base.Charsets;
return sshKeys;
}
- protected CachingPublicKeyAuthenticator authenticator;
- public void setAuthenticator(CachingPublicKeyAuthenticator authenticator) {
- this.authenticator = authenticator;
- }
-
- protected IKeyManager getKeyManager() {
- return authenticator.getKeyManager();
+ protected IPublicKeyManager getKeyManager() {
+ return ctx.getGitblit().getPublicKeyManager();
}
}
import com.gitblit.manager.IRuntimeManager;
import com.gitblit.manager.IUserManager;
import com.gitblit.tickets.ITicketService;
+import com.gitblit.transport.ssh.IPublicKeyManager;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.pages.ActivityPage;
import com.gitblit.wicket.pages.BlamePage;
private final IAuthenticationManager authenticationManager;
+ private final IPublicKeyManager publicKeyManager;
+
private final IRepositoryManager repositoryManager;
private final IProjectManager projectManager;
INotificationManager notificationManager,
IUserManager userManager,
IAuthenticationManager authenticationManager,
+ IPublicKeyManager publicKeyManager,
IRepositoryManager repositoryManager,
IProjectManager projectManager,
IFederationManager federationManager,
this.notificationManager = notificationManager;
this.userManager = userManager;
this.authenticationManager = authenticationManager;
+ this.publicKeyManager = publicKeyManager;
this.repositoryManager = repositoryManager;
this.projectManager = projectManager;
this.federationManager = federationManager;
return authenticationManager;
}
+ public IPublicKeyManager keys() {
+ return publicKeyManager;
+ }
+
public IRepositoryManager repositories() {
return repositoryManager;
}
git.enableGitServlet = true
git.daemonPort = 8300
git.sshPort = 29418
-git.sshPublicKeyAuthenticator = com.gitblit.tests.BogusPublicKeyAuthenticator
+git.sshKeysManager = com.gitblit.transport.ssh.MemoryKeyManager
groovy.scriptsFolder = src/main/distrib/data/groovy
groovy.preReceiveScripts = blockpush
groovy.postReceiveScripts = sendmail
+++ /dev/null
-/*
- * 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.tests;
-
-import java.security.PublicKey;
-
-import org.apache.sshd.server.session.ServerSession;
-
-import com.gitblit.manager.IAuthenticationManager;
-import com.gitblit.transport.ssh.CachingPublicKeyAuthenticator;
-import com.gitblit.transport.ssh.IKeyManager;
-
-public class BogusPublicKeyAuthenticator extends CachingPublicKeyAuthenticator {
-
- public BogusPublicKeyAuthenticator(IKeyManager keyManager,
- IAuthenticationManager authManager) {
- super(keyManager, authManager);
- }
-
- @Override
- protected boolean doAuthenticate(String username, PublicKey suppliedKey,
- ServerSession session) {
- // TODO(davido): put authenticated user in session
- return true;
- }
-}
MarkdownUtilsTest.class, JGitUtilsTest.class, SyndicationUtilsTest.class,\r
DiffUtilsTest.class, MetricUtilsTest.class, X509UtilsTest.class,\r
GitBlitTest.class, FederationTests.class, RpcTests.class, GitServletTest.class, GitDaemonTest.class,\r
- GroovyScriptTest.class, LuceneExecutorTest.class, RepositoryModelTest.class, SshDaemonTest.class,\r
+ SshDaemonTest.class, GroovyScriptTest.class, LuceneExecutorTest.class, RepositoryModelTest.class,\r
FanoutServiceTest.class, Issue0259Test.class, Issue0271Test.class, HtpasswdAuthenticationTest.class,\r
ModelUtilsTest.class, JnaUtilsTest.class, LdapSyncServiceTest.class, FileTicketServiceTest.class,
BranchTicketServiceTest.class, RedisTicketServiceTest.class, AuthenticationManagerTest.class })
static int port = 8280;\r
static int gitPort = 8300;\r
static int shutdownPort = 8281;\r
- static int sshPort = 29418;\r
-\r
-// Overriding of keys doesn't seem to work\r
-// static {\r
-// try {\r
-// sshPort = SshUtils.getFreePort();\r
-// } catch (Exception e) {\r
-// e.printStackTrace();\r
-// }\r
-// }\r
+ static int sshPort = 39418;\r
\r
public static String url = "http://localhost:" + port;\r
public static String gitServletUrl = "http://localhost:" + port + "/git";\r
public static String gitDaemonUrl = "git://localhost:" + gitPort;\r
+ public static String sshDaemonUrl = "ssh://admin@localhost:" + sshPort;\r
public static String account = "admin";\r
public static String password = "admin";\r
\r
"" + shutdownPort, "--gitPort", "" + gitPort, "--repositoriesFolder",\r
"\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",\r
GitBlitSuite.USERSCONF.getAbsolutePath(), "--settings", GitBlitSuite.SETTINGS.getAbsolutePath(),\r
- "--baseFolder", "data");\r
- // doesn't work\r
- //, "--sshPort", "" + sshPort);\r
+ "--baseFolder", "data", "--sshPort", "" + sshPort);\r
}\r
});\r
\r
import org.apache.sshd.ClientSession;
import org.apache.sshd.SshClient;
import org.apache.sshd.common.KeyPairProvider;
+import org.junit.After;
import org.junit.AfterClass;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.gitblit.Constants;
+import com.gitblit.transport.ssh.IPublicKeyManager;
+import com.gitblit.transport.ssh.MemoryKeyManager;
public class SshDaemonTest extends GitblitUnitTest {
}
}
+ protected MemoryKeyManager getKeyManager() {
+ IPublicKeyManager mgr = gitblit().getPublicKeyManager();
+ if (mgr instanceof MemoryKeyManager) {
+ return (MemoryKeyManager) gitblit().getPublicKeyManager();
+ } else {
+ throw new RuntimeException("unexpected key manager type " + mgr.getClass().getName());
+ }
+ }
+
+ @Before
+ public void prepare() {
+ MemoryKeyManager keyMgr = getKeyManager();
+ keyMgr.addKey("admin", pair.getPublic());
+ }
+
+ @After
+ public void tearDown() {
+ MemoryKeyManager keyMgr = getKeyManager();
+ keyMgr.removeAllKeys("admin");
+ }
+
@Test
public void testPublicKeyAuthentication() throws Exception {
SshClient client = SshClient.setUpDefaultClient();