]> source.dussan.org Git - gitblit.git/commitdiff
Remove User parameter from SSH dispatch command setup
authorJames Moger <james.moger@gitblit.com>
Fri, 18 Apr 2014 03:31:44 +0000 (23:31 -0400)
committerJames Moger <james.moger@gitblit.com>
Fri, 18 Apr 2014 03:33:24 +0000 (23:33 -0400)
src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java
src/main/java/com/gitblit/transport/ssh/commands/PluginDispatcher.java
src/main/java/com/gitblit/transport/ssh/commands/RootDispatcher.java
src/main/java/com/gitblit/transport/ssh/git/GitDispatcher.java
src/main/java/com/gitblit/transport/ssh/keys/KeysDispatcher.java
src/site/plugins_extensions.mkd

index 6683e21b048c58cf640a7aabe06a3d69cfd81a88..86b3369da086d115d79c43f000da882993b2afa4 100644 (file)
@@ -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));
index 15345cac09d4b22013767b356e9ee5d5d305194f..42325e7990373089ae529458d7101001dc893762 100644 (file)
@@ -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")
index bebb4ac92e0493420ee0ef736492b3d344311f3b..0bf6d510e5c6f9477779656f91c321cd89dedff6 100644 (file)
@@ -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
index 6447cab32948e2382649ea19af45a45f1e49c907..43265059ffa2c685e4d4800a3a8c64c7f557ad5a 100644 (file)
@@ -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
index 44c3bbe8989ac5fdc5c8dc1bbd6273c8e4ace1a1..53033d3dd2627ef6e25c4ed94aa7a0534a766037 100644 (file)
@@ -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")
index 86d072915d1b58dcf0387e81a3e70443c4303d64..60f8b47dd36f74f685ed96eb0a4b47672a7a52b2 100644 (file)
@@ -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")