Author: dlmarion
Date: Wed Jan 23 01:12:55 2013
New Revision: 1437247
URL: http://svn.apache.org/viewvc?rev=1437247&view=rev
Log:
re #ACCUMULO-967 - Add addAuths command
Added:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddAuthsCommand.java
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java?rev=1437247&r1=1437246&r2=1437247&view=diff
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
(original)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
Wed Jan 23 01:12:55 2013
@@ -62,6 +62,7 @@ import org.apache.accumulo.core.util.for
import org.apache.accumulo.core.util.format.Formatter;
import org.apache.accumulo.core.util.format.FormatterFactory;
import org.apache.accumulo.core.util.shell.commands.AboutCommand;
+import org.apache.accumulo.core.util.shell.commands.AddAuthsCommand;
import org.apache.accumulo.core.util.shell.commands.AddSplitsCommand;
import org.apache.accumulo.core.util.shell.commands.AuthenticateCommand;
import org.apache.accumulo.core.util.shell.commands.ByeCommand;
@@ -311,7 +312,7 @@ public class Shell extends ShellOptions
new TablesCommand()};
Command[] tableControlCommands = {new AddSplitsCommand(), new
CompactCommand(), new ConstraintCommand(), new FlushCommand(), new
GetGroupsCommand(),
new GetSplitsCommand(), new MergeCommand(), new SetGroupsCommand()};
- Command[] userCommands = {new CreateUserCommand(), new
DeleteUserCommand(), new DropUserCommand(), new GetAuthsCommand(), new
PasswdCommand(),
+ Command[] userCommands = {new AddAuthsCommand(), new CreateUserCommand(),
new DeleteUserCommand(), new DropUserCommand(), new GetAuthsCommand(), new
PasswdCommand(),
new SetAuthsCommand(), new UsersCommand()};
commandGrouping.put("-- Writing, Reading, and Removing Data --",
dataCommands);
commandGrouping.put("-- Debugging Commands -------------------",
debuggingCommands);
Added:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddAuthsCommand.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddAuthsCommand.java?rev=1437247&view=auto
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddAuthsCommand.java
(added)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddAuthsCommand.java
Wed Jan 23 01:12:55 2013
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.accumulo.core.util.shell.commands;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.accumulo.core.util.shell.Token;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+
+public class AddAuthsCommand extends Command {
+ private Option userOpt;
+ private Option scanOptAuths;
+
+ @Override
+ public int execute(final String fullCommand, final CommandLine cl, final
Shell shellState) throws AccumuloException, AccumuloSecurityException {
+ final String user = cl.getOptionValue(userOpt.getOpt(),
shellState.getConnector().whoami());
+ final String scanOpts = cl.getOptionValue(scanOptAuths.getOpt());
+ Authorizations auths =
shellState.getConnector().securityOperations().getUserAuthorizations(user);
+ StringBuilder userAuths = new StringBuilder();
+ userAuths.append(auths.toString());
+ userAuths.append(",");
+ userAuths.append(scanOpts);
+
shellState.getConnector().securityOperations().changeUserAuthorizations(user,
ScanCommand.parseAuthorizations(userAuths.toString()));
+ Shell.log.debug("Changed record-level authorizations for user " + user);
+ return 0;
+ }
+
+ @Override
+ public String description() {
+ return "adds authorizations to the maximum scan authorizations for a user";
+ }
+
+ @Override
+ public void registerCompletion(final Token root, final
Map<Command.CompletionSet,Set<String>> completionSet) {
+ registerCompletionForUsers(root, completionSet);
+ }
+
+ @Override
+ public Options getOptions() {
+ final Options o = new Options();
+ final OptionGroup setOrClear = new OptionGroup();
+ scanOptAuths = new Option("s", "scan-authorizations", true, "scan
authorizations to set");
+ scanOptAuths.setArgName("comma-separated-authorizations");
+ setOrClear.addOption(scanOptAuths);
+ setOrClear.setRequired(true);
+ o.addOptionGroup(setOrClear);
+ userOpt = new Option(Shell.userOption, "user", true, "user to operate on");
+ userOpt.setArgName("user");
+ o.addOption(userOpt);
+ return o;
+ }
+
+ @Override
+ public int numArgs() {
+ return 0;
+ }
+}