summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java37
-rw-r--r--src/main/java/com/gitblit/transport/ssh/commands/PluginDispatcher.java25
-rw-r--r--src/main/java/com/gitblit/transport/ssh/commands/RootDispatcher.java14
-rw-r--r--src/main/java/com/gitblit/transport/ssh/git/GitDispatcher.java9
-rw-r--r--src/main/java/com/gitblit/transport/ssh/keys/KeysDispatcher.java15
-rw-r--r--src/site/plugins_extensions.mkd10
6 files changed, 53 insertions, 57 deletions
diff --git a/src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java b/src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java
index 6683e21b..86b3369d 100644
--- a/src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java
+++ b/src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java
@@ -96,57 +96,55 @@ public abstract class DispatchCommand extends BaseCommand implements ExtensionPo
* Setup this dispatcher. Commands and nested dispatchers are normally
* registered within this method.
*
- * @param user
* @since 1.5.0
*/
- protected abstract void setup(UserModel user);
+ protected abstract void setup();
/**
* Register a command or a dispatcher by it's class.
*
- * @param user
* @param clazz
*/
@SuppressWarnings("unchecked")
- protected final void register(UserModel user, Class<? extends BaseCommand> clazz) {
+ protected final void register(Class<? extends BaseCommand> clazz) {
if (DispatchCommand.class.isAssignableFrom(clazz)) {
- registerDispatcher(user, (Class<? extends DispatchCommand>) clazz);
+ registerDispatcher((Class<? extends DispatchCommand>) clazz);
return;
}
- registerCommand(user, clazz);
+ registerCommand(clazz);
}
/**
* Register a command or a dispatcher instance.
*
- * @param user
* @param cmd
*/
- protected final void register(UserModel user, BaseCommand cmd) {
+ protected final void register(BaseCommand cmd) {
if (cmd instanceof DispatchCommand) {
- registerDispatcher(user, (DispatchCommand) cmd);
+ registerDispatcher((DispatchCommand) cmd);
return;
}
- registerCommand(user, cmd);
+ registerCommand(cmd);
}
- private void registerDispatcher(UserModel user, Class<? extends DispatchCommand> clazz) {
+ private void registerDispatcher(Class<? extends DispatchCommand> clazz) {
try {
DispatchCommand dispatcher = clazz.newInstance();
- registerDispatcher(user, dispatcher);
+ registerDispatcher(dispatcher);
} catch (Exception e) {
log.error("failed to instantiate {}", clazz.getName());
}
}
- private void registerDispatcher(UserModel user, DispatchCommand dispatcher) {
+ private void registerDispatcher(DispatchCommand dispatcher) {
Class<? extends DispatchCommand> dispatcherClass = dispatcher.getClass();
if (!dispatcherClass.isAnnotationPresent(CommandMetaData.class)) {
throw new RuntimeException(MessageFormat.format("{0} must be annotated with {1}!", dispatcher.getName(),
CommandMetaData.class.getName()));
}
+ UserModel user = getContext().getClient().getUser();
CommandMetaData meta = dispatcherClass.getAnnotation(CommandMetaData.class);
if (meta.admin() && !user.canAdmin()) {
log.debug(MessageFormat.format("excluding admin dispatcher {0} for {1}",
@@ -155,7 +153,8 @@ public abstract class DispatchCommand extends BaseCommand implements ExtensionPo
}
try {
- dispatcher.setup(user);
+ dispatcher.setContext(getContext());
+ dispatcher.setup();
if (dispatcher.commands.isEmpty() && dispatcher.dispatchers.isEmpty()) {
log.debug(MessageFormat.format("excluding empty dispatcher {0} for {1}",
meta.name(), user.username));
@@ -179,14 +178,15 @@ public abstract class DispatchCommand extends BaseCommand implements ExtensionPo
/**
* Registers a command as long as the user is permitted to execute it.
*
- * @param user
* @param clazz
*/
- private void registerCommand(UserModel user, Class<? extends BaseCommand> clazz) {
+ private void registerCommand(Class<? extends BaseCommand> clazz) {
if (!clazz.isAnnotationPresent(CommandMetaData.class)) {
throw new RuntimeException(MessageFormat.format("{0} must be annotated with {1}!", clazz.getName(),
CommandMetaData.class.getName()));
}
+
+ UserModel user = getContext().getClient().getUser();
CommandMetaData meta = clazz.getAnnotation(CommandMetaData.class);
if (meta.admin() && !user.canAdmin()) {
log.debug(MessageFormat.format("excluding admin command {0} for {1}", meta.name(), user.username));
@@ -198,14 +198,15 @@ public abstract class DispatchCommand extends BaseCommand implements ExtensionPo
/**
* Registers a command as long as the user is permitted to execute it.
*
- * @param user
* @param cmd
*/
- private void registerCommand(UserModel user, BaseCommand cmd) {
+ private void registerCommand(BaseCommand cmd) {
if (!cmd.getClass().isAnnotationPresent(CommandMetaData.class)) {
throw new RuntimeException(MessageFormat.format("{0} must be annotated with {1}!", cmd.getName(),
CommandMetaData.class.getName()));
}
+
+ UserModel user = getContext().getClient().getUser();
CommandMetaData meta = cmd.getClass().getAnnotation(CommandMetaData.class);
if (meta.admin() && !user.canAdmin()) {
log.debug(MessageFormat.format("excluding admin command {0} for {1}", meta.name(), user.username));
diff --git a/src/main/java/com/gitblit/transport/ssh/commands/PluginDispatcher.java b/src/main/java/com/gitblit/transport/ssh/commands/PluginDispatcher.java
index 15345cac..42325e79 100644
--- a/src/main/java/com/gitblit/transport/ssh/commands/PluginDispatcher.java
+++ b/src/main/java/com/gitblit/transport/ssh/commands/PluginDispatcher.java
@@ -33,7 +33,6 @@ import com.gitblit.manager.IGitblit;
import com.gitblit.models.PluginRegistry.InstallState;
import com.gitblit.models.PluginRegistry.PluginRegistration;
import com.gitblit.models.PluginRegistry.PluginRelease;
-import com.gitblit.models.UserModel;
import com.gitblit.utils.FlipTable;
import com.gitblit.utils.FlipTable.Borders;
import com.gitblit.utils.StringUtils;
@@ -49,18 +48,18 @@ import com.google.common.base.Joiner;
public class PluginDispatcher extends DispatchCommand {
@Override
- protected void setup(UserModel user) {
- register(user, ListPlugins.class);
- register(user, StartPlugin.class);
- register(user, StopPlugin.class);
- register(user, EnablePlugin.class);
- register(user, DisablePlugin.class);
- register(user, ShowPlugin.class);
- register(user, RefreshPlugins.class);
- register(user, AvailablePlugins.class);
- register(user, InstallPlugin.class);
- register(user, UpgradePlugin.class);
- register(user, UninstallPlugin.class);
+ protected void setup() {
+ register(ListPlugins.class);
+ register(StartPlugin.class);
+ register(StopPlugin.class);
+ register(EnablePlugin.class);
+ register(DisablePlugin.class);
+ register(ShowPlugin.class);
+ register(RefreshPlugins.class);
+ register(AvailablePlugins.class);
+ register(InstallPlugin.class);
+ register(UpgradePlugin.class);
+ register(UninstallPlugin.class);
}
@CommandMetaData(name = "list", aliases = { "ls" }, description = "List plugins")
diff --git a/src/main/java/com/gitblit/transport/ssh/commands/RootDispatcher.java b/src/main/java/com/gitblit/transport/ssh/commands/RootDispatcher.java
index bebb4ac9..0bf6d510 100644
--- a/src/main/java/com/gitblit/transport/ssh/commands/RootDispatcher.java
+++ b/src/main/java/com/gitblit/transport/ssh/commands/RootDispatcher.java
@@ -23,7 +23,6 @@ import org.slf4j.LoggerFactory;
import ro.fortsoft.pf4j.PluginWrapper;
import com.gitblit.manager.IGitblit;
-import com.gitblit.models.UserModel;
import com.gitblit.transport.ssh.SshDaemonClient;
import com.gitblit.transport.ssh.git.GitDispatcher;
import com.gitblit.transport.ssh.keys.KeysDispatcher;
@@ -42,11 +41,10 @@ class RootDispatcher extends DispatchCommand {
super();
setContext(new SshCommandContext(gitblit, client, cmdLine));
- UserModel user = client.getUser();
- register(user, VersionCommand.class);
- register(user, GitDispatcher.class);
- register(user, KeysDispatcher.class);
- register(user, PluginDispatcher.class);
+ register(VersionCommand.class);
+ register(GitDispatcher.class);
+ register(KeysDispatcher.class);
+ register(PluginDispatcher.class);
List<DispatchCommand> exts = gitblit.getExtensions(DispatchCommand.class);
for (DispatchCommand ext : exts) {
@@ -55,11 +53,11 @@ class RootDispatcher extends DispatchCommand {
String plugin = wrapper.getDescriptor().getPluginId();
CommandMetaData meta = extClass.getAnnotation(CommandMetaData.class);
log.debug("Dispatcher {} is loaded from plugin {}", meta.name(), plugin);
- register(user, ext);
+ register(ext);
}
}
@Override
- protected final void setup(UserModel user) {
+ protected final void setup() {
}
} \ No newline at end of file
diff --git a/src/main/java/com/gitblit/transport/ssh/git/GitDispatcher.java b/src/main/java/com/gitblit/transport/ssh/git/GitDispatcher.java
index 6447cab3..43265059 100644
--- a/src/main/java/com/gitblit/transport/ssh/git/GitDispatcher.java
+++ b/src/main/java/com/gitblit/transport/ssh/git/GitDispatcher.java
@@ -20,7 +20,6 @@ import com.gitblit.git.GitblitReceivePackFactory;
import com.gitblit.git.GitblitUploadPackFactory;
import com.gitblit.git.RepositoryResolver;
import com.gitblit.manager.IGitblit;
-import com.gitblit.models.UserModel;
import com.gitblit.transport.ssh.SshDaemonClient;
import com.gitblit.transport.ssh.commands.BaseCommand;
import com.gitblit.transport.ssh.commands.CommandMetaData;
@@ -54,10 +53,10 @@ public class GitDispatcher extends DispatchCommand {
}
@Override
- protected void setup(UserModel user) {
- register(user, Upload.class);
- register(user, Receive.class);
- register(user, GarbageCollectionCommand.class);
+ protected void setup() {
+ register(Upload.class);
+ register(Receive.class);
+ register(GarbageCollectionCommand.class);
}
@Override
diff --git a/src/main/java/com/gitblit/transport/ssh/keys/KeysDispatcher.java b/src/main/java/com/gitblit/transport/ssh/keys/KeysDispatcher.java
index 44c3bbe8..53033d3d 100644
--- a/src/main/java/com/gitblit/transport/ssh/keys/KeysDispatcher.java
+++ b/src/main/java/com/gitblit/transport/ssh/keys/KeysDispatcher.java
@@ -25,7 +25,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.gitblit.Constants.AccessPermission;
-import com.gitblit.models.UserModel;
import com.gitblit.transport.ssh.IPublicKeyManager;
import com.gitblit.transport.ssh.SshKey;
import com.gitblit.transport.ssh.commands.CommandMetaData;
@@ -47,13 +46,13 @@ import com.google.common.base.Joiner;
public class KeysDispatcher extends DispatchCommand {
@Override
- protected void setup(UserModel user) {
- register(user, AddKey.class);
- register(user, RemoveKey.class);
- register(user, ListKeys.class);
- register(user, WhichKey.class);
- register(user, CommentKey.class);
- register(user, PermissionKey.class);
+ protected void setup() {
+ register(AddKey.class);
+ register(RemoveKey.class);
+ register(ListKeys.class);
+ register(WhichKey.class);
+ register(CommentKey.class);
+ register(PermissionKey.class);
}
@CommandMetaData(name = "add", description = "Add an SSH public key to your account")
diff --git a/src/site/plugins_extensions.mkd b/src/site/plugins_extensions.mkd
index 86d07291..60f8b47d 100644
--- a/src/site/plugins_extensions.mkd
+++ b/src/site/plugins_extensions.mkd
@@ -75,14 +75,14 @@ import com.gitblit.transport.ssh.commands.UsageExample;
public class MyDispatcher extends DispatchCommand {
@Override
- protected void setup(UserModel user) {
+ protected void setup() {
// commands in this dispatcher
- register(user, CommandA.class);
- register(user, CommandB.class);
+ register(CommandA.class);
+ register(CommandB.class);
// nested dispatchers
- register(user, SubDispatcher1.class);
- register(user, SubDispatcher2.class);
+ register(SubDispatcher1.class);
+ register(SubDispatcher2.class);
}
@CommandMetaData(name = "commanda", aliases = { "ca" }, description = "description of command a")