Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 584CED1A6 for ; Wed, 23 Jan 2013 01:13:19 +0000 (UTC) Received: (qmail 39290 invoked by uid 500); 23 Jan 2013 01:13:19 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 39257 invoked by uid 500); 23 Jan 2013 01:13:19 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 39250 invoked by uid 99); 23 Jan 2013 01:13:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Jan 2013 01:13:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Jan 2013 01:13:16 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 26ACC23888CD; Wed, 23 Jan 2013 01:12:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1437247 - in /accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell: Shell.java commands/AddAuthsCommand.java Date: Wed, 23 Jan 2013 01:12:56 -0000 To: commits@accumulo.apache.org From: dlmarion@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130123011256.26ACC23888CD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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> 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; + } +}