4444import org .apache .hadoop .hbase .security .UserProvider ;
4545import org .apache .hadoop .hbase .security .access .Permission .Action ;
4646import org .apache .hadoop .hbase .util .Bytes ;
47- import org .apache .hadoop .hbase .zookeeper .ZKWatcher ;
4847import org .apache .hadoop .security .Groups ;
4948import org .apache .hadoop .security .HadoopKerberosName ;
5049import org .apache .yetus .audience .InterfaceAudience ;
5352import org .apache .hbase .thirdparty .com .google .common .collect .ImmutableSet ;
5453
5554@ InterfaceAudience .Private
56- public final class AccessChecker {
55+ public class AccessChecker {
5756 private static final Logger LOG = LoggerFactory .getLogger (AccessChecker .class );
5857 private static final Logger AUDITLOG =
5958 LoggerFactory .getLogger ("SecurityLogger." + AccessChecker .class .getName ());
60- // TODO: we should move to a design where we don't even instantiate an AccessChecker if
61- // authorization is not enabled (like in RSRpcServices), instead of always instantiating one and
62- // calling requireXXX() only to do nothing (since authorizationEnabled will be false).
63- private AuthManager authManager ;
59+ private final AuthManager authManager ;
6460
6561 /** Group service to retrieve the user group information */
6662 private static Groups groupService ;
6763
68- /**
69- * if we are active, usually false, only true if "hbase.security.authorization"
70- * has been set to true in site configuration.see HBASE-19483.
71- */
72- private boolean authorizationEnabled ;
73-
7464 public static boolean isAuthorizationSupported (Configuration conf ) {
7565 return conf .getBoolean (User .HBASE_SECURITY_AUTHORIZATION_CONF_KEY , false );
7666 }
@@ -79,30 +69,12 @@ public static boolean isAuthorizationSupported(Configuration conf) {
7969 * Constructor with existing configuration
8070 *
8171 * @param conf Existing configuration to use
82- * @param zkw reference to the {@link ZKWatcher}
8372 */
84- public AccessChecker (final Configuration conf , final ZKWatcher zkw )
85- throws RuntimeException {
86- if (zkw != null ) {
87- try {
88- this .authManager = AuthManager .getOrCreate (zkw , conf );
89- } catch (IOException ioe ) {
90- throw new RuntimeException ("Error obtaining AccessChecker" , ioe );
91- }
92- } else {
93- throw new NullPointerException ("Error obtaining AccessChecker, zk found null." );
94- }
95- authorizationEnabled = isAuthorizationSupported (conf );
73+ public AccessChecker (final Configuration conf ) {
74+ this .authManager = new AuthManager (conf );
9675 initGroupService (conf );
9776 }
9877
99- /**
100- * Releases {@link AuthManager}'s reference.
101- */
102- public void stop () {
103- AuthManager .release (authManager );
104- }
105-
10678 public AuthManager getAuthManager () {
10779 return authManager ;
10880 }
@@ -119,9 +91,6 @@ public AuthManager getAuthManager() {
11991 */
12092 public void requireAccess (User user , String request , TableName tableName ,
12193 Action ... permissions ) throws IOException {
122- if (!authorizationEnabled ) {
123- return ;
124- }
12594 AuthResult result = null ;
12695
12796 for (Action permission : permissions ) {
@@ -170,9 +139,6 @@ public void requirePermission(User user, String request, String filterUser, Acti
170139 public void requireGlobalPermission (User user , String request ,
171140 Action perm , TableName tableName ,
172141 Map <byte [], ? extends Collection <byte []>> familyMap , String filterUser ) throws IOException {
173- if (!authorizationEnabled ) {
174- return ;
175- }
176142 AuthResult result ;
177143 if (authManager .authorizeUserGlobal (user , perm )) {
178144 result = AuthResult .allow (request , "Global check allowed" , user , perm , tableName , familyMap );
@@ -201,9 +167,6 @@ public void requireGlobalPermission(User user, String request,
201167 */
202168 public void requireGlobalPermission (User user , String request , Action perm ,
203169 String namespace ) throws IOException {
204- if (!authorizationEnabled ) {
205- return ;
206- }
207170 AuthResult authResult ;
208171 if (authManager .authorizeUserGlobal (user , perm )) {
209172 authResult = AuthResult .allow (request , "Global check allowed" , user , perm , null );
@@ -229,9 +192,6 @@ public void requireGlobalPermission(User user, String request, Action perm,
229192 */
230193 public void requireNamespacePermission (User user , String request , String namespace ,
231194 String filterUser , Action ... permissions ) throws IOException {
232- if (!authorizationEnabled ) {
233- return ;
234- }
235195 AuthResult result = null ;
236196
237197 for (Action permission : permissions ) {
@@ -264,9 +224,6 @@ public void requireNamespacePermission(User user, String request, String namespa
264224 public void requireNamespacePermission (User user , String request , String namespace ,
265225 TableName tableName , Map <byte [], ? extends Collection <byte []>> familyMap ,
266226 Action ... permissions ) throws IOException {
267- if (!authorizationEnabled ) {
268- return ;
269- }
270227 AuthResult result = null ;
271228
272229 for (Action permission : permissions ) {
@@ -303,9 +260,6 @@ public void requireNamespacePermission(User user, String request, String namespa
303260 */
304261 public void requirePermission (User user , String request , TableName tableName , byte [] family ,
305262 byte [] qualifier , String filterUser , Action ... permissions ) throws IOException {
306- if (!authorizationEnabled ) {
307- return ;
308- }
309263 AuthResult result = null ;
310264
311265 for (Action permission : permissions ) {
@@ -341,9 +295,6 @@ public void requirePermission(User user, String request, TableName tableName, by
341295 public void requireTablePermission (User user , String request ,
342296 TableName tableName ,byte [] family , byte [] qualifier ,
343297 Action ... permissions ) throws IOException {
344- if (!authorizationEnabled ) {
345- return ;
346- }
347298 AuthResult result = null ;
348299
349300 for (Action permission : permissions ) {
@@ -374,10 +325,6 @@ public void requireTablePermission(User user, String request,
374325 */
375326 public void performOnSuperuser (String request , User caller , String userToBeChecked )
376327 throws IOException {
377- if (!authorizationEnabled ) {
378- return ;
379- }
380-
381328 List <String > userGroups = new ArrayList <>();
382329 userGroups .add (userToBeChecked );
383330 if (!AuthUtil .isGroupPrincipal (userToBeChecked )) {
@@ -541,9 +488,6 @@ public static List<String> getUserGroups(String user) {
541488 * @return True if the user has the specific permission
542489 */
543490 public boolean hasUserPermission (User user , String request , Permission permission ) {
544- if (!authorizationEnabled ) {
545- return true ;
546- }
547491 if (permission instanceof TablePermission ) {
548492 TablePermission tPerm = (TablePermission ) permission ;
549493 for (Permission .Action action : permission .getActions ()) {
@@ -609,10 +553,6 @@ private AuthResult permissionGranted(String request, User user, Action permReque
609553 */
610554 public AuthResult permissionGranted (String request , User user , Action permRequest ,
611555 TableName tableName , Map <byte [], ? extends Collection <?>> families ) {
612- if (!authorizationEnabled ) {
613- return AuthResult .allow (request , "All users allowed because authorization is disabled" , user ,
614- permRequest , tableName , families );
615- }
616556 // 1. All users need read access to hbase:meta table.
617557 // this is a very common operation, so deal with it quickly.
618558 if (TableName .META_TABLE_NAME .equals (tableName )) {
0 commit comments