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
21 import org.apache.accumulo.core.client.AccumuloException;
22 import org.apache.accumulo.core.client.AccumuloSecurityException;
23 import org.apache.accumulo.core.security.SystemPermission;
24 import org.apache.accumulo.core.security.TablePermission;
25 import org.apache.accumulo.core.util.shell.Shell;
26 import org.apache.accumulo.core.util.shell.Shell.Command;
27 import org.apache.commons.cli.CommandLine;
28 import org.apache.commons.cli.Option;
29 import org.apache.commons.cli.Options;
30
31 public class UserPermissionsCommand extends Command {
32 private Option userOpt;
33 private static int runOnce = 0;
34
35 @Override
36 public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException {
37 final String user = cl.getOptionValue(userOpt.getOpt(), shellState.getConnector().whoami());
38
39 String delim = "";
40 shellState.getReader().printString("System permissions: ");
41 for (SystemPermission p : SystemPermission.values()) {
42 if (p != null && shellState.getConnector().securityOperations().hasSystemPermission(user, p)) {
43 shellState.getReader().printString(delim + "System." + p.name());
44 delim = ", ";
45 }
46 }
47 shellState.getReader().printNewline();
48
49 for (String t : shellState.getConnector().tableOperations().list()) {
50 delim = "";
51 for (TablePermission p : TablePermission.values()) {
52 if (shellState.getConnector().securityOperations().hasTablePermission(user, t, p) && p != null) {
53 if (runOnce == 0) {
54 shellState.getReader().printString("\nTable permissions (" + t + "): ");
55 runOnce++;
56 }
57 shellState.getReader().printString(delim + "Table." + p.name());
58 delim = ", ";
59 }
60
61 }
62 runOnce = 0;
63 }
64 shellState.getReader().printNewline();
65 return 0;
66 }
67
68 @Override
69 public String description() {
70 return "displays a user's system and table permissions";
71 }
72
73 @Override
74 public Options getOptions() {
75 Options o = new Options();
76 userOpt = new Option(Shell.userOption, "user", true, "user to operate on");
77 userOpt.setArgName("user");
78 o.addOption(userOpt);
79 return o;
80 }
81
82 @Override
83 public int numArgs() {
84 return 0;
85 }
86 }