1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.security.access;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24 import org.apache.hadoop.hbase.TableName;
25 import org.apache.hadoop.hbase.util.Bytes;
26
27 import java.io.DataInput;
28 import java.io.DataOutput;
29 import java.io.IOException;
30
31
32
33
34
35 @InterfaceAudience.Private
36 public class UserPermission extends TablePermission {
37 private static final Log LOG = LogFactory.getLog(UserPermission.class);
38
39 private byte[] user;
40
41
42 public UserPermission() {
43 super();
44 }
45
46
47
48
49
50
51 public UserPermission(byte[] user, Action... assigned) {
52 super(null, null, null, assigned);
53 this.user = user;
54 }
55
56
57
58
59
60
61
62 public UserPermission(byte[] user, byte[] actionCodes) {
63 super(null, null, null, actionCodes);
64 this.user = user;
65 }
66
67
68
69
70
71
72
73 public UserPermission(byte[] user, String namespace, Action... assigned) {
74 super(namespace, assigned);
75 this.user = user;
76 }
77
78
79
80
81
82
83
84
85 public UserPermission(byte[] user, String namespace, byte[] actionCodes) {
86 super(namespace, actionCodes);
87 this.user = user;
88 }
89
90
91
92
93
94
95
96
97
98 public UserPermission(byte[] user, TableName table, byte[] family,
99 Action... assigned) {
100 super(table, family, assigned);
101 this.user = user;
102 }
103
104
105
106
107
108
109
110
111
112
113
114
115 public UserPermission(byte[] user, TableName table, byte[] family,
116 byte[] qualifier, Action... assigned) {
117 super(table, family, qualifier, assigned);
118 this.user = user;
119 }
120
121
122
123
124
125
126
127
128
129
130
131
132 public UserPermission(byte[] user, TableName table, byte[] family,
133 byte[] qualifier, byte[] actionCodes) {
134 super(table, family, qualifier, actionCodes);
135 this.user = user;
136 }
137
138
139
140
141
142
143
144 public UserPermission(byte[] user, TablePermission perm) {
145 super(perm.getNamespace(), perm.getTableName(), perm.getFamily(), perm.getQualifier(),
146 perm.actions);
147 this.user = user;
148 }
149
150 public byte[] getUser() {
151 return user;
152 }
153
154
155
156
157 public boolean isGlobal() {
158 return(!hasTable() && !hasNamespace());
159 }
160
161 @Override
162 public boolean equals(Object obj) {
163 if (!(obj instanceof UserPermission)) {
164 return false;
165 }
166 UserPermission other = (UserPermission)obj;
167
168 if ((Bytes.equals(user, other.getUser()) &&
169 super.equals(obj))) {
170 return true;
171 } else {
172 return false;
173 }
174 }
175
176 @Override
177 public int hashCode() {
178 final int prime = 37;
179 int result = super.hashCode();
180 if (user != null) {
181 result = prime * result + Bytes.hashCode(user);
182 }
183 return result;
184 }
185
186 @Override
187 public String toString() {
188 StringBuilder str = new StringBuilder("UserPermission: ")
189 .append("user=").append(Bytes.toString(user))
190 .append(", ").append(super.toString());
191 return str.toString();
192 }
193
194 @Override
195 public void readFields(DataInput in) throws IOException {
196 super.readFields(in);
197 user = Bytes.readByteArray(in);
198 }
199
200 @Override
201 public void write(DataOutput out) throws IOException {
202 super.write(out);
203 Bytes.writeByteArray(out, user);
204 }
205 }