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