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