1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.accumulo.core.util.shell.commands;
18
19 import java.io.IOException;
20 import java.nio.ByteBuffer;
21 import java.util.Map;
22 import java.util.Set;
23
24 import org.apache.accumulo.core.client.AccumuloException;
25 import org.apache.accumulo.core.client.AccumuloSecurityException;
26 import org.apache.accumulo.core.security.CredentialHelper;
27 import org.apache.accumulo.core.security.thrift.Credential;
28 import org.apache.accumulo.core.security.tokens.PasswordToken;
29 import org.apache.accumulo.core.util.shell.Shell;
30 import org.apache.accumulo.core.util.shell.Shell.Command;
31 import org.apache.accumulo.core.util.shell.Token;
32 import org.apache.commons.cli.CommandLine;
33
34 public class UserCommand extends Command {
35 public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException {
36
37 String user = cl.getArgs()[0];
38 byte[] pass;
39
40
41
42
43 final String p = shellState.readMaskedLine("Enter password for user " + user + ": ", '*');
44 if (p == null) {
45 shellState.getReader().printNewline();
46 return 0;
47 }
48 pass = p.getBytes();
49 shellState.updateUser(CredentialHelper.create(user, new PasswordToken().setPassword(pass), shellState.getConnector().getInstance().getInstanceID()));
50 return 0;
51 }
52
53 @Override
54 public String description() {
55 return "switches to the specified user";
56 }
57
58 @Override
59 public void registerCompletion(final Token root, final Map<Command.CompletionSet,Set<String>> special) {
60 registerCompletionForUsers(root, special);
61 }
62
63 @Override
64 public String usage() {
65 return getName() + " <username>";
66 }
67
68 @Override
69 public int numArgs() {
70 return 1;
71 }
72 }