Tighten up restriction on plugin ssh commands

The plugin currently allows all "gerrit plugin" commands, which means
it is possible to install a new plugin while Gerrit is in read-only
mode.

Make it so the only commands allowed are "rm" and "remove" for this
plugin. This will ensure that no other plugins may be reloaded or
added while the readonly plugin is active.

Change-Id: Ie6bb5584ec4559bb8434706f571b86f9ff718776
diff --git a/src/main/java/com/googlesource/gerrit/plugins/readonly/DisableCommandInterceptor.java b/src/main/java/com/googlesource/gerrit/plugins/readonly/DisableCommandInterceptor.java
index 63512a1..447c86b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/readonly/DisableCommandInterceptor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/readonly/DisableCommandInterceptor.java
@@ -18,26 +18,30 @@
 import com.google.gerrit.sshd.SshCreateCommandInterceptor;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
+import java.util.regex.Pattern;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Singleton
 public class DisableCommandInterceptor implements SshCreateCommandInterceptor {
   private static final Logger log = LoggerFactory.getLogger(DisableCommandInterceptor.class);
+  private static final String PATTERN = "^gerrit plugin (\\brm\\b|\\bremove\\b) %s$";
 
   private final String pluginName;
+  private final Pattern pattern;
 
   @Inject
   DisableCommandInterceptor(@PluginName String pluginName) {
     this.pluginName = pluginName;
+    this.pattern = Pattern.compile(String.format(PATTERN, pluginName));
   }
 
   @Override
   public String intercept(String in) {
-    // Prevent disabling of plugin command to enable/disable plugins
-    if (in.startsWith("gerrit plugin")) {
+    if (pattern.matcher(in).matches()) {
       return in;
     }
+
     log.warn("Disabling command: " + in);
     return pluginName + " disable";
   }